Module:Infobox Recipe: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
(Tidy)
Line 14: 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.
--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)
local showFullRecipe = yn(args.showFull or 'no', false)



--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)
--empty tables to hold materials
--empty tables to hold materials
local rawMaterials = {}
local rawMaterials = {}
local intermediateMaterials = {}
local intermediateMaterials = {}

--counter for total price of raw materials
--counter for total price of raw materials
local rawMaterialCost = 0
local rawMaterialCost = 0
Line 26: Line 28:
--get the value for the output product
--get the value for the output product
local output1Value = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')
local output1Value = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')
--Calculate total value of output material(s)
local output1TotalValue = 0
local output1TotalValue = 0
if output1Value[1]['Value'] ~= nil then
if output1Value[1]['Value'] ~= nil then
Line 32: Line 36:
output1TotalValue = 0
output1TotalValue = 0
end
end




--Check if any of the raw mats provided are intermediate products, if they are, return their own raw materials
--Check if any of the raw mats provided are intermediate products, if they are, return their own raw materials
Line 43: Line 49:
rawMaterials = argsMaterials
rawMaterials = argsMaterials
end
end


--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 52: Line 60:
return 0
return 0
end
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
--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: Line 73:
return pageName
return pageName
end
end




--Set SMW properties
--Set SMW properties
Line 71: Line 83:
})
})
end
end
if args.facility then
if args.facility then
mw.smw.set({
mw.smw.set({
Line 76: Line 89:
})
})
end
end




--Creates a row suitable for the raw materials section of the infobox.
--Creates a row suitable for the raw materials section of the infobox.
Line 97: Line 112:
:done()
:done()
end
end




--Creates a row suitable for the intermediate materials section of the infobox.
--Creates a row suitable for the intermediate materials section of the infobox.
Line 121: Line 138:
:done()
:done()
end
end




-- Recipe Table Head
-- Recipe Table Head
Line 171: Line 190:
:done()
:done()


-- Add raw materials
-- Add raw materials
-- Headers
-- Headers
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
Line 187: Line 206:
:done()
:done()


-- Values
-- Values
for _, material in ipairs(rawMaterials) do
for _, material in ipairs(rawMaterials) do
out:node(createRawMaterialRow(material))
out:node(createRawMaterialRow(material))
end
end


-- Add total raw cost
-- Add total raw cost
out
out
:tag('tr')
:tag('tr')
Line 202: Line 221:
:done()
:done()


-- Add Intermediate steps if required
-- Add Intermediate steps if required
-- Headers
-- Headers
if next(intermediateMaterials) ~= nil then
if next(intermediateMaterials) ~= nil then
Line 221: Line 240:
:done()
:done()


-- Values
-- Values
for _, material in ipairs(intermediateMaterials) do
for _, material in ipairs(intermediateMaterials) do
mw.logObject(material)
mw.logObject(material)
Line 228: Line 247:
end
end


-- Add output data
-- Add output data
-- Headers
out
out
-- Headers
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
Line 245: Line 264:
:done()
:done()


-- Values
-- Values
:tag('tr')
:tag('tr')
:tag('td')
:tag('td')
Line 262: Line 281:
:done()
:done()


-- Add profit data
-- Add profit data
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
Line 273: Line 292:
return out
return out
end
end




function p._extractRawMaterials(args)
function p._extractRawMaterials(args)
Line 289: Line 310:
return rawMaterials
return rawMaterials
end
end




--This function takes a table containing the raw materials params received from the calling template.
--This function takes a table containing the raw materials params received from the calling template.
Line 346: Line 369:
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
end
end




function p._reverseTable(t)
function p._reverseTable(t)
Line 354: Line 379:
return reversed
return reversed
end
end




return p
return p