fix restore config & fix default values binder

test-utf-8
rubin 2 years ago
parent fc43b75078
commit 607a1572dc
  1. 72
      TruckHUD.lua

@ -244,6 +244,7 @@ function main()
end end
function settings_load() function settings_load()
wait(0)
local x1, y1 = convertGameScreenCoordsToWindowScreenCoords(14.992679595947, 274.75) local x1, y1 = convertGameScreenCoordsToWindowScreenCoords(14.992679595947, 274.75)
local x2, y2 = convertGameScreenCoordsToWindowScreenCoords(146.17861938477, 345.91665649414) local x2, y2 = convertGameScreenCoordsToWindowScreenCoords(146.17861938477, 345.91665649414)
local x3, y3 = convertGameScreenCoordsToWindowScreenCoords(529.42901611328, 158.08332824707) local x3, y3 = convertGameScreenCoordsToWindowScreenCoords(529.42901611328, 158.08332824707)
@ -333,24 +334,51 @@ function settings_load()
end end
end end
try( -- try(
function() -- function()
local file, error = io.open(AdressJson, "r") -- local file, error = io.open(AdressJson, "r")
if file then -- if file then
inifiles = decodeJson(file:read("*a")) -- inifiles = decodeJson(file:read("*a"))
io.close(file) -- io.close(file)
end -- end
end, -- end,
function(e) -- function(e)
sampAddChatMessage("[TruckHUD] Îøèáêà ÷òåíèÿ êîíôèãà! Ñáðàñûâàþ êîíôèã!", 0xff0000) -- sampAddChatMessage("[TruckHUD] Îøèáêà ÷òåíèÿ êîíôèãà! Ñáðàñûâàþ êîíôèã!", 0xff0000)
local file, error = io.open(AdressJson, "w") -- local file, error = io.open(AdressJson, "w")
if file ~= nil then -- if file ~= nil then
file:write(encodeJson(table_std)) -- file:write(encodeJson(table_std))
file:flush() -- file:flush()
io.close(file) -- io.close(file)
-- end
-- end
-- )
local readJson = function()
local file, error = io.open(AdressJson, "r")
if file then
inifiles = decodeJson(file:read("*a"))
if inifiles == nil then
sampAddChatMessage("[TruckHUD] Îøèáêà ÷òåíèÿ êîíôèãà! Ñáðàñûâàþ êîíôèã!", 0xff0000)
local file, error = io.open(AdressJson, "w")
if file ~= nil then
file:write(encodeJson(table_std))
file:flush()
io.close(file)
end
end end
io.close(file)
end end
) end
local result = pcall(readJson)
if not result then
sampAddChatMessage("[TruckHUD] Îøèáêà ÷òåíèÿ êîíôèãà! Ñáðàñûâàþ êîíôèã!", 0xff0000)
local file, error = io.open(AdressJson, "w")
if file ~= nil then
file:write(encodeJson(table_std))
file:flush()
io.close(file)
end
end
if inifiles ~= nil then if inifiles ~= nil then
@ -362,9 +390,11 @@ function settings_load()
if inifiles[k] == nil then if inifiles[k] == nil then
inifiles[k] = v inifiles[k] = v
end end
for i, s in pairs(v) do if k ~= "binder" and k ~= "binder_sms" then
if inifiles[k][i] == nil then for i, s in pairs(v) do
inifiles[k][i] = s if inifiles[k][i] == nil then
inifiles[k][i] = s
end
end end
end end
end end
@ -1479,9 +1509,9 @@ function doRenderBind()
end end
if drawClickableText("{ff0000}õ", (X + renderGetFontDrawTextLength(font, string .. " ")), Y) then if drawClickableText("{ff0000}õ", (X + renderGetFontDrawTextLength(font, string .. " ")), Y) then
if not binder_mode_sms then if not binder_mode_sms then
inifiles.binder[k] = nil table.remove(inifiles.binder, k)
else else
inifiles.binder_sms[k] = nil table.remove(inifiles.binder_sms, k)
end end
settings_save() settings_save()
end end

Loading…
Cancel
Save