-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
61 lines (53 loc) · 1.34 KB
/
init.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
-- Removes non-serializable data
local function sanitize_table(t)
-- Detect mixed tables
local seen_non_str_keys = false
local seen_str_keys = false
for key, _ in pairs(t) do
if type(key) == 'string' then
seen_str_keys = true
else
seen_non_str_keys = true
end
end
if seen_non_str_keys and seen_str_keys then
for k in pairs(t) do
t[k] = nil
end
return
end
-- Detect non-serializable values
for key, value in pairs(t) do
local value_type = type(value)
if value_type == 'function' or value_type == 'userdata' then
t[key] = nil
elseif value_type == 'table' then
sanitize_table(value)
end
end
end
core.after(0, function()
local game = {}
game.aliases = table.copy(core.registered_aliases)
game.nodes = table.copy(core.registered_nodes)
sanitize_table(game)
for name, node in pairs(game.nodes) do
if node.tiles ~= nil and node.tiles.name ~= nil then
game.nodes[name]["tiles"] = {node["tiles"]["name"]}
end
if node.tiles ~= nil then
for i, tile in ipairs(node.tiles) do
if type(tile) == "table" then
node.tiles[i] = tile.name
end
if type(tile) ~= "string" and type(tile) ~= "table" then
node.tiles[i] = nil
end
end
end
end
local file = io.open(core.get_worldpath() .. '/nodes_dump.json', 'wb')
local json = core.write_json(game, true)
file:write(json)
file:close()
end)