Module:BattleTeam: Difference between revisions

From Cassette Beasts
Solari (talk | contribs)
No edit summary
Solari (talk | contribs)
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
function p.get_monster(frame)
local argument_list = mw.text.split(frame.args[1], ";", true)
local result = {}
if (#argument_list ~= 1) and (#argument_list ~= 3) then
return "Arguments found: " .. #argument_list
end
local override = #argument_list == 3
local row = mw.html.create('tr')
local mon_type = frame.args[2]
if not override then
if mon_type == nil or mon_type == "" then
mon_type = frame:callParserFunction('#invoke', 'Database', 'get_species', frame.args[1], "elemental_type")
end
row:tag('td')
:attr('align', 'center')
:cssText('width: 108px; padding: 6px;')
:wikitext("[[File:" .. frame:callParserFunction('#invoke', 'Database', 'get_species', frame.args[1], "name") .. ".png|80x42px]]")
:done()
:tag('td')
:attr('align', 'center')
:cssText('width: 108px; padding: 6px;')
:wikitext(frame:callParserFunction('#invoke', 'Database', 'get_link', 'species', frame.args[1])
.. "<br/>"
.. frame:expandTemplate({title = 'TypeButton', args = { mon_type }}))
:allDone()
else
row:tag('td')
:attr('align', 'center')
:cssText('width: 108px; padding: 6px;')
:wikitext("[[File:" .. argument_list[3] .. ".png|80x42px]]")
:done()
:tag('td')
:attr('align', 'center')
:cssText('width: 108px; padding: 6px;')
:wikitext(argument_list[2]
.. "<br/>"
.. frame:expandTemplate({title = 'TypeButton', args = { argument_list[1] }}))
:allDone()
end
table.insert(result, tostring(row))
return table.concat(result)
end


function p.get_moves(frame)
function p.get_moves(frame)
Line 6: Line 54:
for _, move in ipairs(move_list) do
for _, move in ipairs(move_list) do
local type_specified = mw.text.split(move, ";", true)
local row = mw.html.create('tr')
local row = mw.html.create('tr')
:attr('align', 'center')
:attr('align', 'left')
local cell = row:tag('td')
local cell = row:tag('td')
:addClass(frame:callParserFunction('#invoke', 'Database', 'get_move', move, 'elemental_type') .. "_type")
:cssText('display: inline-block; line-height: 1.1em; background-repeat: no-repeat; background-position: calc(0% - 0.21em) center; background-size: 1.66em; padding-left: 1.75em; background-color: transparent;')
:cssText('display: inline-block; line-height: 1.25em; font-size: 1em; background-repeat: no-repeat; background-position: calc(0% - 0.2em) center; background-size: 1.65em; padding-left: 1.75em; background-color: transparent;')
:wikitext(frame:callParserFunction('#invoke', 'Database', 'get_link', 'move', move))
if #type_specified <= 1 then
:allDone()
cell:addClass(frame:callParserFunction('#invoke', 'Database', 'get_move', move, 'elemental_type') .. "_type")
:wikitext(frame:callParserFunction('#invoke', 'Database', 'get_link', 'move', move))
else
cell:addClass(type_specified[1] .. "_type")
:wikitext(type_specified[2])
end
table.insert(result, tostring(cell))
cell:allDone()
table.insert(result, tostring(row))
end
end

Latest revision as of 00:51, 14 September 2026

Documentation for this module may be created at Module:BattleTeam/doc

local p = {}

function p.get_monster(frame)
	local argument_list = mw.text.split(frame.args[1], ";", true)
	local result = {}
	
	if (#argument_list ~= 1) and (#argument_list ~= 3) then
		return "Arguments found: " .. #argument_list
	end
	local override = #argument_list == 3
	
	local row = mw.html.create('tr')
	local mon_type = frame.args[2]
	
	if not override then
		if mon_type == nil or mon_type == "" then
			mon_type = frame:callParserFunction('#invoke', 'Database', 'get_species', frame.args[1], "elemental_type")
		end
		
		row:tag('td')
			:attr('align', 'center')
			:cssText('width: 108px; padding: 6px;')
			:wikitext("[[File:" .. frame:callParserFunction('#invoke', 'Database', 'get_species', frame.args[1], "name") .. ".png|80x42px]]")
			:done()
			:tag('td')
			:attr('align', 'center')
			:cssText('width: 108px; padding: 6px;')
			:wikitext(frame:callParserFunction('#invoke', 'Database', 'get_link', 'species', frame.args[1])
				.. "<br/>"
				.. frame:expandTemplate({title = 'TypeButton', args = { mon_type }}))
			:allDone()
	else
		row:tag('td')
			:attr('align', 'center')
			:cssText('width: 108px; padding: 6px;')
			:wikitext("[[File:" .. argument_list[3] .. ".png|80x42px]]")
			:done()
			:tag('td')
			:attr('align', 'center')
			:cssText('width: 108px; padding: 6px;')
			:wikitext(argument_list[2]
				.. "<br/>"
				.. frame:expandTemplate({title = 'TypeButton', args = { argument_list[1] }}))
			:allDone()
	end
	
	table.insert(result, tostring(row))
	return table.concat(result)
end

function p.get_moves(frame)
	local move_list = mw.text.split(frame.args[1], ",", true)
	local result = {}
	
	for _, move in ipairs(move_list) do
		local type_specified = mw.text.split(move, ";", true)
		
		local row = mw.html.create('tr')
			:attr('align', 'left')
		local cell = row:tag('td')
			:cssText('display: inline-block; line-height: 1.1em; background-repeat: no-repeat; background-position: calc(0% - 0.21em) center; background-size: 1.66em; padding-left: 1.75em; background-color: transparent;')
			
		if #type_specified <= 1 then
			cell:addClass(frame:callParserFunction('#invoke', 'Database', 'get_move', move, 'elemental_type') .. "_type")
				:wikitext(frame:callParserFunction('#invoke', 'Database', 'get_link', 'move', move))
		else 
			cell:addClass(type_specified[1] .. "_type")
				:wikitext(type_specified[2])
		end
		
		cell:allDone()
		table.insert(result, tostring(row))
	end
	
	return table.concat(result)
end

return p