-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAbillist.lua
213 lines (179 loc) · 6.53 KB
/
Abillist.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
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
--[[
This module prints the list of all Pokémon, alternative forms included, having
a given ability.
--]]
local k = {}
-- stylua: ignore start
local tab = require('Wikilib-tables')
local txt = require('Wikilib-strings')
local list = require('Wikilib-lists')
local oop = require('Wikilib-oop')
local genlib = require('Wikilib-multigen')
local css = require('Css')
local cc = require('ChooseColor')
local ms = require('MiniSprite')
local resp = require('Resp')
local pokes = require("Poké-data")
local abils = require('PokéAbil-data')
local gens = require("Gens-data")
local mw = require('mw')
-- stylua: ignore end
--[[
Class representing a list entry. Fulfills requirements of makeList, sortNdex
and sortForms of Wikilib/lists
--]]
k.Entry = oop.makeClass(list.PokeLabelledEntry)
--[[
Printing ability is a complex job: event have to be handled, as well as
generation changes. The first argumetn is the ability to be printed, the second
one whether it should be marked or not, to be used for events.
--]]
k.Entry.printAbil = function(abil, marked)
if not abil then
return marked and "" or "Nessuna"
end
-- Marked abilities are italic
local toHTML
if marked then
toHTML = function(ability)
return table.concat({ "<div>''[[", ability, "]]''</div>" })
end
else
toHTML = function(ability)
return table.concat({ "[[", ability, "]]" })
end
end
if type(abil) == "string" then
return toHTML(abil)
end
-- Adding generations superscripts
return table.concat(tab.map(genlib.getGenSpan(abil), function(v)
local first, last = gens[v.first].roman, gens[v.last].roman
return txt.interp("<div>${abil}<sup>${gen}</sup></div>", {
abil = (v.val == "Nessuna" or v.val == "Sconosciuta") and v.val
or toHTML(v.val),
gen = v.first == v.last and first
or table.concat({ first, "-", last }),
})
end))
end
--[[
Constructor: the first argument is an entry from PokéAbil/data, the second
one its key.
--]]
k.Entry.new = function(pokeAbil, name)
local pokedata = genlib.getGen(pokes[name])
local this = k.Entry.super.new(name, pokedata.ndex)
this.abils = pokeAbil
if this.labels[1] == "" then
this.labels[1] = nil
end
return setmetatable(tab.merge(this, pokedata), k.Entry)
end
-- Wikicode for a list entry: Pokémon mini sprite, name, types and abilities.
k.Entry.__tostring = function(this)
-- local form = this.formsData
-- and this.formsData.blacklinks[this.formAbbr] or ''
local form = ""
if 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(
[=[| class="min-width-sm-20" data-sort-value="${ndex}" | ${static}
| class="black-text min-width-sm-40 min-width-xs-80" | [[${name}]]${form}
| class="min-width-xl-20 width-sm-40 width-xs-100" style="padding: 1ex 0.8ex;" | ${types}
| class="black-text min-width-sm-33" style="padding: 0.3ex;" | <div class="visible-sm text-small">Prima abilità</div>${abil1}${abilEv}
| class="black-text min-width-sm-33" style="padding: 0.3ex;" | <div class="visible-sm text-small">Seconda abilità</div>${abil2}
| class="black-text min-width-sm-33" style="padding: 0.3ex;" | <div class="visible-sm text-small">Abilità speciali</div>${abild}]=],
{
ndex = this.ndex and txt.ff(this.ndex) or "???",
static = ms.staticLua({
txt.ff(this.ndex or 0)
.. (this.formAbbr == "base" and "" or this.formAbbr or ""),
}),
name = this.name,
form = form,
types = resp.twoTypeBoxesLua(
this.type1,
this.type2,
{ "thin" },
nil,
{ "inline-block-sm", "min-width-sm-70" }
),
abil1 = k.Entry.printAbil(this.abils.ability1),
abilEv = k.Entry.printAbil(this.abils.abilitye, true),
abil2 = k.Entry.printAbil(this.abils.ability2),
abild = k.Entry.printAbil(this.abils.abilityd),
}
)
end
k.headers = {}
-- Wikicode for list header: it takes the color name
k.headers.makeHeader = function(color)
return txt.interp(
[=[{| class="sortable roundy text-center pull-center white-rows" style="border-spacing: 0; padding: 0.3ex; ${bg};"
|- class="hidden-sm ${text}"
! style="padding-top: 0.5ex; padding-bottom: 0.5ex;" | [[Elenco Pokémon secondo il Pokédex Nazionale|#]]
! Pokémon
! [[Tipo|Tipi]]
! Prima abilità
! Seconda abilità
! Abilità speciale]=],
{
bg = css.horizGradLua({ type = color }),
text = cc.forModGradBgLua(color),
}
)
end
k.headers.separator =
'|- class="roundy flex-sm flex-row flex-wrap flex-main-stretch flex-items-center" style="margin-top: 0.5rem;"'
k.headers.makeFooter = function(color)
return txt.interp(
[=[|-
! class="text-left font-small ${text}" colspan="6" style="padding: 0.3ex 0.3em;" |
* Le abilità in ''corsivo'' sono ottenibili solo in determinate circostanze.
|}]=],
{
text = cc.forModGradBgLua(color),
}
)
end
-- =============================== AbilEntry ===============================
-- Class representing an entry of a Pokémon with a certain ability.
k.AbilEntry = oop.makeClass(k.Entry)
--[[
Constructor: the same as the superclass but adding a filter for Pokémon with
a certain ability.
The first argument is an entry from PokéAbil/data, the second one its key and
the third is the ability the Pokémon must have.
--]]
k.AbilEntry.new = function(pokeAbil, name, abil)
if not tab.deepSearch(pokeAbil, abil) then
return nil
end
local this = k.AbilEntry.super.new(pokeAbil, name)
return setmetatable(this, k.AbilEntry)
end
--[[
Funzione d'interfaccia: si passano il tipo per il colore
e il titolo della pagina, da cui si ricava quello
dell'abilità.
--]]
k.abillist = function(frame)
local type = txt.trim(frame.args[1]) or "pcwiki"
local abil = txt.trim(mw.text.decode(frame.args[2]))
abil = abil or "Cacofonia"
return list.makeList({
source = abils,
iterator = list.pokeNames,
entryArgs = abil,
makeEntry = k.AbilEntry.new,
header = k.headers.makeHeader(type),
separator = k.headers.separator,
footer = k.headers.makeFooter(type),
})
end
k.Abillist = k.abillist
return k