-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPokémonInfo-BoxAbil.lua
More file actions
165 lines (130 loc) · 4.43 KB
/
PokémonInfo-BoxAbil.lua
File metadata and controls
165 lines (130 loc) · 4.43 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
-- Abilities box for template PokémonInfo
local j = {}
-- stylua: ignore start
local mw = require('mw')
local txt = require('Wikilib-strings')
local tab = require('Wikilib-tables')
local l = require('Links')
local oop = require('Wikilib-oop')
local multigen = require('Wikilib-multigen')
local list = require('Wikilib-lists')
local abils = require("PokéAbil-data")
-- stylua: ignore end
--[[
This class represents a cell of the abilities box and contains information
about the abilities and the forms that share the same abilities combination.
--]]
local AbilsBox = oop.makeClass(list.Labelled)
--[[
Static fields and methods
--]]
AbilsBox.STRINGS = {
singleAbilBox = '<div class="width-xl-33 width-xs-50" style="padding: 0.2em;">${abil}<div class="small-text">${desc}</div></div>',
singleAbilNoLabel = '<div class="width-xl-33 width-xs-50" style="padding: 0.2em;">${abil}</div>',
formAbilsBox = '<div>${forms}</div><div class="flex flex-row flex-wrap flex-items-center flex-main-stretch" style="padding: 0.2em;">${abils}</div>',
formLabel = "<div class=\"width-xl-100\" style=\"padding-bottom: 0.2em;\">'''${label}'''</div>",
LABELS = {
ability1 = "Prima abilità",
ability2 = "Seconda abilità",
abilityd = "Abilità speciale",
abilitye = "Abilità evento",
},
}
-- Table holding forms to be ignored
AbilsBox.ignorableForms = {
"pikachuR",
"pikachuD",
"pikachuCn",
"pikachuS",
"pikachuW",
"pikachuCm",
"eeveeCm",
}
--[[
Constructor: takes the name of the Pokémon, and an optionally extended name of
the form. The name is given in the form name/ndex + abbreviation,
--]]
AbilsBox.new = function(name, formName)
-- Pokémon whose ability is yet unknown
if abils[name].ability1 == "" then
return nil
end
-- Ignored forms
if tab.search(AbilsBox.ignorableForms, name) then
return nil
end
local this = AbilsBox.super.new(formName)
this.abils = abils[name]
return setmetatable(this, AbilsBox)
end
AbilsBox.__eq = function(a, b)
return tab.equal(a.abils, b.abils)
end
-- Prints a single ability. If it's "Nessuna", it returns a "-" without link
local toStringAbil = function(abil)
if abil == "Nessuna" or abil == "Sconosciuta" then
return "—"
end
return l.aColor(abil)
end
--[[
Get the function to print a single ability.
--]]
AbilsBox.getAbilityPrinter = function(this)
local str = tab.getn(this.abils) == 1 and AbilsBox.STRINGS.singleAbilNoLabel
or AbilsBox.STRINGS.singleAbilBox
return function(ability, key)
return txt.interp(str, {
abil = multigen.printSpans(
multigen.getGenSpan(ability),
toStringAbil
),
desc = AbilsBox.STRINGS.LABELS[key],
})
end
end
--[[
Wikicode for an abilities box cell: the standard abilities are on the left,
and the hidden one is on the right. The event ability takes the place of the
hidden ability when there is none, otherwise it sits below. The form names
are added at the top, if present.
--]]
AbilsBox.__tostring = function(this)
local abilBoxes = tab.map(this.abils, this:getAbilityPrinter())
local temp = {}
-- Inserting ensures to avoid holes for concat
table.insert(temp, abilBoxes.ability1)
table.insert(temp, abilBoxes.ability2)
table.insert(temp, abilBoxes.abilityd)
table.insert(temp, abilBoxes.abilitye)
local abilstring = table.concat(temp)
local forms = #this.labels < 1 and ""
or txt.interp(AbilsBox.STRINGS.formLabel, {
label = mw.text.listToText(this.labels, ", ", " e "),
})
return txt.interp(AbilsBox.STRINGS.formAbilsBox, {
abils = abilstring,
forms = forms,
})
end
-- HTML code for the forms cells
local printBoxes = function(boxes)
local acc = tab.map(boxes, tostring)
return table.concat(acc)
end
--[[
Given a Pokémon name, or its ndex, returns the HTML code for the template
PokémonInfo abilities box. Every combination of abilities has its own cell,
with the forms that have if displayed above.
--]]
j.boxAbil = function(frame)
local name = txt.trim(frame.args[1] or "")
name = txt.parseInt(name) or mw.text.decode(name):lower()
return list.makeFormsLabelledBoxes({
name = name,
makeBox = AbilsBox.new,
printBoxes = printBoxes,
})
end
j.BoxAbil, j.box_abil, j.Box_abil = j.boxAbil, j.boxAbil, j.boxAbil
return j