forked from pokemoncentral/wiki-lua-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbillist-allpokes.lua
126 lines (95 loc) · 3.18 KB
/
Abillist-allpokes.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--[[
This module prints the list of all Pokémon, alternative forms included, with
their ability.
--]]
local k = {}
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 abl = require('Abillist')
local pokes = require("Poké-data")
local abils = require('PokéAbil-data')
local gendata = require("Gens-data")
-- Generation filtered entry
k.GenEntry = oop.makeClass(abl.Entry)
--[[
Constructor: the first argument is an entry from PokéAbil/data, the second
one its key and the third one, optional, marks the generation this entry
should display data for: if omitted, all the generation but the first are taken
in account
--]]
k.GenEntry.new = function(pokeAbil, name, gen)
if gen and genUtils.getGen.ndex(pokes[name].ndex) ~= gen then
return nil
end
if pokeAbil.ability1 == "" then
return nil
end
local this = k.GenEntry.super.new(pokeAbil, name)
return setmetatable(this, k.GenEntry)
end
--[[
Equality operator for entries' merging.
--]]
k.GenEntry.__eq = function(a, b)
-- The two entries are equals iff their name and abilities are the same
return a.name == b.name and table.equal(a.abils, b.abils)
end
--[[
Print the list of Pokémon from the given generation.
--]]
local listgen = function(gen)
return list.makeCollapsedList({
source = abils,
iterator = list.pokeNames,
makeEntry = k.GenEntry.new,
entryArgs = gen,
header = abl.headers.makeHeader(gendata[gen].region),
separator = abl.headers.separator,
footer = abl.headers.makeFooter(gendata[gen].region),
fullGroupLabel = 'Tutte le forme',
})
end
--[[
Main Wikicode interface. No parameters, just prints the list of Pokémon with
their abilities.
{{#invoke: Abillist/allpokes | abillist }}
--]]
k.abillist = function(frame) -- luacheck: no unused
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
k.Abillist = k.abillist
--[[
Secondary Wikicode interface. Given a gen number, prints the list for that
generation.
Example:
{{#invoke: Abillist/allpokes | listgen | 8 }}
--]]
k.listgen = function(frame)
return listgen(tonumber(frame.args[1]))
end
--[[
WikiCode interface to print a list of entries. Supports only Pokémon names.
Example:
{{#invoke: Abillist/allpokes | manualEntry | staraptor goomy ampharos scraggy }}
--]]
k.list = function(frame)
local ndexlist = frame.args[1]
local res = { abl.headers.makeHeader(string.trim(frame.args.color)) }
for ndex in ndexlist:gmatch("[^ ]+") do
table.insert(res, tostring(k.GenEntry.new(abils[ndex], ndex)))
end
table.insert(res, abl.headers.makeFooter(string.trim(frame.args.color)))
return table.concat(res, "\n|-\n")
-- return table.concat(res, "\n|-\n") .. "\n" .. abl.headers.makeFooter(string.trim(frame.args.color))
end
k.List = k.list
return k