Module:Infobox Recipe: Difference between revisions
no edit summary
The Gaffer (talk | contribs) No edit summary |
The Gaffer (talk | contribs) No edit summary |
||
Line 37:
if showFullRecipe then
local Materials = p._getTrueRawMaterials(argsMaterials)
if next(Materials) ~= nil then
rawMaterials = Materials.rawMaterials
Line 45 ⟶ 44:
rawMaterials = argsMaterials
end
mw.logObject(rawMaterials)
--Simple query to get the shop buy price for the provided material, if no buy price is available returns 0
Line 67 ⟶ 68:
--Set SMW properties
mw.smw.set({
["Uses item"] =
["Uses item_and_quantity"] = material.name .. ',' .. tostring(material.quantity)
end▼
})
end
Line 88 ⟶ 80:
end
--Creates a row suitable for the raw materials section of the infobox.
local function createRawMaterialRow(item
local materialBuyPrice = getBuyPrice(item)
rawMaterialCost = rawMaterialCost + materialBuyPrice
Line 103 ⟶ 95:
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(item.quantity or 1)
:done()
:wikitext(currency_cell(materialBuyPrice))
Line 109 ⟶ 101:
end
--Creates a row suitable for the intermediate materials section of the infobox.
local function createIntermediateMaterialRow(item
local facility = getFacility(item)
return mw.html.create('tr')
Line 123 ⟶ 115:
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(item.quantity or 1)
:done()
:tag('td')
Line 200 ⟶ 192:
-- Values
for _, material in ipairs(rawMaterials) do
mw.logObject(material)
out:node(createRawMaterialRow(material))
end
Line 300 ⟶ 293:
end
--This function takes a table containing the raw materials params received from the calling template.
--For each of the raw materials, a query will be executed to see if it has the property 'Uses item'.
--If it does, that means that the 'raw material' is actually an 'intermediate material' as it is itself created.
--This allows for a full recipe to be shown where only intermediate ingredients were provided.
function p._getTrueRawMaterials(argsMaterials)
--mw.logObject(result)
-- Add the raw materials used by this intermediate material to rawMaterials
local quantities = result[1]["Uses item and quantity"]
▲ if result and result[1] and result[1]["Uses item"] then
for index, usedItem in ipairs(usesItems) do
▲ -- The item is an intermediate material, add it to intermediateMaterials
▲ table.insert(intermediateMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] })
local quantity = 1
if quantities and type(quantities) == "table" then
▲ -- Add the raw materials used by this intermediate material to rawMaterials
local quantityString = quantities[index]
▲ local usesItems = result[1]["Uses item"]
local _, qty = quantityString:match("(.-),(%d+)")
quantity = tonumber(qty) or 1
▲ if type(usesItems) == "table" then
mw.logObject(tonumber(qty))
▲ for _, usedItem in ipairs(usesItems) do
end
▲ local pageName = usedItem:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")
end
else
local quantity = 1
table.insert(rawMaterials, { ["name"] = pageName, ["quantity"] = 1 })▼
if quantities and type(quantities) == "string" then
local _, qty = quantities:match("(.-),(%d+)")
quantity = tonumber(qty) or 1
-- The item is a raw material, add it to rawMaterials▼
end
table.insert(rawMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] })▼
end
else
mw.logObject(item)
end
end
end
|