forked from z4gs/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.lua
More file actions
54 lines (43 loc) · 1.3 KB
/
Copy pathSettings.lua
File metadata and controls
54 lines (43 loc) · 1.3 KB
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
local Http = game:GetService("HttpService")
local Data = {}
function table_merge(...)
local tables_to_merge = { ... }
local result = tables_to_merge[1]
for i = 2, #tables_to_merge do
local from = tables_to_merge[i]
for k, v in pairs(from) do
if type(k) == "number" then
table.insert(result, v)
elseif type(k) == "string" then
if type(v) == "table" then
result[k] = result[k] or {}
result[k] = table_merge(result[k], v)
else
result[k] = v
end
end
end
end
return result
end
local function init(FolderName, Dict)
if not isfolder(FolderName) then
makefolder(FolderName)
end
local savedData = isfile(FolderName.."/data.json") and Http:JSONDecode(readfile(FolderName.."/data.json"))
if savedData then
Data = table_merge(savedData, Dict)
else
Data = Dict
end
return setmetatable({}, {
__index = function(self, idx)
return Data[idx]
end,
__newindex = function(self, idx, newv)
Data[idx] = newv
writefile(FolderName.."/data.json", Http:JSONEncode(Data))
end
});
end
return init