Module:Infobox Recipe: Difference between revisions

194 bytes removed ,  Yesterday at 14:24
no edit summary
No edit summary
No edit summary
Line 17:
--Get each of the rawmatX parameters from params and store their values in a new table
local argsMaterials = p._extractRawMaterials(args)
--mw.logObject(argsMaterials)
--empty tables to hold materials
local rawMaterials = {}
Line 44 ⟶ 43:
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 103 ⟶ 100:
--Creates a row suitable for the intermediate materials section of the infobox.
local function createIntermediateMaterialRow(item)
local facility = getFacility(item.name)
return mw.html.create('tr')
:tag('td')
:css{ ['border-right'] = 'none' }
:wikitext('[[File:' .. item.name .. '.png|30px|link=' .. item .. ']]')
:done()
:tag('td')
:css{ ['border-left'] = 'none' }
:wikitext('[[' .. item.name .. ']]')
:done()
:tag('td')
Line 192 ⟶ 189:
-- Values
for _, material in ipairs(rawMaterials) do
mw.logObject(material)
out:node(createRawMaterialRow(material))
end
Line 227 ⟶ 223:
-- Values
for _, material in ipairs(intermediateMaterials) do
out:node(createIntermediateMaterialRow(material.name))
end
end
Line 305 ⟶ 301:
if item["name"] then
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
-- The item is an intermediate material, add it to intermediateMaterials
Line 322 ⟶ 317:
local _, qty = quantityString:match("(.-),(%d+)")
quantity = tonumber(qty) or 1
mw.logObject(tonumber(qty))
end
table.insert(rawMaterials, { ["name"] = pageName, ["quantity"] = quantity })
Line 338 ⟶ 332:
-- The item is a raw material, add it to rawMaterials
table.insert(rawMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] })
mw.logObject(item)
end
end
end
 
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
end
839

edits