This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
Kosmos/Compiled/EdiZon/editor/scripts/json.lua
2020-02-26 19:27:35 -05:00

74 lines
1.2 KiB
Lua

-- json --
json = require("lib.json")
function convertToTable(s)
t = {}
for i = 1, #s do
t[i] = string.byte(s:sub(i, i))
end
return t
end
saveFileBuffer = json.decode(edizon.getSaveFileString())
function getValueFromSaveFile()
strArgs = edizon.getStrArgs()
intArgs = edizon.getIntArgs()
item = saveFileBuffer
for i, tag in pairs(strArgs) do
if type(item) ~= "table" then break end
if string.sub(tag, 1, 1) == "\\" then
tag = tonumber(tag:sub(2)) + 1
if tag == nil then return 0 end
end
item = item[tag]
end
if intArgs[1] == 0 then
return item
else
return item and 1 or 0
end
end
function setValueInSaveFile(value)
local items = saveFileBuffer
strArgs = edizon.getStrArgs()
intArgs = edizon.getIntArgs()
local ref = items
for i, tag in ipairs(strArgs) do
if string.sub(tag, 1, 1) == "\\" then
tag = tonumber(tag:sub(2)) + 1
end
if i == #strArgs then
if intArgs[1] == 0 then
ref[tag] = value
else
ref[tag] = (value == 1)
end
else
ref = ref[tag]
end
end
end
function getModifiedSaveFile()
encoded = json.encode(saveFileBuffer)
convertedTable = {}
convertedTable = convertToTable(encoded)
return convertedTable
end