Skip to content

Commit 3bab732

Browse files
authored
if keys, magic and herbs files exist then load them initially before attempt do download (#548)
1 parent ce150f2 commit 3bab732

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

scriptsList.lua

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ table.insert(mudletModules, "skrypty/utils/colors")
120120
table.insert(mudletModules, "skrypty/utils/list")
121121
table.insert(mudletModules, "skrypty/utils/sounds")
122122
table.insert(mudletModules, "skrypty/utils/string")
123+
table.insert(mudletModules, "skrypty/utils/data_files")
123124
table.insert(mudletModules, "skrypty/utils/keybinds")
124125
table.insert(mudletModules, "skrypty/utils/keybinds_ship")
125126
table.insert(mudletModules, "skrypty/utils/time")

skrypty/utils/data_files.lua

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function scripts.utils:load_data_from_files()
2+
herbs["data"] = self:read_json(herbs.data_file_path)
3+
4+
scripts.inv["magics_data"] = self:read_json(scripts.inv.magics_file_path)
5+
if scripts.inv["magics_data"] then
6+
scripts.inv:setup_magics_triggers()
7+
end
8+
scripts.inv["magic_keys_data"] = self:read_json(scripts.inv.magic_keys_file_path)
9+
if scripts.inv["magic_keys_data"] then
10+
scripts.inv:setup_magic_keys_triggers()
11+
end
12+
end
13+
14+
function scripts.utils:read_json(file_path)
15+
local file_handle = io.open(file_path, "r")
16+
if file_handle then
17+
local file_content = file_handle:read("*all")
18+
local decoded_value = yajl.to_value(file_content)
19+
file_handle:close()
20+
return decoded_value
21+
end
22+
end
23+
24+
scripts.utils:load_data_from_files()

0 commit comments

Comments
 (0)