Module:Item Products: Difference between revisions
From Guinea Isles Wiki
No edit summary |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 28: | Line 28: | ||
-- Render wikitable | -- Render wikitable | ||
local t = mw.html.create('table') | local t = mw.html.create('table') | ||
t:addClass('wikitable sortable products-list align-center- | t:addClass('wikitable sortable products-list align-center-2 align-center-3 align-center-4') | ||
local title_row = t:tag('tr') | local title_row = t:tag('tr') | ||
| Line 40: | Line 40: | ||
:tag('th') | :tag('th') | ||
:attr('data-sort-type', 'number') | :attr('data-sort-type', 'number') | ||
:wikitext(' | :wikitext('Requirements') | ||
:done() | :done() | ||
:tag('th') | :tag('th') | ||
| Line 56: | Line 56: | ||
for _, out in pairs(recipe["output"]) do | for _, out in pairs(recipe["output"]) do | ||
if out["amount"] > 1 then | if out["amount"] > 1 then | ||
output_text = output_text .. string.format("\n* | output_text = output_text .. string.format("\n* {{Plink|%s}} × %s", out["name"], tostring(out["amount"])) | ||
else | else | ||
output_text = output_text .. string.format("\n* {{Plink|%s}}", out["name"]) | output_text = output_text .. string.format("\n* {{Plink|%s}}", out["name"]) | ||
| Line 70: | Line 70: | ||
-- Skills | -- Skills | ||
local skills_text = "" | |||
if recipe["reqs"]["skills"] ~= nil then | |||
skills_text = "{{Plainlist|" | |||
for skill_id, req in pairs(recipe["reqs"]["skills"]) do | |||
skills_text = skills_text .. string.format("\n* {{SkillPic|%s|%s}}", skill_id, req["level"]) | |||
end | |||
skills_text = skills_text .. "}}" | |||
end | |||
-- XP | -- XP | ||
| Line 75: | Line 83: | ||
-- Material list text | -- Material list text | ||
local material_text = "{{Plainlist|" | local material_text = "{{Plainlist|" | ||
for _, | for _, mat in pairs(recipe["mats"]) do | ||
if | if mat["amount"] > 1 then | ||
material_text = material_text .. string.format("\n* | material_text = material_text .. string.format("\n* {{Plink|%s}} × %s", mat["name"], tostring(mat["amount"])) | ||
else | else | ||
material_text = material_text .. string.format("\n* {{Plink|%s}}", | material_text = material_text .. string.format("\n* {{Plink|%s}}", mat["name"]) | ||
end | end | ||
end | end | ||
| Line 87: | Line 95: | ||
local prow = t:tag('tr') | local prow = t:tag('tr') | ||
:tag('td') | :tag('td') | ||
:wikitext(output_text) | :wikitext(frame:preprocess(output_text)) | ||
:tag('td') | :tag('td') | ||
:wikitext( | :wikitext(frame:preprocess(station_text)) | ||
:tag('td') | :tag('td') | ||
:wikitext( | :wikitext(frame:preprocess(skills_text)) | ||
:tag('td') | :tag('td') | ||
:wikitext("") | :wikitext("") | ||
:tag('td') | :tag('td') | ||
:wikitext(material_text) | :wikitext(frame:preprocess(material_text)) | ||
:done() | :done() | ||
end | end | ||
Latest revision as of 15:01, 21 September 2025
Documentation for this module may be created at Module:Item Products/doc
local recipes = require('Module:Recipes')
local p = {}
function p.main(frame)
local args = frame:getParent().args
-- Get recipe data
local item_id = nil
if args["id"] ~= nil then
item_id = args["id"]
else
item_id = mw.title.getCurrentTitle().text
end
if item_id == nil then
return "Error: No item id found"
end
local products = recipes.get_item_products(item_id)
if products == nil then
return "Error: Unable to find id " .. item_id .. " in recipes through get_item_products!"
end
if products == {} then
return "No products found for id " .. item_id .. " in recipes through get_item_products."
end
-- Render wikitable
local t = mw.html.create('table')
t:addClass('wikitable sortable products-list align-center-2 align-center-3 align-center-4')
local title_row = t:tag('tr')
:tag('th')
--:attr('colspan', '2')
:wikitext('Output')
:done()
:tag('th')
:wikitext('Station')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Requirements')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('XP')
:done()
:tag('th')
:wikitext('Materials')
:done()
-- Render rows
for _, recipe in pairs(products) do
-- Output list text
local output_text = "{{Plainlist|"
for _, out in pairs(recipe["output"]) do
if out["amount"] > 1 then
output_text = output_text .. string.format("\n* {{Plink|%s}} × %s", out["name"], tostring(out["amount"]))
else
output_text = output_text .. string.format("\n* {{Plink|%s}}", out["name"])
end
end
output_text = output_text .. "}}"
-- Station
local station_text = "None"
if recipe["station"] ~= nil then
station_text = string.format("[[%s]]", recipe["station"])
end
-- Skills
local skills_text = ""
if recipe["reqs"]["skills"] ~= nil then
skills_text = "{{Plainlist|"
for skill_id, req in pairs(recipe["reqs"]["skills"]) do
skills_text = skills_text .. string.format("\n* {{SkillPic|%s|%s}}", skill_id, req["level"])
end
skills_text = skills_text .. "}}"
end
-- XP
-- Material list text
local material_text = "{{Plainlist|"
for _, mat in pairs(recipe["mats"]) do
if mat["amount"] > 1 then
material_text = material_text .. string.format("\n* {{Plink|%s}} × %s", mat["name"], tostring(mat["amount"]))
else
material_text = material_text .. string.format("\n* {{Plink|%s}}", mat["name"])
end
end
material_text = material_text .. "}}"
-- Create row
local prow = t:tag('tr')
:tag('td')
:wikitext(frame:preprocess(output_text))
:tag('td')
:wikitext(frame:preprocess(station_text))
:tag('td')
:wikitext(frame:preprocess(skills_text))
:tag('td')
:wikitext("")
:tag('td')
:wikitext(frame:preprocess(material_text))
:done()
end
-- Return table
return t
end
return p