Module:Item Products: Difference between revisions

From Guinea Isles Wiki
No edit summary
No edit summary
Line 30: Line 30:
local title_row = t:tag('tr')
local title_row = t:tag('tr')
         :tag('th')
         :tag('th')
             :attr('colspan', '2')
             --:attr('colspan', '2')
             :wikitext('Item')
             :wikitext('Output')
         :done()
         :done()
         :tag('th')
         :tag('th')
Line 50: Line 50:
     -- Render rows
     -- Render rows
     for _, recipe in pairs(products) do
     for _, recipe in pairs(products) do
     -- Name
     -- Outputs
     local name_str
     local output_text = "{{plainlist"
    for _, out in recipe["outputs"] do
    if out["amount"] > 1 then
    output_text = output_text .. string.format("|{{plink|%s}} x %s", out["name"], tostring(out["amount"]))
    else
    output_text = output_text .. string.format("|{{plink|%s}}", out["name"])
    end
    end
    
    
    output_text = output_text .. "}}"
   
    return output_text
     end
     end
      
      

Revision as of 18:41, 20 September 2025

Documentation for this module may be created at Module:Item Products/doc

local recipes = require('Module:Recipes')

local p = {}

function p._main(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-1 align-center-3 align-center-4 align-center-5')
	
	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('Skills')
        :done()
        :tag('th')
            :attr('data-sort-type', 'number')
            :wikitext('XP')
        :done()
        :tag('th')
            :wikitext('Materials')
        :done()
    
    -- Render rows
    for _, recipe in pairs(products) do
    	-- Outputs
    	local output_text = "{{plainlist"
    	for _, out in recipe["outputs"] do
    		if out["amount"] > 1 then
    			output_text = output_text .. string.format("|{{plink|%s}} x %s", out["name"], tostring(out["amount"]))
    		else
    			output_text = output_text .. string.format("|{{plink|%s}}", out["name"])
    		end
    	end
    	
    	output_text = output_text .. "}}"
    	
    	return output_text
    end
    
	-- Return table
	return t
end

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end

return p