Jump to navigation
Jump to search
(Added 2nd capture loops) Tags: Mobile edit Mobile web edit |
(update arena function) |
||
(19 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require( 'Module:Arguments' ).getArgs | |||
local p = {} | local p = {} | ||
local shortname = { | local shortname = { | ||
Line 5: | Line 7: | ||
["Pokémon Ranger: Guardian Signs"] = "Pokemon Ranger GS", | ["Pokémon Ranger: Guardian Signs"] = "Pokemon Ranger GS", | ||
} | } | ||
local function _move( guide, move, rating ) | |||
out = "" | |||
if guide == "Pokémon Ranger" then | |||
if move == "None" then | |||
return "None" | |||
else | |||
for j = 1, rating do | |||
out = out .. "[[File:" .. shortname[ guide ] .. ' ' .. move .. ' ' .. "Icon.png|" .. move .. "]] " | |||
end | |||
end | |||
else | |||
if rating == "-" then | |||
out = "[[File:Pokemon Ranger SoA " .. move .. " Icon.png|" .. move .. "]]" | |||
else | |||
out = "[[File:Pokemon Ranger SoA " .. move .. ' ' .. rating .. " Icon.png|" .. move .. ' ' .. rating .. "]]" | |||
end | |||
end | |||
return out | |||
end | |||
local function _capture( args ) | local function _capture( args ) | ||
local | local guide = mw.title.getCurrentTitle().rootText | ||
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' ) | local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' ) | ||
local root = mw.html.create( 'table' ) | local root = mw.html.create( 'table' ) | ||
Line 18: | Line 40: | ||
row:tag( 'th' ):wikitext( "Field Move" ) | row:tag( 'th' ):wikitext( "Field Move" ) | ||
row:tag( 'th' ):wikitext( "Poké Assist" ) | row:tag( 'th' ):wikitext( "Poké Assist" ) | ||
row:tag( 'th' ):wikitext( "Loops" ) | if guide == "Pokémon Ranger" then | ||
row:tag( 'th' ):wikitext( "Loops" ) | |||
end | |||
for i, v in ipairs( args ) do | for i, v in ipairs( args ) do | ||
local monData = data[ "browser" ][ v ] | local monData = {} | ||
if data["browser"][v] then | |||
monData = data["browser"][v] | |||
else | |||
monData = data["browser-past"][v] | |||
end | |||
local row = root:tag( 'tr' ) | local row = root:tag( 'tr' ) | ||
if monData.filename then | |||
if monData. | prefix = monData.filename | ||
else | else | ||
prefix = shortname[guide] | |||
end | end | ||
row:tag( 'td' ):wikitext( "[[File:" .. prefix .. ' ' .. monData.name .. ".png|" .. monData.name .. "]]" .. " " .. '[[' .. guide .. '/Browser#'.. monData.name .. '|' .. monData.name .. ']]' ) | |||
move = _move( guide, monData.move, monData.rating ) | |||
row:tag( 'td' ):wikitext( move ) | row:tag( 'td' ):wikitext( move ) | ||
row:tag( 'td' ):wikitext( monData.assist ) | row:tag( 'td' ):wikitext( monData.assist ) | ||
if | if guide == "Pokémon Ranger" then | ||
if monData.loops2page == mw.title.getCurrentTitle().text then | |||
loops = monData.loops2 | |||
else | |||
loops = monData.loops | |||
end | |||
row:tag( 'td' ):wikitext ( loops ) | |||
end | |||
end | end | ||
return tostring( root ) | return tostring( root ) | ||
end | end | ||
local function _challenge( args ) | local function _challenge( args ) | ||
local guide = mw.title.getCurrentTitle().rootText | local guide = mw.title.getCurrentTitle().rootText | ||
Line 74: | Line 99: | ||
end | end | ||
function | local function _browser( guide, section ) | ||
local | local frame = mw.getCurrentFrame() | ||
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' ) | local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' ) | ||
local root = mw.html.create( 'table' ) | local root = mw.html.create( 'table' ) | ||
Line 88: | Line 113: | ||
row:tag( 'th' ):wikitext( "Field Move" ) | row:tag( 'th' ):wikitext( "Field Move" ) | ||
row:tag( 'th' ):wikitext( "Poké Assist" ) | row:tag( 'th' ):wikitext( "Poké Assist" ) | ||
row:tag( 'th' ):wikitext( "Loops" ) | if guide == "Pokémon Ranger" then | ||
row:tag( 'th' ):wikitext( "Loops" ) | |||
end | |||
local nums = {} | local nums = {} | ||
for k in pairs( data[ | for k in pairs( data[ section ] ) do | ||
table.insert( nums, k ) | table.insert( nums, k ) | ||
end | end | ||
Line 98: | Line 125: | ||
for i = 1, #nums do | for i = 1, #nums do | ||
local k, v = nums[ i ], data[ | local k, v = nums[ i ], data[ section ][ nums[ i ] ] | ||
local row = root:tag( 'tr' ) | local row = root:tag( 'tr' ) | ||
row:tag( 'td' ):wikitext( k ):css( 'line-height', ' | row:tag( 'td' ):wikitext( k ):css( 'line-height', '20px' ) | ||
row:tag( 'td' ):wikitext( "[[File:" .. | if v.filename then | ||
prefix = v.filename | |||
else | |||
prefix = shortname[guide] | |||
end | |||
row:tag( 'td' ):wikitext( "[[File:" .. prefix .. ' ' .. v.name .. ".png|" .. v.name .. "]]" ) | |||
row:tag( 'td' ) | row:tag( 'td' ) | ||
:wikitext( frame:expandTemplate{ title = 'a', args = { v.name, frame:expandTemplate{ title = 'bp', args = { v.name } } } } ) | :wikitext( frame:expandTemplate{ title = 'a', args = { v.name, frame:expandTemplate{ title = 'bp', args = { v.name } } } } ) | ||
:css( 'text-align', 'left' ) | :css( 'text-align', 'left' ) | ||
row:tag( 'td' ):wikitext( v.group ) | row:tag( 'td' ):wikitext( v.group ) | ||
move = _move( guide, v.move, v.rating ) | |||
row:tag( 'td' ):wikitext( move ) | row:tag( 'td' ):wikitext( move ) | ||
row:tag( 'td' ):wikitext( v.assist ) | row:tag( 'td' ):wikitext( v.assist ) | ||
row:tag( 'td' ):wikitext( v.loops ) | if guide == "Pokémon Ranger" then | ||
row:tag( 'td' ):wikitext( v.loops ) | |||
end | |||
end | end | ||
return tostring( root ) | return tostring( root ) | ||
end | |||
function p.arena() | |||
local guide = mw.title.getCurrentTitle().rootText | |||
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' ) | |||
local root = mw.html.create( 'table' ) | |||
:addClass( 'wikitable mid-table' ) | |||
:css( 'text-align', 'center' ) | |||
local row = root:tag( 'tr' ) | |||
row:tag( 'th' ):wikitext( "Pokémon" ) | |||
row:tag( 'th' ):wikitext( "Requirements" ) | |||
row:tag( 'th' ):wikitext( "Points" ) | |||
row:tag( 'th' ):wikitext( "Loops" ) | |||
for level, k in ipairs(data[ "arena" ]) do | |||
root:tag( 'tr' ):tag( 'td' ) | |||
:attr( 'colspan', 4 ) | |||
:css( 'text-align', 'center' ) | |||
:css( { ['background-color'] = '#317103', color = 'white' } ) | |||
:wikitext( "Level " .. level ) | |||
for j, v in ipairs( data[ "arena" ][ level ] ) do | |||
local monData = data[ "browser" ][ v[ "#" ] ] | |||
local row = root:tag( 'tr' ) | |||
row:tag( 'td' ):wikitext( "[[File:" .. shortname[ guide ] .. ' ' .. monData.name .. ".png|" .. monData.name .. "]]" .. " " .. '[[' .. guide .. '/Browser#'.. monData.name .. '|' .. monData.name .. ']]' ) | |||
if v.requirement then | |||
row:tag( 'td' ):wikitext( v.requirement ) | |||
else | |||
row:tag( 'td' ):wikitext( "None" ) | |||
end | |||
row:tag( 'td' ):wikitext( v.points ) | |||
row:tag( 'td' ):wikitext( monData.loops ) | |||
end | |||
end | |||
return tostring( root ) | |||
end | |||
function p.browser( frame ) | |||
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Browser' } ) | |||
local guide = mw.title.getCurrentTitle().rootText | |||
local section = args[1] or "browser" | |||
return _browser( guide, section ) | |||
end | end | ||
function p.capture( frame ) | function p.capture( frame ) | ||
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Capture' } ) | local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Capture' } ) | ||
Line 129: | Line 202: | ||
function p.challenge( frame ) | function p.challenge( frame ) | ||
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Challenge' } ) | local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Challenge' } ) | ||
Latest revision as of 13:53, 16 May 2024
Documentation for this module may be created at Module:Pokemon/Ranger/Documentation
local getArgs = require( 'Module:Arguments' ).getArgs
local p = {}
local shortname = {
["Pokémon Ranger"] = "Pokemon Ranger",
["Pokémon Ranger: Shadows of Almia"] = "Pokemon Ranger SoA",
["Pokémon Ranger: Guardian Signs"] = "Pokemon Ranger GS",
}
local function _move( guide, move, rating )
out = ""
if guide == "Pokémon Ranger" then
if move == "None" then
return "None"
else
for j = 1, rating do
out = out .. "[[File:" .. shortname[ guide ] .. ' ' .. move .. ' ' .. "Icon.png|" .. move .. "]] "
end
end
else
if rating == "-" then
out = "[[File:Pokemon Ranger SoA " .. move .. " Icon.png|" .. move .. "]]"
else
out = "[[File:Pokemon Ranger SoA " .. move .. ' ' .. rating .. " Icon.png|" .. move .. ' ' .. rating .. "]]"
end
end
return out
end
local function _capture( args )
local guide = mw.title.getCurrentTitle().rootText
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' )
local root = mw.html.create( 'table' )
:addClass( 'wikitable mid-table' )
:css( 'text-align', 'center' )
local row = root:tag( 'tr' )
row:tag( 'th' ):wikitext( "Pokémon" )
row:tag( 'th' ):wikitext( "Field Move" )
row:tag( 'th' ):wikitext( "Poké Assist" )
if guide == "Pokémon Ranger" then
row:tag( 'th' ):wikitext( "Loops" )
end
for i, v in ipairs( args ) do
local monData = {}
if data["browser"][v] then
monData = data["browser"][v]
else
monData = data["browser-past"][v]
end
local row = root:tag( 'tr' )
if monData.filename then
prefix = monData.filename
else
prefix = shortname[guide]
end
row:tag( 'td' ):wikitext( "[[File:" .. prefix .. ' ' .. monData.name .. ".png|" .. monData.name .. "]]" .. " " .. '[[' .. guide .. '/Browser#'.. monData.name .. '|' .. monData.name .. ']]' )
move = _move( guide, monData.move, monData.rating )
row:tag( 'td' ):wikitext( move )
row:tag( 'td' ):wikitext( monData.assist )
if guide == "Pokémon Ranger" then
if monData.loops2page == mw.title.getCurrentTitle().text then
loops = monData.loops2
else
loops = monData.loops
end
row:tag( 'td' ):wikitext ( loops )
end
end
return tostring( root )
end
local function _challenge( args )
local guide = mw.title.getCurrentTitle().rootText
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' )
local root = mw.html.create( 'table' )
:addClass( 'wikitable mid-table' )
:css( 'text-align', 'center' )
local row = root:tag( 'tr' )
row:tag( 'th' ):wikitext( "Pokémon" )
row:tag( 'th' ):wikitext( "Requirements" )
row:tag( 'th' ):wikitext( "Points" )
row:tag( 'th' ):wikitext( "Loops" )
for i, v in ipairs( args ) do
local monData = data[ "browser" ][ v ]
local challengeData = data[ "challenges" ][ v ]
local row = root:tag( 'tr' )
row:tag( 'td' ):wikitext( "[[File:" .. shortname[ guide ] .. ' ' .. monData.name .. ".png|" .. monData.name .. "]]" .. " " .. '[[' .. guide .. '/Browser#'.. monData.name .. '|' .. monData.name .. ']]' )
row:tag( 'td' ):wikitext( challengeData.requirement )
row:tag( 'td' ):wikitext( challengeData.points )
row:tag( 'td' ):wikitext( monData.loops )
end
return tostring( root )
end
local function _browser( guide, section )
local frame = mw.getCurrentFrame()
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' )
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" )
if guide == "Pokémon Ranger" then
row:tag( 'th' ):wikitext( "Loops" )
end
local nums = {}
for k in pairs( data[ section ] ) do
table.insert( nums, k )
end
table.sort( nums )
for i = 1, #nums do
local k, v = nums[ i ], data[ section ][ nums[ i ] ]
local row = root:tag( 'tr' )
row:tag( 'td' ):wikitext( k ):css( 'line-height', '20px' )
if v.filename then
prefix = v.filename
else
prefix = shortname[guide]
end
row:tag( 'td' ):wikitext( "[[File:" .. prefix .. ' ' .. v.name .. ".png|" .. v.name .. "]]" )
row:tag( 'td' )
:wikitext( frame:expandTemplate{ title = 'a', args = { v.name, frame:expandTemplate{ title = 'bp', args = { v.name } } } } )
:css( 'text-align', 'left' )
row:tag( 'td' ):wikitext( v.group )
move = _move( guide, v.move, v.rating )
row:tag( 'td' ):wikitext( move )
row:tag( 'td' ):wikitext( v.assist )
if guide == "Pokémon Ranger" then
row:tag( 'td' ):wikitext( v.loops )
end
end
return tostring( root )
end
function p.arena()
local guide = mw.title.getCurrentTitle().rootText
local data = mw.loadJsonData( 'Module:Pokemon/' .. string.sub( shortname[ guide ], 9 ) .. '.json' )
local root = mw.html.create( 'table' )
:addClass( 'wikitable mid-table' )
:css( 'text-align', 'center' )
local row = root:tag( 'tr' )
row:tag( 'th' ):wikitext( "Pokémon" )
row:tag( 'th' ):wikitext( "Requirements" )
row:tag( 'th' ):wikitext( "Points" )
row:tag( 'th' ):wikitext( "Loops" )
for level, k in ipairs(data[ "arena" ]) do
root:tag( 'tr' ):tag( 'td' )
:attr( 'colspan', 4 )
:css( 'text-align', 'center' )
:css( { ['background-color'] = '#317103', color = 'white' } )
:wikitext( "Level " .. level )
for j, v in ipairs( data[ "arena" ][ level ] ) do
local monData = data[ "browser" ][ v[ "#" ] ]
local row = root:tag( 'tr' )
row:tag( 'td' ):wikitext( "[[File:" .. shortname[ guide ] .. ' ' .. monData.name .. ".png|" .. monData.name .. "]]" .. " " .. '[[' .. guide .. '/Browser#'.. monData.name .. '|' .. monData.name .. ']]' )
if v.requirement then
row:tag( 'td' ):wikitext( v.requirement )
else
row:tag( 'td' ):wikitext( "None" )
end
row:tag( 'td' ):wikitext( v.points )
row:tag( 'td' ):wikitext( monData.loops )
end
end
return tostring( root )
end
function p.browser( frame )
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Browser' } )
local guide = mw.title.getCurrentTitle().rootText
local section = args[1] or "browser"
return _browser( guide, section )
end
function p.capture( frame )
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Capture' } )
return _capture( args )
end
function p.challenge( frame )
local args = getArgs( frame, { wrappers = 'Template:Pokemon Ranger/Challenge' } )
return _challenge( args )
end
return p