forked from pokemoncentral/wiki-lua-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatlist-unique.lua
148 lines (119 loc) · 4.37 KB
/
Statlist-unique.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
--[[
This module prints a list of all Pokémon
having unique base stat total
--]]
local u = {}
local css = require('Css')
local ms = require('MiniSprite')
local gamesUtil = require('Wikilib-games')
local list = require('Wikilib-lists')
local oop = require('Wikilib-oop')
local statsUtil = require('Wikilib-stats')
local str = require('Wikilib-strings') -- luacheck: no unused
local tab = require('Wikilib-tables') -- luacheck: no unused
local multigen = require('Wikilib-multigen')
local gendata = require("Gens-data")
local pokes = require('Poké-data')
--[[
Mapreduce part of the module: returns a table
whose keys are Pokémon names and values their
base stat total, filtering only unique base
stat total values.
Even though makeList allows for some form of
filtering, it does not allow conditions to be
based on the whole collection, making a separate
function necessary.
--]]
local uniqueStatTotal = function(allStats, gen)
local pokesInGen = table.filter(allStats, function(_, poke)
return not string.parseInt(poke)
and gamesUtil.isInGen(poke, gen)
end)
-- Mapping to base stat totals
local tots = table.map(pokesInGen, function(pokeStats)
return statsUtil.statsSum(
statsUtil.getStatsGen(pokeStats, gen))
end)
--[[
Filtering unique base stat totals only:
checks if there's not any base stat total
equal to the current one but of a different
Pokémon
--]]
return table.filter(tots, function(tot, poke)
return not table.any(tots, function(otherTot, otherPoke)
return tot == otherTot and poke ~= otherPoke
end)
end)
end
--[[
Class representing an entry for the unique stat total
list. By subclassing PokeSortableEntry it implements
all the interfaces needed for sortForm, sortNdex
and makeList in Wikilib/lists
--]]
local Entry = oop.makeClass(list.PokeSortableEntry)
--[[
Constructor: the first argument is a base stat total
and the second the name of the Pokémon having it.
Filtering requires checking other entries, and is
therefore not implemented here: hence, this constructor
never returns nil.
--]]
Entry.new = function(total, name)
local this = table.merge(
Entry.super.new(name),
multigen.getGen(pokes[name])
)
this.total = total
return setmetatable(this, Entry)
end
--[[
Wikicode for a list entry: shows Pokémon ndex,
mini sprite, name and base stats, plus total
and average.
--]]
Entry.__tostring = function(this)
return string.interp([=[| class="hidden-xs" style="padding: 0.3ex 0.6ex" | ${ndex}
| style="padding: 0.3ex 0.6ex" | ${ms}
| style="padding: 0.3ex 0.6ex" | [[${name}|<span style="color: #000;">${name}</span>]]${form}
| style="padding: 0.3ex 0.6ex" | '''${total}''']=],
{
ndex = this.ndex and string.tf(this.ndex) or '???',
ms = ms.staticLua{string.tf(this.ndex or 0) ..
(this.formAbbr == 'base' and ''
or this.formAbbr or '')},
name = this.name,
form = this.formsData and
this.formsData.blacklinks[this.formAbbr]
or '',
total = this.total
})
end
--[[
Wiki interface function: returns the list
of all Pokémon having unique base stat total
in the provided generation, which defaults
to the latest.
Examples:
Latest generation:
{{#invoke: Statlist/unique | statlistUnique }}
Specific generation:
{{#invoke: Statlist/unique | statlistUnique | 4 }}
--]]
u.statlistUnique = function(frame)
local gen = tonumber(frame.args[1]) or gendata.latest
return list.makeList({
source = uniqueStatTotal(require('PokéStats-data'), gen),
makeEntry = Entry,
header = string.interp([=[{| class="sortable roundy-corners pull-center text-center white-rows" style="border-spacing: 0; padding: 0.3ex; ${bg};"
|-
! class="hidden-xs" style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 0.8ex;" | [[Pokédex Nazionale|<span style="color: #000;">#</span>]]
! style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 0.8ex;" |
! style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 0.8ex;" | Pokémon
! style="padding-top: 0.8ex; padding-bottom: 0.8ex; padding-left: 0.8ex;" | Totale]=],
{ bg = css.horizGradLua{type = 'pcwiki'} })
})
end
u.StatlistUnique = u.statlistUnique
return u