Module:BattleTeam

From Cassette Beasts

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