Module:Infobox Recipe: Difference between revisions
m
Spaces to tabs
The Gaffer (talk | contribs) No edit summary |
m (Spaces to tabs) |
||
Line 2:
function p._main(frame)
local argsMaterials = p._extractRawMaterials(args)
--empty tables to hold materials
local rawMaterials = {}
local intermediateMaterials = {}
--counter for total price of raw materials
--get the value for the output product
local output1Value = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')
Line 29:
output1TotalValue = 0
end
--Check if any of the raw mats provided are intermediate products, if they are, return their own raw materials
if showFullRecipe then
Line 45:
local queryResult = mw.smw.ask('[[:+]][[Sold item::' .. material['name'] .. ']]|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or 0
if type(queryResult) == "table" and queryResult[1]['Shop buy price'] then
end
Line 55:
local pageName = ''
if result and result[1] and result[1]["Uses facility"] then
end
--Set SMW properties
if args.rawmat1 then
})
})
})
mw.smw.set({
["Uses facility"] = args.facility
Line 89:
local row = {}
table.insert(row, '| [[File:' .. item['name'] .. '.png|30px]]')
end
--Creates a row suitable for the intermediate materials section of the infobox. Quantity is optional, if no value is provided it will default to 1
local function createIntermediateMaterialRow(item, quantity)
Line 101:
local facility = getFacility(item)
table.insert(row, '| [[File:' .. item .. '.png|30px]]')
-- Recipe Table Head
-- Add raw materials
-- Add total raw cost
-- Add Intermediate steps if required
-- Headers
-- Add output data
-- Values▼
table.insert(out, '| [[File:' .. args.output1 .. '.png|30px]]')▼
table.insert(out, '| ' .. (args.output1 and '[[' .. args.output1 .. ']]' or 'Unknown'))▼
table.insert(out, '| style="text-align: right;" | ' .. (args.output1qty or 1))▼
table.insert(out, '| style="text-align: right;" | ' .. currency(output1TotalValue))▼
table.insert(out, '|-')▼
-- Add profit data▼
table.insert(out, '! colspan="3" | Profit')▼
table.insert(out, '| style="text-align: right;" | ' .. currency(output1TotalValue - rawMaterialCost))▼
table.insert(out, '|}')▼
return table.concat(out, '\n')▼
▲
end
function p._extractRawMaterials(args)
end
function p._getTrueRawMaterials(argsMaterials)
if result and result[1] and result[1]["Uses item"] then▼
-- If usesItems is a table (multiple items), iterate and add each to queryResult▼
local
for _, usedItem in ipairs(usesItems) do▼
local pageName = usedItem:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")▼
if type(usesItems) == "table" then
table.insert(queryResult, { ["name"] = pageName, ["quantity"] = 1 })▼
-- If usesItems is a single item, add it directly▼
end
local pageName = usesItems:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")▼
else
table.insert(queryResult, { ["name"] = pageName, ["quantity"] = 1 })▼
end
return queryResult▼
end
end
end
|