Module:Infobox Recipe: Difference between revisions
no edit summary
The Gaffer (talk | contribs) No edit summary |
The Gaffer (talk | contribs) No edit summary |
||
Line 38:
if next(Materials) ~= nil then
rawMaterials = Materials.rawMaterials
intermediateMaterials = p._reverseTable(Materials.intermediateMaterials)
end
else
Line 223:
-- Values
for _, material in ipairs(intermediateMaterials) do
mw.logObject(material)
out:node(createIntermediateMaterialRow(material))
end
Line 298 ⟶ 299:
local intermediateMaterials = {}
local function _processMaterial(material, quantity)
for _, item in pairs(argsMaterials) do▼
if
local result = mw.smw.ask('[[:+]][[' ..
if result and result[1] and result[1]["Uses item"] then
-- The item is an intermediate material, add it to intermediateMaterials
table.insert(intermediateMaterials, { ["name"] =
-- Add the raw materials used by this intermediate material to rawMaterials
Line 312 ⟶ 313:
for index, usedItem in ipairs(usesItems) do
local pageName = usedItem:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")
local
if quantities and type(quantities) == "table" then
local quantityString = quantities[index]
local _,
end
end
else
local pageName = usesItems:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")
local
if quantities and type(quantities) == "string" then
local _,
end
end
else
-- The item is a raw material, add it to rawMaterials
table.insert(rawMaterials, { ["name"] =
end
end
end
-- Iterate over the initial argsMaterials
▲ for _, item in pairs(argsMaterials) do
if item["name"] then
_processMaterial(item["name"], item["quantity"])
end
end
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
end
function p._reverseTable(t)
local reversed = {}
for i = #t, 1, -1 do
table.insert(reversed, t[i])
end
return reversed
end
|