forked from Oinite12/tiwmig-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.lua
More file actions
62 lines (54 loc) · 1.97 KB
/
index.lua
File metadata and controls
62 lines (54 loc) · 1.97 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
-- Loading features
SMODS.current_mod.optional_features = {
retrigger_joker = true
}
G_TWMG = G_TWMG or {}
G_TWMG.mod_path = tostring(SMODS.current_mod.path)
F_TWMG = F_TWMG or {}
-- == VARIABLES
G_TWMG.max_card_layers = 3
G_TWMG.infinite_joker_iterator = {
index = 0,
group_size = 10
}
-- A shorthand of adding an event to G.E_MANAGER that only defines the properties trigger, delay, and func.\
-- Event function will always return true, so "return true" is not required.\
-- Consequently, do not use this function if the event function needs to return a non-true value\
-- or if other parameters such as blocking require specification.
---@param trigger string | nil
---@param delay number | nil
---@param func function
---@return nil
F_TWMG.add_simple_event = function(trigger, delay, func)
-- This is here in the main mod file so it's loaded before everything,
-- because everything uses this function
G.E_MANAGER:add_event(Event {
trigger = trigger,
delay = delay,
func = function() func(); return true end
})
end
-- Loads all Lua files in a directory.
---@param folder_name string
---@param condition_function? fun(file_name: string): boolean
---@return nil
function F_TWMG.load_directory(folder_name, condition_function)
local mod_path = G_TWMG.mod_path
local files = NFS.getDirectoryItems(mod_path .. folder_name)
local console_label = "TIWMIG"
for _,file_name in ipairs(files) do
local condition_is_met = true
if condition_function then condition_is_met = condition_function(file_name) end
if file_name:match(".lua$") and condition_is_met then
local console_line_format = ("[%s] Loading file %s")
local file_format = ("%s/%s")
print(console_line_format:format(console_label, file_name))
local file_func, err = SMODS.load_file(file_format:format(folder_name, file_name))
if err then error(err) end
if file_func then file_func() end
end
end
end
F_TWMG.load_directory("func")
F_TWMG.load_directory("load_assets")
F_TWMG.load_directory("items")