trusted
167
edits
(Add Mk fixup) |
(Break up recipe row functions, add comments, use recipe ID to determine component/building) |
||
Line 17: | Line 17: | ||
} | } | ||
local OilSeepID = 7 | local OilSeepID = 7 | ||
-- exported functions | |||
function funcs.recipesMaking(frame) | function funcs.recipesMaking(frame) | ||
Line 27: | Line 29: | ||
function recipesMakingName(name, frame) | function recipesMakingName(name, frame) | ||
local rtable = { | |||
frame:expandTemplate{title='ProductionChainTable/head', args={}}, | |||
} | |||
local item = itemByName(name) | local item = itemByName(name) | ||
for _, recipe in pairs(recipesMakingByID(item.ID)) do | |||
table.insert(rtable, recipeRow(recipe, frame)) | |||
end | |||
local vein = veinMakingByID(item.ID) | local vein = veinMakingByID(item.ID) | ||
if vein ~= nil then | |||
table.insert(rtable, veinRow(item, vein, frame)) | |||
end | |||
for _, giant in pairs(deduplicateGiants(gasGiantsMakingByID(item.ID))) do | |||
table.insert(rtable, gasGiantRow(item, giant, frame)) | |||
end | |||
if isItemOcean(item.ID) then | |||
table.insert(rtable, oceanRow(item, ocean, frame)) | |||
end | |||
table.insert(rtable, '|}') | |||
return table.concat(rtable, '\n') | |||
end | end | ||
Line 45: | Line 60: | ||
function recipesUsingName(name, frame) | function recipesUsingName(name, frame) | ||
local output = {} | local output = {} | ||
local header = frame:expandTemplate{title='ProductionChainTable/head', args={}} | |||
local item = itemByName(name) | local item = itemByName(name) | ||
local components, buildings = recipesUsingByID(item.ID) | local components, buildings = recipesUsingByID(item.ID) | ||
if next(components) then | if next(components) then | ||
table.insert(output, '=== Components ===') | table.insert(output, '=== Components ===') | ||
table.insert(output, | table.insert(output, header) | ||
for _, recipe in pairs(components) do | |||
table.insert(output, recipeRow(recipe, frame)) | |||
end | |||
table.insert(output, '|}') | |||
end | end | ||
if next(buildings) then | if next(buildings) then | ||
table.insert(output, '=== Buildings ===') | table.insert(output, '=== Buildings ===') | ||
table.insert(output, | table.insert(output, header) | ||
for _, recipe in pairs(buildings) do | |||
table.insert(output, recipeRow(recipe, frame)) | |||
end | |||
table.insert(output, '|}') | |||
end | end | ||
return table.concat(output, '\n') | return table.concat(output, '\n') | ||
Line 93: | Line 117: | ||
end | end | ||
function | -- make rows and recipe data for tables | ||
local | |||
function recipeRow(recipe, frame) | |||
local rdata = { | |||
Building = titleCase(machines[recipe.Type]), | |||
} | |||
if recipe.Type == 'Fractionate' then | |||
rdata.Recipe = fractionateRecipe(recipe, frame) | |||
else | |||
rdata.Recipe = itemRecipe(recipe, frame) | |||
end | end | ||
if | if recipe.Handcraft then | ||
rdata.Replicator = 'Yes' | |||
else | |||
rdata.Replicator = 'No' | |||
end | end | ||
local tech = technologyForRecipeID(recipe.ID) | |||
if tech ~= nil then | |||
rdata.Technology = titleCase(tech.Name) | |||
else | |||
rdata.Technology = '' | |||
end | end | ||
return '|-\n| ' .. frame:expandTemplate{title='ProductionChain', args=rdata} | |||
end | end | ||
function itemRecipe(recipe, frame) | function itemRecipe(recipe, frame) | ||
local rdata = { | local rdata = { | ||
CraftTime = string.format('%s s', tostring(recipe.TimeSpend/60)), | CraftTime = string.format('%s s', tostring(recipe.TimeSpend/60)), | ||
Line 194: | Line 171: | ||
end | end | ||
return frame:expandTemplate{title='ItemRecipe', args=rdata} | return frame:expandTemplate{title='ItemRecipe', args=rdata} | ||
end | |||
function veinRow(item, vein, frame) | |||
if vein.ID == OilSeepID then -- I don't have a better test for oil right now | |||
local extractor = itemByName(machines.Oil) | |||
local extractorTech = technologyForRecipeID(recipesMakingByID(extractor.ID)[1].ID) | |||
local oildata = { | |||
Building = titleCase(extractor.Name), | |||
Replicator = 'No', | |||
Technology = titleCase(extractorTech.Name), | |||
Recipe = oilRecipe(item, vein, frame), | |||
} | |||
return '|-\n| ' .. frame:expandTemplate{title='ProductionChain', args=oildata} | |||
else | |||
local miner = itemByName(machines.Mine) | |||
local minerTech = technologyForRecipeID(recipesMakingByID(miner.ID)[1].ID) | |||
local veindata = { | |||
Building = titleCase(miner.Name), | |||
Replicator = 'Mine', | |||
Technology = titleCase(minerTech.Name), | |||
Recipe = veinRecipe(item, vein, frame), | |||
} | |||
return '|-\n| ' .. frame:expandTemplate{title='ProductionChain', args=veindata} | |||
end | |||
end | end | ||
Line 217: | Line 218: | ||
} | } | ||
return frame:expandTemplate{title='ItemRecipe', args=odata} | return frame:expandTemplate{title='ItemRecipe', args=odata} | ||
end | |||
function gasGiantRow(item, giant, frame) | |||
local collector = itemByName(machines.Gas) | |||
local collectorTech = technologyForRecipeID(recipesMakingByID(collector.ID)[1].ID) | |||
local giantdata = { | |||
Building = titleCase(collector.Name), | |||
Replicator = 'Mine', | |||
Technology = titleCase(collectorTech.Name), | |||
Recipe = gasGiantRecipe(giant, frame) | |||
} | |||
return '|-\n| ' .. frame:expandTemplate{title='ProductionChain', args=giantdata} | |||
end | end | ||
Line 231: | Line 244: | ||
end | end | ||
return frame:expandTemplate{title='ItemRecipe', args=gdata} | return frame:expandTemplate{title='ItemRecipe', args=gdata} | ||
end | |||
function oceanRow(item, ocean, frame) | |||
local pump = itemByName(machines.Ocean) | |||
local pumpTech = technologyForRecipeID(recipesMakingByID(pump.ID)[1].ID) | |||
local oceandata = { | |||
Building = titleCase(pump.Name), | |||
Replicator = 'No', | |||
Technology = titleCase(pumpTech.Name), | |||
Recipe = oceanRecipe(item, frame) | |||
} | |||
return '|-\n| ' .. frame:expandTemplate{title='ProductionChain', args=oceandata} | |||
end | end | ||
Line 243: | Line 268: | ||
return frame:expandTemplate{title='ItemRecipe', args=odata} | return frame:expandTemplate{title='ItemRecipe', args=odata} | ||
end | end | ||
-- get data from protosets | |||
function itemByName(name) | function itemByName(name) | ||
Line 280: | Line 307: | ||
for _, itemid in pairs(recipe.Items) do | for _, itemid in pairs(recipe.Items) do | ||
if itemid == id then | if itemid == id then | ||
if itemByID(recipe.Results[1]). | if itemByID(recipe.Results[1]).ID > 2000 then | ||
table.insert(buildings, recipe) | table.insert(buildings, recipe) | ||
else | else | ||
Line 333: | Line 360: | ||
return false | return false | ||
end | end | ||
-- deduplication | |||
function deduplicateGiants(giants) | function deduplicateGiants(giants) | ||
Line 348: | Line 377: | ||
return dedup | return dedup | ||
end | end | ||
-- display formatting | |||
function titleCase(str) | function titleCase(str) |