-
Notifications
You must be signed in to change notification settings - Fork 261
/
json.lua
79 lines (57 loc) · 1.43 KB
/
json.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- json --
json = require("lib.json")
saveFileString = edizon.getSaveFileString()
saveFileString = saveFileString:gsub('{%s*}', '{"edizon":true}')
saveFileBuffer = json.decode(saveFileString)
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
local function convertToTable(s)
t = {}
for i = 1, #s do
t[i] = string.byte(s:sub(i, i))
end
return t
end
function getModifiedSaveFile()
encoded = json.encode(saveFileBuffer)
encoded = encoded:gsub('{"edizon":true}', '{}')
convertedTable = {}
convertedTable = convertToTable(encoded)
return convertedTable
end