Module:Torneko 1 Dungeon Items table

MDFW - The Mystery Dungeon Tree of Information.
Revision as of 21:47, 10 April 2024 by Adkuate (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Torneko 1 Dungeon Items table/doc

--------------------------------------------------------------------------------
--
--				Module:Torneko 1 Dungeon Items table
--
--------------------------------------------------------------------------------

local p = {}
local mw = require('mw')

function p.main(frame)
	local args = frame.args
	local categoryArg = args["category"]
	local output = {}
	-- Header row
	table.insert(output, '<table class="MDWiki" style="text-align: center; width: 100%;">')
	table.insert(output, '<tr>')
	if categoryArg then
		table.insert(output, '<th colspan="3" style="height: 5rem;">[[File:Torneko 1 - ' .. frame:preprocess('{{#switch:' .. categoryArg .. ' | Herbs = Herb | Food = Bread | Weapons = Sword | Shields = Shield | Rings = Ring | Scrolls = Scroll | Staves = Staff | Projectiles = Arrow | #default=' .. (categoryArg) .. ' }}') .. '.svg|32x32px|alt=' .. (categoryArg) .. '|' .. (categoryArg) .. ']]<br>' .. frame:expandTemplate{title = "Torneko1", args = {(categoryArg or "")}} .. '</th>')
	else
		table.insert(output, '<th colspan="3" style="height: 5rem;">' .. frame:expandTemplate{title = "Research"} .. '</th>')
	end
	table.insert(output, '</tr>')
	table.insert(output, '<tr>')
	if string.lower(categoryArg) == "gold" then
		table.insert(output, '<th style="width: 33%;">Lowest amount</th>')
		table.insert(output, '<th style="width: 33%;">Highest ammount</th>')
	else
		table.insert(output, '<th style="width: 33%;">English</th>')
		table.insert(output, '<th style="width: 33%;">Japanese</th>')
	end
	table.insert(output, '<th style="width: 34%;">Floors</th>')
	table.insert(output, '</tr>')
	-- Data rows
	for i = 1, 100 do
		local itemArg = args["item_" .. i]
		local lowAmountArg = args["low_amount_" .. i]
		local highAmountArg = args["high_amount_" .. i]
		local floorsArg = args["floors_" .. i]
		if not itemArg and not floorsArg and not lowAmountArg and not highAmountArg then
			break -- exit loop when no more rows are found
		end
		local rowData = {}
		table.insert(rowData, '<tr>')
		if string.lower(categoryArg) == "poké" then
			table.insert(rowData, '<td>' .. (lowAmountArg or frame:expandTemplate{title = "Research"}) .. '</td>')
			table.insert(rowData, '<td>' .. (highAmountArg or frame:expandTemplate{title = "Research"}) .. '</td>')
		else
			if itemArg then
				table.insert(rowData, '<td>' .. frame:expandTemplate{title = "Torneko1", args = {itemArg}} .. '</td>')
				table.insert(rowData, '<td>' .. frame:preprocess('{{#invoke:Torneko 1 Item Data Cell|torneko1ItemDataCell|name=' .. itemArg .. '}}') .. '</td>')
			else
				table.insert(rowData, '<td>' .. frame:expandTemplate{title = "Research"} .. '</td>')
				table.insert(rowData, '<td>' .. frame:expandTemplate{title = "Research"} .. '</td>')
			end
		end
		table.insert(rowData, '<td>' .. (floorsArg or frame:expandTemplate{title = "Research"}) .. '</td>')
		table.insert(rowData, '</tr>')
		table.insert(output, table.concat(rowData))
	end
	table.insert(output, '</table>')
	return table.concat(output)
end

return p