Module:Rescue Team Pokémon Locations table

MDFW - The Mystery Dungeon Tree of Information.
Revision as of 09:23, 26 January 2025 by Adkuate (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Rescue Team Pokémon Locations table/doc

--------------------------------------------------------------------------------
--
--					Module:Rescue Team Pokémon Locations 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()
	-- Header row
	header
		:tag('tr')
			:tag('th'):cssText("width: 20%"):wikitext(frame:expandTemplate{title = "RescueTeam", args = {"Location"}}):done()
			:tag('th'):cssText("width: 20%"):wikitext("Floors"):done()
			:tag('th'):cssText("width: 20%"):wikitext(frame:expandTemplate{title = "RescueTeam", args = {"Level"}}):done()
			:tag('th'):cssText("width: 20%"):wikitext("Spawn Rate"):done()
			:tag('th'):cssText("width: 20%"):wikitext(frame:expandTemplate{title = "RescueTeam", args = {"Recruiting", "Recruitable"}}):done()

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

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

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

		row
			:tag('tr'):done()
				:tag('td'):wikitext(frame:expandTemplate{title = "RescueTeam", args = {(locationArg or "")}}):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 recruitableArg == nil or recruitableArg == '' or string.lower(recruitableArg) == "false" or string.lower(recruitableArg) == "no" then
			row
				:tag('td'):cssText("background: #F2CECE; color: maroon"):wikitext("✗"):done()
		else
			row
				:tag('td'):cssText("background: #CEF2CE; color: darkgreen"):wikitext("✓"):done()
		end

		rows
			:node(row)
			:allDone()

		i = i + 1
	end

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

end

return p