forked from pokemoncentral/wiki-lua-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNdex-list.lua
86 lines (69 loc) · 2.16 KB
/
Ndex-list.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
--[[
This module prints the list of all Pokémon, useless alternative forms
included, for the ndex list (ie: only name, MS and type).
--]]
local n = {}
local tab = require('Wikilib-tables') -- luacheck: no unused
local txt = require('Wikilib-strings') -- luacheck: no unused
local list = require('Wikilib-lists')
-- local oop = require('Wikilib-oop')
local genUtils = require('Wikilib-gens')
-- local multigen = require('Wikilib-multigen')
local entry = require('Ndex')
local pokes = require('Poké-data')
local gendata = require("Gens-data")
local useless = require("UselessForms-data")
--[[
Print the list of Pokémon from the given generation.
Data (ie: types) are from the latest gen.
--]]
local listgen = function(gen)
-- Creates a fake Poké/data table with data for Pokémon from a single gen,
-- but adding also useless forms
local source = table.filter(pokes, function(v, k)
return not string.parseInt(k)
and genUtils.getGen.ndex(v.ndex) == gen
end)
for upoke, uval in pairs(useless) do
if source[upoke] then
for _, v in pairs(uval.gamesOrder) do
if v ~= "base" then
source[upoke .. v] = source[upoke]
end
end
end
end
return list.makeList({
source = source,
iterator = list.pokeNames,
makeEntry = entry.Entry.new,
-- entryArgs = gen,
header = entry.headerLua(gendata[gen].region),
separator = "",
footer = "</div>",
})
end
--[[
Main Wikicode interface. No parameters, just prints the list of Pokémon.
{{#invoke: Ndex/list | list }}
--]]
n.list = function(_)
local tables = {}
for gen = 1, gendata.latest do
table.insert(tables, table.concat{
"==", string.fu(gendata[gen].ext), " generazione==" })
table.insert(tables, listgen(gen))
end
return table.concat(tables, "\n")
end
--[[
Secondary Wikicode interface. Given a gen number, prints the list for that
generation.
Example:
{{#invoke: Ndex/list | listgen | 4 }}
--]]
n.listgen = function(frame)
return listgen(tonumber(frame.args[1]))
end
n.Listgen = n.listgen
return n