trusted
167
edits
(ipairs preserves order, use instead of pairs/sorting) |
(Only display headers if both sections exist, split components/buildings only when making table, remove unused sort) |
||
Line 62: | Line 62: | ||
local header = frame:expandTemplate{title='ProductionChainTable/head', args={}} | local header = frame:expandTemplate{title='ProductionChainTable/head', args={}} | ||
local item = itemByName(name) | local item = itemByName(name) | ||
local components | local components = {} | ||
local buildings = {} | |||
for _, r in ipairs(recipesUsingByID(item.ID)) do | |||
if r.GridIndex >= 2000 then | |||
table.insert(buildings, r) | |||
else | |||
table.insert(components, r) | |||
end | |||
end | |||
if next(components) then | if next(components) then | ||
table.insert(output, '=== Components ===') | if next(buildings) then | ||
table.insert(output, '=== Components ===') | |||
end | |||
table.insert(output, header) | table.insert(output, header) | ||
for _, recipe in ipairs(components) do | for _, recipe in ipairs(components) do | ||
Line 72: | Line 82: | ||
end | end | ||
if next(buildings) then | if next(buildings) then | ||
table.insert(output, '=== Buildings ===') | if next(components) then | ||
table.insert(output, '=== Buildings ===') | |||
end | |||
table.insert(output, header) | table.insert(output, header) | ||
for _, recipe in ipairs(buildings) do | for _, recipe in ipairs(buildings) do | ||
Line 305: | Line 317: | ||
end | end | ||
function recipesUsingByID(id) | function recipesUsingByID(id) | ||
local | local recipes = {} | ||
for _, recipe in ipairs(protosets.RecipeProtoSet.dataArray) do | for _, recipe in ipairs(protosets.RecipeProtoSet.dataArray) do | ||
for _, itemid in ipairs(recipe.Items) do | for _, itemid in ipairs(recipe.Items) do | ||
if itemid == id then | if itemid == id then | ||
table.insert(recipes, recipe) | |||
break | break | ||
end | end | ||
end | end | ||
end | end | ||
return | return recipes | ||
end | end | ||
Line 365: | Line 372: | ||
-- sorting/deduplication | -- sorting/deduplication | ||
function deduplicateGiants(giants) | function deduplicateGiants(giants) |