-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStatlist.lua
More file actions
297 lines (250 loc) · 11.6 KB
/
Statlist.lua
File metadata and controls
297 lines (250 loc) · 11.6 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
--[[
This module prints a list of all Pokémon base statistics.
Generation I has a separate table because it has different statistics, while
the other are merged into one.
--]]
local s = {}
-- stylua: ignore start
local tab = require('Wikilib-tables')
local txt = require('Wikilib-strings')
local css = require('Css')
local ms = require('MiniSprite')
local gamesUtil = require('Wikilib-games')
local genUtil = require('Wikilib-gens')
local formUtil = require('Wikilib-forms')
local list = require('Wikilib-lists')
local mg = require('Wikilib-multigen')
local oop = require('Wikilib-oop')
local statsUtil = require('Wikilib-stats')
local c = require("Colore-data")
local gendata = require("Gens-data")
local pokes = require('Poké-data')
local stats = require('PokéStats-data')
local mw = require('mw')
-- stylua: ignore end
--[[
Class representing an entry for the base statistics list. By subclassing
PokeSortableEntry it implements all the interfaces needed for sortForm,
sortNdex and makeList in Wikilib/lists
--]]
s.Entry = oop.makeClass(list.PokeLabelledEntry)
--[[
Returns a stub for the generation span of the statistics sum, which lacks the
end. The starting generation is either the passed one or the latest; the value
itself is computed from those of the passed statistics in such generation.
--]]
s.Entry.makeSumSpan = function(stats, gen)
gen = gen or gendata.latest
stats = statsUtil.getStatsGen(stats, gen)
return {
val = statsUtil.statsSum(stats),
first = gen,
}
end
--[[
Returns the generation spans for the statistics sum, starting from the given
generation. First generation is not included.
--]]
s.Entry.makeSum = function(stats, startGen)
--[[
If stats have not changed throughout the generations, returning a
single span beginning and ends in the latest generation.
--]]
if not statsUtil.didStatsChange(stats) then
local sum = s.Entry.makeSumSpan(stats)
sum.last = gendata.latest
return { sum }
end
-- Skipping first gen
startGen = math.max(startGen, 2)
local sums = { s.Entry.makeSumSpan(stats, startGen) }
for gen = startGen + 1, gendata.latest do
-- Whether any stat changed in the current gen
local anyChange = tab.any(stats, function(stat)
return type(stat) == "table" and stat[gen]
end)
if anyChange then
sums[#sums].last = gen - 1
table.insert(sums, s.Entry.makeSumSpan(stats, gen))
end
end
sums[#sums].last = gendata.latest
return sums
end
--[[
Wikicode for a single stat cell: can print both generation spans and single
values
--]]
s.Entry.printStatCell = function(stat, statName)
local interpData = { bg = c[statName].light }
if type(stat) == "number" then
interpData.val = txt.printNumber(stat)
interpData.latest = stat
else
interpData.val = mg.printSpans(stat, txt.printNumber)
interpData.latest = stat[#stat].val
end
return txt.interp(
'| style="padding: 0.3ex 0.8ex; font-weight: bolder; background: #${bg};" data-sort-value="${latest}" | ${val}',
interpData
)
end
--[[
Constructor: the first argument is an entry from PokéStats/data; the second one
is its key; the third one is optional, and marks the generation this entry
should display data for: if omitted, all the generation but the first are taken
in account. Therefore, the only filtering performed is to exclude Pokémon and
forms not existing in the passed generation, if any.
--]]
s.Entry.new = function(stats, poke, gen)
if gen and not gamesUtil.isInGen(poke, gen) then
return nil
end
local this = s.Entry.super.new(poke, pokes[poke].ndex)
-- No generation means from second onwards
this.statsOrder = statsUtil.statsOrder[gen or 2]
-- Statistics are not merged at top level to ease subsequent calculations
if gen then
-- No need for generation spans in single-generation case
this.stats = statsUtil.getStatsGen(stats, gen)
this.statsSum = statsUtil.statsSum(this.stats)
this.statsAvg = this.statsSum / tab.getn(this.stats)
else
local pokeGen = this.formAbbr
and genUtil.getGen.game(this.formsData.since[this.formAbbr])
or genUtil.getGen.ndex(this.ndex)
pokeGen = math.max(pokeGen, 2)
this.stats = statsUtil.cleanStats(mg.getGenSpans(stats), 2)
this.statsSum = s.Entry.makeSum(stats, pokeGen)
local statsCount = tab.getn(this.stats)
this.statsAvg = tab.map(this.statsSum, function(span)
span = mw.clone(span)
span.val = span.val / statsCount
return span
end)
end
return setmetatable(this, s.Entry)
end
--[[
Equality operator for entries' merging.
--]]
s.Entry.__eq = function(a, b)
-- The two entries are equals iff their stats tables are the same
return tab.equal(a.stats, b.stats)
end
--[[
Wikicode for a list entry: shows Pokémon ndex, mini sprite, name and base
stats, plus total and average.
--]]
s.Entry.__tostring = function(this)
local cells = tab.map(this.statsOrder, function(stat)
return s.Entry.printStatCell(this.stats[stat], stat)
end, ipairs)
table.insert(cells, s.Entry.printStatCell(this.statsSum, "pcwiki"))
table.insert(cells, s.Entry.printStatCell(this.statsAvg, "pcwiki"))
local name = pokes[this.name].name
local form = ""
if this.labels[1] and this.labels[1] ~= "" then
form = this.labels[1] == "Tutte le forme"
and '<div class="small-text">Tutte le forme</div>'
or this.formsData.blacklinks[this.formAbbr]
end
return txt.interp(
[=[| style="padding: 0.3ex 0.8ex;" data-sort-value="${sortDex}" | ${ndex}
| style="padding: 0.3ex 0.8ex;" data-sort-value="${sortName}" | ${ms}
| class="black-text" style="padding: 0.3ex 0.8ex;" | [[${name}]]${form}
${statsCells}]=],
{
sortDex = this.ndex or "???",
ndex = genUtil.ndexToString(this.ndex),
sortName = formUtil.formSortValue(this.ndex, this.formAbbr, name),
ms = ms.staticLua({
txt.ff(this.ndex or 0)
.. (this.formAbbr == "base" and "" or this.formAbbr or ""),
}),
name = name,
form = form,
statsCells = table.concat(cells, "\n"),
}
)
end
-- Headers
s.headers = {}
-- List header
s.headers.header = txt.interp(
[=[{| class="roundy-corners text-center pull-center white-rows sortable" style="border-spacing: 0; padding: 0.6ex; ${bg};"
|-
! class="black-text" style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex;" | [[Elenco Pokémon secondo il Pokédex Nazionale|#]]
! colspan="2" style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex;" | Pokémon
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${hp};" | [[Statistiche#PS|PS]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${atk};" | [[Statistiche#Attacco|Attacco]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${def};" | [[Statistiche#Difesa|Difesa]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${spatk};" | [[Statistiche#Attacco Speciale|Attacco Sp.]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${spdef};" | [[Statistiche#Difesa Speciale|Difesa Sp.]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${spe};" | [[Statistiche#Velocità|Velocità]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${pcw};" | Totale
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${pcw};" | Media]=],
{
bg = css.horizGradLua({ type = "pcwiki" }),
hp = c.ps.normale,
atk = c.attacco.normale,
def = c.difesa.normale,
spatk = c.attacco_speciale.normale,
spdef = c.difesa_speciale.normale,
spe = c.velocita.normale,
pcw = c.pcwiki.dark,
}
)
-- List header
s.headers.firstGenHeader = txt.interp(
[=[{| class="roundy-corners text-center pull-center white-rows sortable" style="border-spacing: 0; padding: 0.6ex; ${bg};"
|-
! class="black-text" style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex;" | [[Elenco Pokémon secondo il Pokédex Nazionale|#]]
! colspan="2" style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex;" | Pokémon
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${hp};" | [[Statistiche#PS|PS]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${atk};" | [[Statistiche#Attacco|Attacco]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${def};" | [[Statistiche#Difesa|Difesa]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${spec};" | [[Statistiche#Speciali|Speciali]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${spe};" | [[Statistiche#Velocità|Velocità]]
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${pcw};" | Totale
! class="roundytop text-small white-text" style="position: sticky; top: 0; z-index: 10; padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 1ex; background-color: #${pcw};" | Media]=],
{
bg = css.horizGradLua({ type = "pcwiki" }),
hp = c.ps.normale,
atk = c.attacco.normale,
def = c.difesa.normale,
spec = c.speciale.normale,
spe = c.velocita.normale,
pcw = c.pcwiki.dark,
}
)
--[[
Wiki interface function: called with no argument, returns the list of all
Pokémon statistics for all generations but the first, which has a separate
table.
Example:
{{#invoke: Statlist | statlist }}
--]]
s.statlist = function(_)
return table.concat({
[[===Dalla seconda generazione in poi===]],
list.makeCollapsedList({
source = stats,
makeEntry = s.Entry.new,
iterator = list.pokeNames,
header = s.headers.header,
fullGroupLabel = "Tutte le forme",
}),
[[===Nella prima generazione===]],
list.makeCollapsedList({
source = stats,
makeEntry = s.Entry.new,
entryArgs = 1,
iterator = list.pokeNames,
header = s.headers.firstGenHeader,
fullGroupLabel = "Tutte le forme",
}),
}, "\n")
end
s.Statlist = s.statlist
return s