Module:Infobox Recipe: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
The Gaffer (talk | contribs) No edit summary |
The Gaffer (talk | contribs) No edit summary |
||
Line 17: | Line 17: | ||
--Get each of the rawmatX parameters from params and store their values in a new table |
--Get each of the rawmatX parameters from params and store their values in a new table |
||
local argsMaterials = p._extractRawMaterials(args) |
local argsMaterials = p._extractRawMaterials(args) |
||
--mw.logObject(argsMaterials) |
|||
--empty tables to hold materials |
--empty tables to hold materials |
||
local rawMaterials = {} |
local rawMaterials = {} |
||
Line 44: | Line 43: | ||
rawMaterials = argsMaterials |
rawMaterials = argsMaterials |
||
end |
end |
||
mw.logObject(rawMaterials) |
|||
--Simple query to get the shop buy price for the provided material, if no buy price is available returns 0 |
--Simple query to get the shop buy price for the provided material, if no buy price is available returns 0 |
||
Line 103: | Line 100: | ||
--Creates a row suitable for the intermediate materials section of the infobox. |
--Creates a row suitable for the intermediate materials section of the infobox. |
||
local function createIntermediateMaterialRow(item) |
local function createIntermediateMaterialRow(item) |
||
local facility = getFacility(item) |
local facility = getFacility(item.name) |
||
return mw.html.create('tr') |
return mw.html.create('tr') |
||
:tag('td') |
:tag('td') |
||
:css{ ['border-right'] = 'none' } |
:css{ ['border-right'] = 'none' } |
||
:wikitext('[[File:' .. item .. '.png|30px|link=' .. item .. ']]') |
:wikitext('[[File:' .. item.name .. '.png|30px|link=' .. item .. ']]') |
||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:css{ ['border-left'] = 'none' } |
:css{ ['border-left'] = 'none' } |
||
:wikitext('[[' .. item .. ']]') |
:wikitext('[[' .. item.name .. ']]') |
||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
Line 192: | Line 189: | ||
-- Values |
-- Values |
||
for _, material in ipairs(rawMaterials) do |
for _, material in ipairs(rawMaterials) do |
||
mw.logObject(material) |
|||
out:node(createRawMaterialRow(material)) |
out:node(createRawMaterialRow(material)) |
||
end |
end |
||
Line 227: | Line 223: | ||
-- Values |
-- Values |
||
for _, material in ipairs(intermediateMaterials) do |
for _, material in ipairs(intermediateMaterials) do |
||
out:node(createIntermediateMaterialRow(material |
out:node(createIntermediateMaterialRow(material)) |
||
end |
end |
||
end |
end |
||
Line 305: | Line 301: | ||
if item["name"] then |
if item["name"] then |
||
local result = mw.smw.ask('[[:+]][[' .. item["name"] .. ']]|?Uses item|?Uses item_and_quantity') |
local result = mw.smw.ask('[[:+]][[' .. item["name"] .. ']]|?Uses item|?Uses item_and_quantity') |
||
--mw.logObject(result) |
|||
if result and result[1] and result[1]["Uses item"] then |
if result and result[1] and result[1]["Uses item"] then |
||
-- The item is an intermediate material, add it to intermediateMaterials |
-- The item is an intermediate material, add it to intermediateMaterials |
||
Line 322: | Line 317: | ||
local _, qty = quantityString:match("(.-),(%d+)") |
local _, qty = quantityString:match("(.-),(%d+)") |
||
quantity = tonumber(qty) or 1 |
quantity = tonumber(qty) or 1 |
||
mw.logObject(tonumber(qty)) |
|||
end |
end |
||
table.insert(rawMaterials, { ["name"] = pageName, ["quantity"] = quantity }) |
table.insert(rawMaterials, { ["name"] = pageName, ["quantity"] = quantity }) |
||
Line 338: | Line 332: | ||
-- The item is a raw material, add it to rawMaterials |
-- The item is a raw material, add it to rawMaterials |
||
table.insert(rawMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] }) |
table.insert(rawMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] }) |
||
mw.logObject(item) |
|||
end |
end |
||
end |
end |
||
end |
end |
||
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials } |
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials } |
||
end |
end |