compacting-storage.lua: I forgot how table constructors work

This commit is contained in:
Emerson Rosen-Jones 2025-11-17 19:18:23 -05:00
parent d3f03632e2
commit cce18737d2

View file

@ -122,7 +122,7 @@ function dist_to_num (dist)
end end
function get_dist (item_type, items) function get_dist (item_type, items)
local dist = { nuggets: 0, ingots: 0, blocks: 0 } local dist = { nuggets = 0, ingots = 0, blocks = 0 }
for _, item in pairs(items) do for _, item in pairs(items) do
local type, form = item.name:match".-:(%l-)_(%l*)" local type, form = item.name:match".-:(%l-)_(%l*)"
if type == item_type and dist[form] ~= nil then if type == item_type and dist[form] ~= nil then
@ -134,15 +134,15 @@ end
function get_diff (dist1, dist2) function get_diff (dist1, dist2)
return { return {
nuggets: dist1.nuggets - dist2.nuggets, nuggets = dist1.nuggets - dist2.nuggets,
ingots: dist1.ingots - dist2.ingots, ingots = dist1.ingots - dist2.ingots,
blocks: dist1.blocks - dist2.blocks blocks = dist1.blocks - dist2.blocks
} }
end end
function filter_clamp (diff, current_dist) function filter_clamp (diff, current_dist)
-- reduce diff numbers to what can be crafted using current resources -- reduce diff numbers to what can be crafted using current resources
local new_diff = { nuggets: 0, ingots: 0, blocks: 0 } local new_diff = { nuggets = 0, ingots = 0, blocks = 0 }
if diff.blocks > 0 then if diff.blocks > 0 then
new_diff.blocks = math.min( new_diff.blocks = math.min(
diff.blocks, diff.blocks,