mirror of
https://github.com/Zenithsiz/logistic-belt-network.git
synced 2026-02-03 09:50:34 +00:00
Fixed and improved data handling in data.lua.
This commit is contained in:
parent
cbf2ef36a1
commit
801bec4050
28
data.lua
28
data.lua
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user