Module:Infobox Recipe: Difference between revisions

Tidy
No edit summary
(Tidy)
Line 14:
--If set to true, will check if any of the items passed as a rawmaterialparam are actually intermediate materials. Will then change the display order of the infobox.
local showFullRecipe = yn(args.showFull or 'no', false)
 
 
--Get each of the rawmatX parameters from params and store their values in a new table
local argsMaterials = p._extractRawMaterials(args)
--empty tables to hold materials
local rawMaterials = {}
local intermediateMaterials = {}
 
--counter for total price of raw materials
local rawMaterialCost = 0
Line 26 ⟶ 28:
--get the value for the output product
local output1Value = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')
--Calculate total value of output material(s)
local output1TotalValue = 0
if output1Value[1]['Value'] ~= nil then
Line 32 ⟶ 36:
output1TotalValue = 0
end
 
 
 
--Check if any of the raw mats provided are intermediate products, if they are, return their own raw materials
Line 43 ⟶ 49:
rawMaterials = argsMaterials
end
 
 
--Simple query to get the shop buy price for the provided material, if no buy price is available returns 0
Line 52 ⟶ 60:
return 0
end
 
 
 
--If one of the raw materials provided as a param has been identified as an intermediate material then get the facility it is created at to display in the intermediate Ingredient row
Line 63 ⟶ 73:
return pageName
end
 
 
 
--Set SMW properties
Line 71 ⟶ 83:
})
end
if args.facility then
mw.smw.set({
Line 76 ⟶ 89:
})
end
 
 
 
--Creates a row suitable for the raw materials section of the infobox.
Line 97 ⟶ 112:
:done()
end
 
 
 
--Creates a row suitable for the intermediate materials section of the infobox.
Line 121 ⟶ 138:
:done()
end
 
 
 
-- Recipe Table Head
Line 171 ⟶ 190:
:done()
 
-- Add raw materials
-- Headers
:tag('tr')
:tag('th')
Line 187 ⟶ 206:
:done()
 
-- Values
for _, material in ipairs(rawMaterials) do
out:node(createRawMaterialRow(material))
end
 
-- Add total raw cost
out
:tag('tr')
Line 202 ⟶ 221:
:done()
 
-- Add Intermediate steps if required
-- Headers
if next(intermediateMaterials) ~= nil then
Line 221 ⟶ 240:
:done()
 
-- Values
for _, material in ipairs(intermediateMaterials) do
mw.logObject(material)
Line 228 ⟶ 247:
end
 
-- Add output data
-- Headers
out
-- Headers
:tag('tr')
:tag('th')
Line 245 ⟶ 264:
:done()
 
-- Values
:tag('tr')
:tag('td')
Line 262 ⟶ 281:
:done()
 
-- Add profit data
:tag('tr')
:tag('th')
Line 273 ⟶ 292:
return out
end
 
 
 
function p._extractRawMaterials(args)
Line 289 ⟶ 310:
return rawMaterials
end
 
 
 
--This function takes a table containing the raw materials params received from the calling template.
Line 346 ⟶ 369:
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
end
 
 
 
function p._reverseTable(t)
Line 354 ⟶ 379:
return reversed
end
 
 
 
return p
956

edits