forked from beyond-all-reason/Beyond-All-Reason
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspringOverrides.lua
75 lines (61 loc) · 1.95 KB
/
springOverrides.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
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
if Spring.GetModOptions then
local modOptions = Spring.GetModOptions()
local modOptionsFile = VFS.Include('modoptions.lua')
for _, modOption in ipairs(modOptionsFile) do
local key = modOption.key
if modOption.type ~= "section" then
if modOptions[key] == nil then
modOptions[key] = modOption.def
end
if (modOption.type == 'bool') and (type(modOptions[key]) ~= 'boolean') then
local value = tonumber(modOptions[key])
modOptions[key] = value == 1 and true or false
end
if modOption.type == 'number' then
modOptions[key] = tonumber(modOptions[key])
end
end
end
-- Prevent widgets from messing with each other's modoptions table.
-- The native engine call does this by returning a new table each time but that is wasteful
local readOnlyModOptions = {}
setmetatable(readOnlyModOptions, {
__index = modOptions,
__newindex = function(t, k, v)
error("attempt to update a read-only Spring.GetModOptions table", 2)
end
})
Spring.GetModOptions = function ()
return readOnlyModOptions
end
-- Returns a copy of the modOptions table. Slower, but allows iterating over
-- the returned table using pairs/ipairs.
Spring.GetModOptionsCopy = function ()
return table.copy(modOptions)
end
end
if Spring.Echo then
local echo = Spring.Echo
local printOptions = { pretty = true }
local function multiEcho(...)
local args = table.pack(...)
local tableIndexes = {}
for index = 1, args.n do
local value = args[index]
if type(value) == 'table' then
table.insert(tableIndexes, index)
end
end
-- When Spring.Echo is called with a single table parameter, engine will echo "TABLE: {value}",
-- where {value} is whatever value happens to be the first value in the table
if #tableIndexes == 1 and args.n == 1 then
echo("<table>")
else
echo(unpack(args, 1, args.n))
end
for _, index in ipairs(tableIndexes) do
echo(table.toString(args[index], printOptions))
end
end
Spring.Echo = multiEcho
end