Fixed and improved data handling in data.lua.

This commit is contained in:
Filipe Rodrigues 2021-09-26 22:31:43 +01:00
parent cbf2ef36a1
commit 801bec4050

View File

@ -2,28 +2,24 @@
-- Imports
local lbn = require("lbn")
local table_len = lbn.util.table_len
local table_map = lbn.util.table_map
local table_values = lbn.util.table_values
local array_flatten = lbn.util.array_flatten
-- Get all data modules to add
local data_mods = { "entities", "hotkeys", "items", "recipies", "technologies" }
local data = table_map(data_mods, function(_, mod)
local data_to_add = lbn.util.array_map_table(data_mods, function(mod)
return mod, require(("data.%s"):format(mod))
end)
-- Log all data we got
-- Then add them all
do
for name, table in pairs(data) do
log(("Found %i %s"):format(table_len(table), name))
for name, arr in pairs(data_to_add) do
lbn.util.assert_array(arr)
if settings.startup["lbn:log"].value then
log(("Adding %i %s: %s"):format(#arr, name, lbn.util.format_array(arr)))
end
if #arr ~= 0 then
data:extend(arr)
end
end
end
-- Then flatten it to get all data
local all_data = array_flatten(table_values(data))
-- Then, if not empty, add it all
if #all_data ~= 0 then
data:extend(all_data)
end