Module:Infobox Recipe: Difference between revisions

no edit summary
(Link all images to the item/facility; Get rid of border between item image and name)
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 27 ⟶ 28:
local output1Value = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')
local output1TotalValue = 0
mw.logObject(output1Value[1]['Value'])
if output1Value[1]['Value'] ~= nil then
output1TotalValue = output1Value[1]['Value'] * (tonumber(args.output1qty) or 1)
Line 36:
--Check if any of the raw mats provided are intermediate products, if they are, return their own raw materials
if showFullRecipe then
local trueRawMaterialsMaterials = p._getTrueRawMaterials(argsMaterials)
if next(trueRawMaterialsMaterials) ~= nil then
rawMaterials = trueRawMaterialsMaterials.rawMaterials
intermediateMaterials = argsMaterials
intermediateMaterials = Materials.intermediateMaterials
end
else
rawMaterials = argsMaterials
end
 
--Simple query to get the shop buy price for the provided material, if no buy price is available returns 0
local function getBuyPrice(material)
Line 300 ⟶ 301:
 
function p._getTrueRawMaterials(argsMaterials)
local queryResultrawMaterials = {}
local intermediateMaterials = argsMaterials{}
 
for _, item in pairs(argsMaterials) do
if item["name"] then
Line 306 ⟶ 309:
 
if result and result[1] and result[1]["Uses item"] then
-- The item is an intermediate material, add it to intermediateMaterials
table.insert(intermediateMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] })
-- Add the raw materials used by this intermediate material to rawMaterials
local usesItems = result[1]["Uses item"]
 
-- If usesItems is a table (multiple items), iterate and add each to queryResult
if type(usesItems) == "table" then
for _, usedItem in ipairs(usesItems) do
local pageName = usedItem:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")
table.insert(queryResultrawMaterials, { ["name"] = pageName, ["quantity"] = 1 })
end
else
-- If usesItems is a single item, add it directly
local pageName = usesItems:gsub("%[%[", ""):gsub("%]%]", ""):gsub("|.*", ""):gsub("^:", "")
table.insert(queryResultrawMaterials, { ["name"] = pageName, ["quantity"] = 1 })
end
else
-- The item is a raw material, add it to rawMaterials
table.insert(rawMaterials, { ["name"] = item["name"], ["quantity"] = item["quantity"] })
end
end
end
 
return queryResult
return { rawMaterials = rawMaterials, intermediateMaterials = intermediateMaterials }
end
 
956

edits