Module:Sandbox: Difference between revisions

MDFW - The Mystery Dungeon Tree of Information.
Jump to navigation Jump to search
No edit summary
(I'm stupid apparently and there's an extra td for some reason but It should be better now)
Line 9: Line 9:


function p.main(frame)
function p.main(frame)
local data = mw.loadData("Module:Sandbox/test")
local data = require("Module:Sandbox/test")
local metatable = {__index = function () return "" end}
setmetatable(data, metatable)
local args = frame.args
local args = frame.args
local output = {}
local output = mw.html.create()
local header = mw.html.create()
-- Header row
-- Header row
table.insert(output, '<table class="templateTheme" style="text-align: center; margin: auto; width: 50%;">')
header
table.insert(output, '<tr>')
:tag('tr')
table.insert(output, '<th class="templatePrimary" rowspan="2" style="width: 10%;">Sprite</th>')
:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("Sprite"):done()
table.insert(output, '<th class="templatePrimary" colspan="2">' .. frame:expandTemplate{title = "RescueTeamDX", args = {"Pokémon"}} .. '</th>')
:tag('th'):addClass("templatePrimary"):attr("colspan", "2" ):cssText("width: 10%"):wikitext("{{RescueTeamDX|Pokémon}}"):done()
table.insert(output, '<th class="templatePrimary" colspan="2" rowspan="2" style="width: 20%;">' .. frame:expandTemplate{title = "RescueTeamDX", args = {"Types"}} .. '</th>')
:tag('th'):addClass("templatePrimary"):attr("colspan", "2" ):attr("rowspan", "2" ):cssText("width: 20%"):wikitext("{{RescueTeamDX|Types}}"):done()
table.insert(output, '<th class="templatePrimary" rowspan="2" style="width: 10%;">' .. frame:expandTemplate{title = "RescueTeamDX", args = {"Level"}} .. '</th>')
:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("{{RescueTeamDX|Level}}"):done()
table.insert(output, '<th class="templatePrimary" rowspan="2" style="width: 10%;">Floors</th>')
:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("Floors"):done()
table.insert(output, '</tr>')
:tag('td'):wikitext(recruit)
table.insert(output, '<tr>')
:tag('tr')
table.insert(output, '<th class="templatePrimary" style="width: 25%;">English</th>')
:tag('th'):addClass("templatePrimary"):cssText("width: 25%"):wikitext("English"):done()
table.insert(output, '<th class="templatePrimary" style="width: 25%;">Japanese</th>')
:tag('th'):addClass("templatePrimary"):cssText("width: 25%"):wikitext("Japanese"):done()
table.insert(output, '</tr>')
 
-- Data rows
-- Data rows
local rows = mw.html.create()
for i = 1, 150 do
for i = 1, 150 do
local monsterArg = args["pokémon_" .. i]
local row = mw.html.create()
local monsterArg = args["pokemon_" .. i]
local floorsArg = args["floors_" .. i]
local floorsArg = args["floors_" .. i]
local levelArg = args["level_" .. i]
local levelArg = args["level_" .. i]
Line 33: Line 39:
break -- exit loop when no more rows are found
break -- exit loop when no more rows are found
end
end
local typeOne = data[monsterArg or ""][type1]
local typeOne = data[monsterArg]["type1"] or ""
local typeTwo = data[monsterArg or ""][type2]
local typeTwo = data[monsterArg]["type2"] or ""
local rowData = {}
row
table.insert(rowData, '<tr class="monstersTableRow">')
:tag("tr"):addClass("monstersTableRow"):done()
table.insert(rowData, '<th class="templatePrimary">' .. frame:expandTemplate{title = "RescueTeamDXSprite", args = {(monsterArg or ""), size = "50x50px"}} .. '</th>')
:tag("th"):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXSprite", args = {(monsterArg or ""), size = "50x50px"}}):done()
table.insert(rowData, '<td class="templateSecondary">' .. frame:expandTemplate{title = "RescueTeamDX", args = {(monsterArg or "")}} .. '</td>')
:tag("td"):addClass("templateSecondary"):wikitext(frame:expandTemplate{title = "RescueTeamDX", args = {(monsterArg or "")}})
table.insert(rowData, '<td class="templateSecondary">' .. data[monsterArg or ""][ja] .. '</td>')
:tag("td"):addClass("templateSecondary"):wikitext(data[monsterArg]["ja"])
if typeTwo == nil or typeTwo == '' then
if typeTwo == nil or typeTwo == '' then
table.insert(rowData, '<td class="templatePrimary" colspan="2">' .. frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}} .. '</td>')
row
:tag('td'):addClass("templatePrimary"):attr("colspan", "2" ):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}}):done()
else
else
table.insert(rowData, '<td class="templatePrimary">' .. frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}} .. '</td>')
row
table.insert(rowData, '<td class="templatePrimary">' .. frame:expandTemplate{title = "RescueTeamDXType", args = {typeTwo}} .. '</td>')
:tag('td'):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}}):done()
:tag('td'):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeTwo}}):done()
 
