forked from tetraminus/Tetrapak
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigHelper.lua
More file actions
102 lines (76 loc) · 2.82 KB
/
ConfigHelper.lua
File metadata and controls
102 lines (76 loc) · 2.82 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function Load_Config()
local mod = SMODS.current_mod
if not NFS.getInfo(mod.path.."config.lua") then
print("No config file found for Tetrapak, creating")
local file = NFS.newFile(mod.path.."config.lua")
local allcardnames = {}
for k, v in pairs(NFS.getDirectoryItems(mod.path.."jokers")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
for k, v in pairs(NFS.getDirectoryItems(mod.path.."spectrals")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
local conf = GetDefaultConfig()
for k, v in pairs(allcardnames) do
conf.Enabled[v] = true
end
Save_Config(conf)
end
local config = nil
local success, configLoader = pcall(NFS.load, mod.path.."config.lua")
if success then
local success, loadedconfig = pcall(configLoader)
if not success then
-- Handle error in config
loadedconfig = GetDefaultConfig()
end
config = loadedconfig
else
-- Handle error in loading config
config = GetDefaultConfig()
end
Save_Config(config)
-- fill in Enabled with any new cards that have no entry
local allcardnames = {}
for k, v in pairs(NFS.getDirectoryItems(mod.path.."jokers")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
for k, v in pairs(NFS.getDirectoryItems(mod.path.."spectrals")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
for k, v in pairs(NFS.getDirectoryItems(mod.path.."vouchers")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
for k, v in pairs(NFS.getDirectoryItems(mod.path.."blinds")) do
table.insert(allcardnames, string.sub(v, 1, string.len(v) - 4):lower())
end
for k, v in pairs(allcardnames) do
if config.Enabled[v] == nil then
config.Enabled[v] = true
end
end
Save_Config(config)
G.TETRAPAK_Config = config
end
function Save_Config(conf)
if not conf then
conf = G.TETRAPAK_Config
end
local mod = SMODS.current_mod
local file = NFS.newFile(mod.path.."config.lua")
file:open("w")
file:write("return " .. table.tostring(conf))
file:close()
end
function GetDefaultConfig()
return {
info = [[
This is the config file for Tetrapak.
Set the value of each card to true to enable it, or false to disable it.
If you want to disable a card, you can also just delete the file from the jokers or spectrals folder.
there will be more options in the future.
]],
Enabled = {
}
}
end