Module:Adventure Squad Pokémon Dungeon table

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

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

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

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

function p.main(frame)
	local args = frame.args

	local output = mw.html.create()
	local header = mw.html.create()

	local data = require("Module:Adventure Squad Dungeon Data Cell")
	local metatable = {__index = function () return "" end}
	setmetatable(data, metatable)

	-- Header row
	header
		:tag('tr'):done()
			:tag('th'):attr("colspan", "2"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Dungeon"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Floor", "Floors"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Level"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Spawn Rate"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Recruiting", "Recruitable"}}):done()
			:tag('th'):attr("rowspan", "2"):cssText("width: 10%"):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {"Version"}}):done()
		:tag('tr'):done()
			:tag('th'):cssText("width: 25%"):wikitext("English"):done()
			:tag('th'):cssText("width: 25%"):wikitext("Japanese"):done()

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

	while true do
		local row = mw.html.create()
		local dungeonArg = args["dungeon_" .. i]
		local floorsArg = args["floors_" .. i]
		local levelsArg = args["levels_" .. i]
		local spawnrateArg = args["spawnrate_" .. i]
		local recruitableArg = args["recruitable_" .. i]
		local versionArg = args["version_" .. i]

		if not dungeonArg and not floorsArg and not levelsArg and not spawnrateArg and not recruitableArg and not versionArg then
			break -- exit loop when no more rows are found
		end

		row
			:tag('tr'):done()
				:tag('td'):wikitext(frame:expandTemplate{title = "AdventureSquad", args = {(dungeonArg or "")}}):done()
				:tag('td'):wikitext(data[dungeonArg]["ja"]):done()
				:tag('td'):wikitext(floorsArg or frame:expandTemplate{title = "Research"}):done()
				:tag('td'):wikitext(levelsArg or frame:expandTemplate{title = "Research"}):done()
				:tag('td'):wikitext(spawnrateArg or frame:expandTemplate{title = "Research"}):done()
				
		if string.lower(recruitableArg) == "yes" or string.lower(recruitableArg) == "true" or recruitableArg == "✓" then
			row
				:tag('td'):wikitext("✓"):cssText("background:lightblue; color:midnightblue;"):done()
		else
			row
				:tag('td'):wikitext("✗"):cssText("background:#F2CECE; color:maroon;"):done()
		end
		
		row
			:tag("td"):wikitext(data[dungeonArg]["version"]):cssText(frame:preprocess('{{#switch: {{lc: ' .. (data[dungeonArg]["version"] or "") .. '}} | water=background-color:#0000FF!important; color: white; | fire=background-color:#FF0000!important; | light=background-color:#FFFF00!important; }}'))

		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