-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_util.lua
42 lines (35 loc) · 1012 Bytes
/
mod_util.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
local mod_util = {}
function mod_util.icon_to_icons(prototype)
if not prototype.icons then
prototype.icons = {{icon = prototype.icon, icon_size = prototype.icon_size}}
prototype.icon = nil
prototype.icon_size = nil
end
end
function mod_util.set_icon_tint(prototype, tint)
mod_util.icon_to_icons(prototype)
for _, icon in pairs(prototype.icons) do
icon.tint = tint
end
end
function mod_util.iterate_recursive(value, callback, parent, key)
if (not callback(parent, key, value)) and type(value) == "table" then
for k, v in pairs(value) do
mod_util.iterate_recursive(v, callback, value, k)
end
end
end
function mod_util.get_optional(parent, key)
return parent and parent[key]
end
function mod_util.set_optional(parent, key, value)
if type(parent) == "table" then
parent[key] = value
end
end
function mod_util.deepcopy_optional(parent, key)
if parent and type(parent[key]) == "table" then
return table.deepcopy(parent[key])
end
end
return mod_util