end
end
table.insert(rowData, '<td class="templateSecondary">' .. (levelArg or "") .. '</td>')
row
table.insert(rowData, '<td class="templateSecondary">' .. (floorsArg or "") .. '</td>')
:tag("td"):addClass("templateSecondary"):wikitext(levelArg or ""):done()
table.insert(rowData, '</tr>')
:tag("td"):addClass("templateSecondary"):wikitext(floorsArg or ""):done()
table.insert(output, table.concat(rowData))
rows
:node(row)
:allDone()
end
end
table.insert(output, '</table>')
return table.concat(output)
output
:tag('table'):addClass("templateTheme"):cssText("text-align: center; margin: auto; width: 50%")
:node(header)
:node(rows)
return tostring(output)
 
end
end


return p
return p

Revision as of 09:31, 14 March 2024



--------------------------------------------------------------------------------
--
--				Module:Rescue Team DX Dungeon Fainted Pokémon table
--
--------------------------------------------------------------------------------

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

function p.main(frame)
	local data = require("Module:Sandbox/test")
	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')
			:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("Sprite"):done()
			:tag('th'):addClass("templatePrimary"):attr("colspan", "2" ):cssText("width: 10%"):wikitext("{{RescueTeamDX|Pokémon}}"):done()
			:tag('th'):addClass("templatePrimary"):attr("colspan", "2" ):attr("rowspan", "2" ):cssText("width: 20%"):wikitext("{{RescueTeamDX|Types}}"):done()
			:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("{{RescueTeamDX|Level}}"):done()
			:tag('th'):addClass("templatePrimary"):attr("rowspan", "2" ):cssText("width: 10%"):wikitext("Floors"):done()
			:tag('td'):wikitext(recruit)
		:tag('tr')
			:tag('th'):addClass("templatePrimary"):cssText("width: 25%"):wikitext("English"):done()
			:tag('th'):addClass("templatePrimary"):cssText("width: 25%"):wikitext("Japanese"):done()

	-- Data rows
	local rows = mw.html.create()
	for i = 1, 150 do
		local row = mw.html.create()
		local monsterArg = args["pokemon_" .. i]
		local floorsArg = args["floors_" .. i]
		local levelArg = args["level_" .. i]
		if not monsterArg and not floorsArg and not levelArg then
			break -- exit loop when no more rows are found
		end
		local typeOne = data[monsterArg]["type1"] or ""
		local typeTwo = data[monsterArg]["type2"] or ""
		row
			:tag("tr"):addClass("monstersTableRow"):done()
			:tag("th"):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXSprite", args = {(monsterArg or ""), size = "50x50px"}}):done()
			:tag("td"):addClass("templateSecondary"):wikitext(frame:expandTemplate{title = "RescueTeamDX", args = {(monsterArg or "")}})
			:tag("td"):addClass("templateSecondary"):wikitext(data[monsterArg]["ja"])
			
		if typeTwo == nil or typeTwo == '' then
			row
				:tag('td'):addClass("templatePrimary"):attr("colspan", "2" ):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}}):done()
		else
			row
				:tag('td'):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeOne}}):done()
				:tag('td'):addClass("templatePrimary"):wikitext(frame:expandTemplate{title = "RescueTeamDXType", args = {typeTwo}}):done()

		end
			row
				:tag("td"):addClass("templateSecondary"):wikitext(levelArg or ""):done()
				:tag("td"):addClass("templateSecondary"):wikitext(floorsArg or ""):done()
		rows
			:node(row)
			:allDone()
			
	end
		
		output
			:tag('table'):addClass("templateTheme"):cssText("text-align: center; margin: auto; width: 50%")
				:node(header)
				:node(rows)
		return  tostring(output)

end

return p