Module:Item Products: Difference between revisions

From Guinea Isles Wiki
No edit summary
No edit summary
Line 52: Line 52:
     -- Render rows
     -- Render rows
     for _, recipe in pairs(products) do
     for _, recipe in pairs(products) do
     -- Outputs
     -- Output list text
     local output_text = "{{Plainlist|"
     local output_text = "{{Plainlist|"
     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* {{Plink|%s}} x %s", out["name"], tostring(out["amount"]))
     output_text = output_text .. string.format("\n* %s x {{Plink|%s}}", tostring(out["amount"]), out["name"])
     else
     else
     output_text = output_text .. string.format("\n* {{Plink|%s}}", out["name"])
     output_text = output_text .. string.format("\n* {{Plink|%s}}", out["name"])
     end
     end
     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
   
    -- XP
    
    
     output_text = output_text .. "}}"
     -- Material list text
    local material_text = "{{Plainlist|"
    for _, out in pairs(recipe["mats"]) do
    if out["amount"] > 1 then
    material_text = material_text .. string.format("\n* %s x {{Plink|%s}}", tostring(out["amount"]), out["name"])
    else
    material_text = material_text .. string.format("\n* {{Plink|%s}}", out["name"])
    end
    end
    material_text = material_text .. "}}"
    
    
     return frame:preprocess(output_text)
     -- Create row
local prow = t:tag('tr')
:tag('td')
:wikitext(item.output.image)
:tag('td')
:attr('data-sort-value', item.product)
:wikitext(name_str)
:done()
:tag('td')
:wikitext(member_str)
:node(skills_cell)
:node(experience_cell)
:tag('td')
:attr('data-sort-value', mat_sort_val)
:addClass('plainlist')
:node(mats_ul)
:done()
     end
     end
      
      

Revision as of 19:22, 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(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-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
    	-- 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* %s x {{Plink|%s}}", tostring(out["amount"]), out["name"])
    		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
    	
    	-- XP
    	
    	-- Material list text
    	local material_text = "{{Plainlist|"
    	for _, out in pairs(recipe["mats"]) do
    		if out["amount"] > 1 then
    			material_text = material_text .. string.format("\n* %s x {{Plink|%s}}", tostring(out["amount"]), out["name"])
    		else
    			material_text = material_text .. string.format("\n* {{Plink|%s}}", out["name"])
    		end
    	end
    	material_text = material_text .. "}}"
    	
    	-- Create row
		local prow = t:tag('tr')
			:tag('td')
				:wikitext(item.output.image)
			:tag('td')
				:attr('data-sort-value', item.product)
				:wikitext(name_str)
			:done()
			:tag('td')
				:wikitext(member_str)
			:node(skills_cell)
			:node(experience_cell)
			:tag('td')
				:attr('data-sort-value', mat_sort_val)
				:addClass('plainlist')
				:node(mats_ul)
			:done()
    end
    
	-- Return table
	return t
end

return p