fix restore config & fix default values binder

test-utf-8
rubin 2 years ago
parent fc43b75078
commit 607a1572dc
  1. 44
      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,15 +334,43 @@ function settings_load()
end end
end end
try( -- try(
function() -- function()
-- local file, error = io.open(AdressJson, "r")
-- if file then
-- inifiles = decodeJson(file:read("*a"))
-- io.close(file)
-- end
-- end,
-- function(e)
-- 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
-- )
local readJson = 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"))
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) io.close(file)
end end
end, end
function(e) io.close(file)
end
end
local result = pcall(readJson)
if not result then
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
@ -350,7 +379,6 @@ function settings_load()
io.close(file) io.close(file)
end end
end end
)
if inifiles ~= nil then if inifiles ~= nil then
@ -362,12 +390,14 @@ function settings_load()
if inifiles[k] == nil then if inifiles[k] == nil then
inifiles[k] = v inifiles[k] = v
end end
if k ~= "binder" and k ~= "binder_sms" then
for i, s in pairs(v) do for i, s in pairs(v) do
if inifiles[k][i] == nil then if inifiles[k][i] == nil then
inifiles[k][i] = s inifiles[k][i] = s
end end
end end
end end
end
settings_save() settings_save()
else else
error_ini = true error_ini = true
@ -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