trusted
167
edits
(Add vein and gas giant support, and use local variables) |
(Show fractionator percentage instead of time, possibly add infobox recipes?) |
||
Line 50: | Line 50: | ||
table.insert(output, '=== Buildings ===') | table.insert(output, '=== Buildings ===') | ||
table.insert(output, tableRecipes(item, buildings, nil, nil, frame)) | table.insert(output, tableRecipes(item, buildings, nil, nil, frame)) | ||
end | |||
return table.concat(output, '\n') | |||
end | |||
function funcs.itemRecipes(frame) | |||
return itemRecipesForName(frame:getParent().args[1], frame) | |||
end | |||
function funcs.itemRecipesDirect(frame) | |||
return itemRecipesForName(frame.args[1], frame) | |||
end | |||
function itemRecipesForName(name, frame) | |||
local item = itemByName(name) | |||
local output = {} | |||
for _, r in pairs(recipesMakingByID(item.ID)) do | |||
table.insert(output, itemRecipe(r, frame)) | |||
end | |||
local vein = veinMakingByID(item.ID) | |||
if vein then | |||
table.insert(output, veinRecipe(item, vein, frame)) | |||
end | |||
for _, giant in pairs(deduplicateGiants(gasGiantsMakingByID(item.ID))) do | |||
table.insert(output, gasGiantRecipe(giant, frame)) | |||
end | end | ||
return table.concat(output, '\n') | return table.concat(output, '\n') | ||
Line 57: | Line 80: | ||
local result = {} | local result = {} | ||
for _, recipe in pairs(recipes) do | for _, recipe in pairs(recipes) do | ||
local data = { | local data = { | ||
Building = titleCase(machines[recipe.Type]), | Building = titleCase(machines[recipe.Type]), | ||
Recipe = frame | Recipe = itemRecipe(recipe, frame) | ||
} | } | ||
if recipe.Handcraft then | if recipe.Handcraft then | ||
Line 87: | Line 100: | ||
local miner = itemByName(machines.Mine) | local miner = itemByName(machines.Mine) | ||
local minerTech = technologyForRecipeID(recipesMakingByID(miner.ID)[1].ID) | local minerTech = technologyForRecipeID(recipesMakingByID(miner.ID)[1].ID) | ||
local veindata = { | local veindata = { | ||
Building = titleCase(miner.Name), | Building = titleCase(miner.Name), | ||
Replicator = 'Mine', | Replicator = 'Mine', | ||
Technology = titleCase(minerTech.Name), | Technology = titleCase(minerTech.Name), | ||
Recipe = | Recipe = veinRecipe(item, vein, frame), | ||
} | } | ||
table.insert(result, '| ' .. frame:expandTemplate{title='ProductionChain', args=veindata}) | table.insert(result, '| ' .. frame:expandTemplate{title='ProductionChain', args=veindata}) | ||
Line 108: | Line 112: | ||
local collectorTech = technologyForRecipeID(recipesMakingByID(collector.ID)[1].ID) | local collectorTech = technologyForRecipeID(recipesMakingByID(collector.ID)[1].ID) | ||
for _, giant in pairs(gas) do | for _, giant in pairs(gas) do | ||
local gasdata = { | |||
Building = titleCase(collector.Name), | Building = titleCase(collector.Name), | ||
Replicator = 'Mine', | Replicator = 'Mine', | ||
Technology = titleCase(collectorTech.Name), | Technology = titleCase(collectorTech.Name), | ||
Recipe = frame | Recipe = gasGiantRecipe(giant, frame) | ||
} | } | ||
table.insert(result, '| ' .. frame:expandTemplate{title='ProductionChain', args=gasdata}) | table.insert(result, '| ' .. frame:expandTemplate{title='ProductionChain', args=gasdata}) | ||
Line 129: | Line 123: | ||
local prefix = frame:expandTemplate{title='ProductionChainTable/head', args={}} | local prefix = frame:expandTemplate{title='ProductionChainTable/head', args={}} | ||
return string.format('%s\n%s\n|}', prefix, table.concat(result, '\n|-\n')) | return string.format('%s\n%s\n|}', prefix, table.concat(result, '\n|-\n')) | ||
end | |||
function itemRecipe(recipe, frame) | |||
if recipe.Type == 'Fractionate' then | |||
return fractionateRecipe(recipe, frame) | |||
end | |||
local rdata = { | |||
CraftTime = string.format('%s s', tostring(recipe.TimeSpend/60)), | |||
} | |||
for i, itemid in ipairs(recipe.Results) do | |||
rdata[string.format('Out%d', i)] = titleCase(itemByID(itemid).Name) | |||
rdata[string.format('Out%dQty', i)] = tostring(recipe.ResultCounts[i]) | |||
end | |||
for i, itemid in ipairs(recipe.Items) do | |||
rdata[string.format('In%d', i)] = titleCase(itemByID(itemid).Name) | |||
rdata[string.format('In%dQty', i)] = tostring(recipe.ItemCounts[i]) | |||
end | |||
return frame:expandTemplate{title='ItemRecipe', args=rdata} | |||
end | |||
function fractionateRecipe(recipe, frame) | |||
local ratio = 100 * recipe.ResultCounts[1] / recipe.ItemCounts[1] | |||
local rdata = { | |||
CraftTime = tostring(ratio) .. '%', | |||
} | |||
for i, itemid in ipairs(recipe.Results) do | |||
rdata[string.format('Out%d', i)] = titleCase(itemByID(itemid).Name) | |||
rdata[string.format('Out%dQty', i)] = '1' | |||
end | |||
for i, itemid in ipairs(recipe.Items) do | |||
rdata[string.format('In%d', i)] = titleCase(itemByID(itemid).Name) | |||
rdata[string.format('In%dQty', i)] = '1' | |||
end | |||
return frame:expandTemplate{title='ItemRecipe', args=rdata} | |||
end | |||
function veinRecipe(item, vein, frame) | |||
local vname = string.gsub(vein.Name, '%sVeins$', ' Vein') | |||
local idata = { | |||
In1 = titleCase(vname), | |||
In1Qty = '1', | |||
Out1 = titleCase(item.Name), | |||
Out1Qty = '1', | |||
CraftTime = '2 s', | |||
} | |||
return frame:expandTemplate{title='ItemRecipe', args=idata} | |||
end | |||
function gasGiantRecipe(gas, frame) | |||
local gdata = { | |||
CraftTime = '?', | |||
In1 = titleCase(gas.DisplayName), | |||
In1Qty = '', | |||
} | |||
for i, productID in ipairs(gas.GasItems) do | |||
local product = itemByID(productID) | |||
gdata[string.format('Out%d', i)] = titleCase(product.Name) | |||
gdata[string.format('Out%dQty', i)] = '1' | |||
end | |||
return frame:expandTemplate{title='ItemRecipe', args=gdata} | |||
end | end | ||