Module:PokemonByNumber: Difference between revisions
Jump to navigation
Jump to search
created module |
No edit summary |
||
| Line 10: | Line 10: | ||
end | end | ||
local allRowsCache = nil | local allRowsCache = nil | ||
local function loadAllRows() | local function loadAllRows() | ||
| Line 28: | Line 25: | ||
end | end | ||
local typeColorCache = {} | local typeColorCache = {} | ||
local function typeColorDark(frame, pokeType) | local function typeColorDark(frame, pokeType) | ||
| Line 43: | Line 36: | ||
pokeType = nonEmpty(pokeType) | pokeType = nonEmpty(pokeType) | ||
if not pokeType then | if not pokeType then | ||
return '<td></td>' | return '<td></td>' | ||
end | end | ||
Latest revision as of 11:51, 31 July 2026
Documentation for this module may be created at Module:PokemonByNumber/doc
local p = {}
local DATA_FORMAT = 'CSV with header'
local function nonEmpty(s)
if s == nil then return nil end
s = mw.text.trim(tostring(s))
if s == '' then return nil end
return s
end
local allRowsCache = nil
local function loadAllRows()
if allRowsCache then return allRowsCache end
local csvData = mw.ext.externalData.getExternalData{
url = 'https://wiki.pokemonrevolution.net/index.php?title=Special:GetData/PokemonRawList',
format = DATA_FORMAT,
data = {
number = 'Pokedex Number', name = 'Name', type1 = 'Type1', type2 = 'Type2',
generation = 'Generation', wild = 'Wild', npc = 'NPC',
},
}
allRowsCache = csvData or {}
return allRowsCache
end
local typeColorCache = {}
local function typeColorDark(frame, pokeType)
if not typeColorCache[pokeType] then
typeColorCache[pokeType] = frame:expandTemplate{ title = pokeType .. ' color' }
end
return typeColorCache[pokeType]
end
local function typeCell(frame, pokeType)
pokeType = nonEmpty(pokeType)
if not pokeType then
return '<td></td>'
end
return '<td style="background: #' .. typeColorDark(frame, pokeType) .. ';">[[' .. pokeType ..
'_(type)|<span style="color:#FFFFFF">' .. pokeType .. '</span>]]</td>'
end
function p.main(frame)
local gen = nonEmpty(frame.args[1])
if not gen then
return "<span style='color:red'>Usage: {{PokemonByNumber|GenerationNumber}}</span>"
end
local buf = {}
buf[#buf + 1] = '<table class="pro-table" align="center" style="width: 61%; text-align: center;">'
buf[#buf + 1] = '<tr class="pro-table-header"><th scope="col" class="pro-table-header-cell" ' ..
'style="border-radius: 15px 1px 1px 1px; width: 5%">No.</th>' ..
'<th scope="col" class="pro-table-header-cell" colspan="2" width="21%">Name</th>' ..
'<th scope="col" class="pro-table-header-cell" width="18%">Type 1</th>' ..
'<th class="pro-table-header-cell" style="border-radius: 1px 15px 1px 1px; width: 18%">Type 2</th></tr>'
for _, row in ipairs(loadAllRows()) do
if row.generation == gen then
-- "'''emboldened''' = wild-encounterable, ''italicized'' =
-- NPC-obtainable" per the footer note below; the original just
-- echoed the raw Wild/NPC field text around the name instead of
-- actually applying that formatting.
local nameLink = '[[' .. row.name .. ']]'
if nonEmpty(row.wild) then
nameLink = "'''" .. nameLink .. "'''"
end
if nonEmpty(row.npc) then
nameLink = "''" .. nameLink .. "''"
end
buf[#buf + 1] = '<tr style="background-color: #DDD; color: #000000;">' ..
'<td>' .. row.number .. '</td>' ..
'<td width="5%">[[File:' .. row.number .. 'Icon.png]]</td>' ..
'<td>' .. nameLink .. '</td>' ..
typeCell(frame, row.type1) ..
typeCell(frame, row.type2) ..
'</tr>'
end
end
buf[#buf + 1] = '<tr><td style="border-radius: 1px 1px 15px 15px; text-align: left; padding: 3px; ' ..
'color: #FFFFFF; font-size: 13px; margin-left: 10px;" colspan="5">' ..
"<ul><li>All '''emboldened''' Pokémon are encounterable in the wild</li>" ..
"<li>All ''italicized'' Pokémon are NPC-obtainable</li></ul>" ..
'See Pokémon-individualized pages for more information.</td></tr>'
buf[#buf + 1] = '</table>'
return table.concat(buf)
end
return p