From StrategyWiki, the video game walkthrough and strategy guide wiki
Revision as of 03:06, 25 April 2024 by Prod (talk | contribs) (handle shortnames)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Pokemon/Ranger/Documentation

local getArgs = require('Module:Arguments').getArgs
local data = mw.loadJsonData( 'Module:Pokemon Ranger/Browser.json' )

local p = {}
local shortname = {
	["Pokémon Ranger"] = " ",
	["Pokémon Ranger: Shadows of Almia"] = " SoA",
	["Pokémon Ranger: Guardian Signs"] = " GS",
}

local function _capture( args )
    local game = args[1] or 'Pokémon Ranger'
    local monNum = args[2] or '0'

    if monNum == '0' then return '' end

    local guide = "Pokémon Ranger"
    local monData = data[guide][monNum]

    local row = {
        "|-\n",
        '| class="t_ranger_wild_img" | ', '[[File:Pokemon Ranger', shortname[ guide ], ' ', monData.name, '.png|40x40px|', monData.name, ']]', '\n',
        '| class="t_ranger_wild_name" | ', monData.name, '\n',
        '| ', monData.loops, '\n',
        '| ', monData.move, '\n',
        '| ', monData.assist, '\n',
    }

    return table.concat( row )
end

function p.browser( frame )
	local guide = mw.title.getCurrentTitle().rootText 
	mons = data[ guide ]
	local root = mw.html.create( 'table' )
					:addClass( 'wikitable mid-table sortable' )
					:css( 'text-align', 'center' )

	local row = root:tag( 'tr' )
	row:tag( 'th' ):wikitext( "#" )
	row:tag( 'th' ):wikitext( "Image" )
	row:tag( 'th' ):wikitext( "Name" )
	row:tag( 'th' ):wikitext( "Group" )
	row:tag( 'th' ):wikitext( "Field Move" )
	row:tag( 'th' ):wikitext( "Poké Assist" )
	row:tag( 'th' ):wikitext( "Loops" )

	local nums = {}

	for k in pairs(mons) do
	    table.insert(nums, k)
	end
	table.sort(nums)

	for i = 1, #nums do
		local k, t = nums[i], mons[ nums[i] ]
		local row = root:tag( 'tr' )
		row:tag( 'td' ):wikitext( k ):css( 'line-height', '40px' )
		row:tag( 'td' ):wikitext( "[[File:Pokemon Ranger" .. shortname[ guide ] .. ' ' .. t.name .. ".png|" .. t.name .. "]]" )
		row:tag( 'td' ):wikitext( frame:expandTemplate{ title = 'bp', args = { t.name } } ):css( 'text-align', 'left' )
		row:tag( 'td' ):wikitext( t.group )
		if t.move == "None" then
			move = "None"
		elseif t.rating == "1" then
			move = t.move
		else
			move = t.move .. " " .. t.rating
		end
		row:tag( 'td' ):wikitext( move )
		row:tag( 'td' ):wikitext( t.assist )
		row:tag( 'td' ):wikitext( t.loops )
	end
	
	return tostring( root )
end

function p.capture( frame )
    local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Capture row' } )
    
    return _capture( args )
end

return p