Module:Adventure Squad Dungeon Pokémon table

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

Documentation for this module may be created at Module:Adventure Squad Dungeon Pokémon table/doc

--------------------------------------------------------------------------------
--
--				Module:Adventure Squad Dungeon Pokémon table
--
--------------------------------------------------------------------------------

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

function p.main(frame)
	local data = require("Module:Adventure Squad Pokémon Data Cell")
	local metatable = {__index = function () return "" end}
	setmetatable(data, metatable)
	local args = frame.args

	local output = mw.html.create()
	local header = mw.html.create()
	-- Header row
	header
		:tag('tr'):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext("Model"):done()
			:tag('th'):attr("colspan", "2"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Pokémon"}}):done()
			:tag('th'):attr("colspan", "2"):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Type"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext("Floors"):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Team Size"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Exclusive"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Recruiting", "Recruit Chance"}}):done()
		:tag('tr'):done()
			:tag('th'):cssText("width: 15%"):wikitext("English"):done()
			:tag('th'):cssText("width: 15%"):wikitext("Japanese"):done()

	-- Data rows
	local rows = mw.html.create()
	local i = 1

	while true do
		local row = mw.html.create()
		local monsterArg = args["pokémon_" .. i]
		local floorsArg = args["floors_" .. i]
		local recruitableArg = args["recruitable_" .. i]

		if not monsterArg and not floorsArg and not recruitableArg then
			break -- exit loop when no more rows are found
		end

		local typeOne = data[monsterArg]["type1"] or ""
		local typeTwo = data[monsterArg]["type2"] or ""
		local exclusive = data[monsterArg]["exclusive"] or ""
		local verColor = ""

		if string.lower(exclusive) == "No" then
			verColor = 'background-color: red'
		elseif string.lower(exclusive) == "yes" then
			verColor = 'background-color: cornflowerblue'
		end
		
		local teamSize = data[monsterArg]["teamSize"] or ""
		
		if teamSize == 1 then
			teamSize = "★"
		elseif teamSize == 2 then
			teamSize = "★★"
		elseif teamSize == 3 then
			teamSize = "★★★"
		elseif teamSize == 4 then
			teamSize = "★★★★"
		else
			teamSize = "0"
		end

		row
			:tag('tr'):done()
				:tag('th'):wikitext(frame:expandTemplate{title = "AdventureSquadModel", args = {(monsterArg or ""), size = "64x64px"}}):done()
				:tag('td'):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {(monsterArg or "")}}):done()
				:tag('td'):wikitext(data[monsterArg]["ja"]):done()
	
		if typeTwo == nil or typeTwo == '' then
			row
				:tag('th'):attr("colspan", "2"):wikitext(frame:expandTemplate{title = "AdventureSquadType", args = {typeOne}}):done()
		else
			row
				:tag('th'):wikitext(frame:expandTemplate{title = "AdventureSquadType", args = {typeOne}}):done()
				:tag('th'):wikitext(frame:expandTemplate{title = "AdventureSquadType", args = {typeTwo}}):done()
		end

		row
			:tag('td'):wikitext(floorsArg or frame:expandTemplate{title = "Research"}):done()
			:tag('td'):cssText(verColor):wikitext(teamSize):done()
			:tag('td'):cssText(verColor):wikitext(exclusive):done()

		if recruitableArg == nil or recruitableArg == '' or string.lower(recruitableArg) == "false" or string.lower(recruitableArg) == "no" then
			row
				:tag('td'):attr("colspan", "2"):wikitext("Unrecruitable"):done()
		else
			row
				:tag('td'):wikitext(data[monsterArg]["recruit"]):done()
		end

		rows
			:node(row)
			:allDone()

		i = i + 1
	end

	output
		:tag('table'):addClass("MDWiki"):cssText("text-align: center; margin: auto; width: 50%;")
			:node(header)
			:node(rows)
	return tostring(output)

end

return p