-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDebRes-1glitch.lua
More file actions
212 lines (177 loc) · 6.21 KB
/
DebRes-1glitch.lua
File metadata and controls
212 lines (177 loc) · 6.21 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
--[[
Crea una tabella in cui sono presenti tutte le debolezze e
resistenze di un Pokémon Glitch di prima generazione.
Per i Pokémon glitch con più forme (Missigno.), crea solo le tabelle
effettivamente diverse, inserendo nel titolo tutte le
forme che condividono la stessa.
Può essere chiamato con il nome di un Pokémon, es:
{{#invoke: DebRes/1glitch | DebRes | 'M (00) }}
Se un glitch con lo stesso nome compare in più giochi
il modulo crea automaticamente una tabella diversa per
ogni gioco in cui ha debolezze e resistenze diverse
richiamandolo con solo il nome
(ATTENZIONE: non crea una tabella per ogni combinazione
di tipi diversa ma per ogni combinazione di debolezze e
resistenze diversa)
--]]
local dr = {}
-- stylua: ignore start
local mw = require('mw')
local w = require('Wikilib')
local txt = require('Wikilib-strings')
local tab = require('Wikilib-tables')
local wdata = require("Wikilib-data")
local gamesUtil = require('Wikilib-games')
local list = require('Wikilib-lists')
local oop = require('Wikilib-oop')
local sig = require('Wikilib-sigle')
local drbase = require('DebRes-base')
local etdata = require("EffTipi-1glitch-data")
local glitch = require("Glitch-data")
-- stylua: ignore end
--[[
Questa classe rappresenta una tabella di efficacia
tipi di prima generazione. Primariamente, contiene
informazioni riguardo l'efficacia dei vari tipi di
attacchi contro un certo Pokémon, ovvero contro una
certa combinazione di tipi; oltre a ciò, possiede
le righe che compongono il footer.
--]]
local GlitchEffTable = oop.makeClass(drbase.EffTable)
-- Tutti i possibili moltiplicatori dell'efficacia
GlitchEffTable.allEff = { 0, 0.25, 0.5, 1, 2, 4 }
-- Override addLabel to use the game name as label
GlitchEffTable.addLabel = function(this, label)
if type(label) == "table" then
this.labels = tab.merge(this.labels, label)
else
table.insert(this.labels, sig.gamesName(label, "/"))
end
end
-- Override createColors to handle glitch types
GlitchEffTable.createColors = function(this)
this.colors = tab.copy(this.types)
for k, v in pairs(this.colors) do
v = string.lower(v)
this.colors[k] = (v == "coleottero" or tab.search(wdata.allTypes, v))
and v
or "sconosciuto"
end
end
-- Stringhe utili per il footer
GlitchEffTable.FooterStrings = {
-- Testo se il Pokémon ha tipi diversi da quelli dell'efficacia
CHANGETYPE = "\n* Nonostante questo Pokémon sia di tipo ${typeOr}, subisce danni come se fosse di tipo ${typeEff}",
-- Link ad un tipo
TYPE = "[[${type1}]]",
-- Link ad un doppio tipo
DUALTYPE = "[[${type1}]]/[[${type2}]]",
}
--[[
Costruttore della classe: ha in ingresso il
nome del Pokémon, nella forma nome + sigla gioco,
e, opzionalmente, il nome esteso dell gioco
--]]
GlitchEffTable.new = function(name, game)
-- Can't call super.new because it requires parameters that do not exists
-- for glitches
local this = setmetatable(GlitchEffTable.super.super.new(), GlitchEffTable)
if game then
name = name:gsub("(.*)" .. game .. "$", "%1")
-- se viene passato il gioco, il glitch ha più
-- forme, quindi bisogna aggiungere la label
this:addLabel(game)
else
game = tab.deepSearch(glitch, name)
end
local data = glitch[game][tab.deepSearch(glitch[game], name)]
local types = data.typeEffectiveness and tab.copy(data.typeEffectiveness)
or { data.type1, data.type2 }
if not types[2] then
types[2] = types[1]
end
this.types =
{ type1 = string.lower(types[1]), type2 = string.lower(types[2]) }
this.typeEffectiveness = data.typeEffectiveness
this.abil = "nessuna"
this.gen = 1
this.et = etdata
-- Colori per la stampa
this:createColors()
this:computeEff()
this:makeFooter()
return this
end
GlitchEffTable.makeFooter = function(this)
local types = tab.map(this.types, txt.fu)
local effTypes = this.typeEffectiveness
this.footer = {}
-- Creates the only possible footer row
if effTypes then
table.insert(
this.footer,
txt.interp(GlitchEffTable.FooterStrings.CHANGETYPE, {
typeOr = txt.interp(
types.type2 and GlitchEffTable.FooterStrings.DUALTYPE
or GlitchEffTable.FooterStrings.TYPE,
types
),
typeEff = txt.interp(
effTypes[2] and GlitchEffTable.FooterStrings.DUALTYPE
or GlitchEffTable.FooterStrings.TYPE,
{
type1 = effTypes[1],
type2 = effTypes[2],
}
),
})
)
end
end
--[[
Funzione d'interfaccia al wikicode: prende in ingresso
il nome di un Pokémon glitch e genera le table dell'efficacia
tipi di prima generazione. Se il Pokémon ha più forme,
ritorna una table per ogni forma, tutte collassabili con
solo quella della forma base estesa al caricamento della pagina.
--]]
dr.debRes = function(frame)
local p = tab.map(frame.args, w.trim)
local games = {}
local name = mw.text.decode(p[1])
--[[
controlla se il glitch esiste in più giochi,
e nel caso prepara una table con l'elenco
dei giochi
--]]
if p[2] or p.game then
table.insert(games, p[2] or p.game)
else
for game, glitches in pairs(glitch) do
if tab.deepSearch(glitches, name) then
table.insert(games, game)
end
end
end
-- Crea altData a partire da games
local altData
if #games > 1 then
altData = { gamesOrder = {}, names = {} }
for _, v in ipairs(games) do
table.insert(altData.gamesOrder, v)
altData.names[v] = v
end
-- Ordina altData.gamesOrder in modo da avere prima i giochi più vecchi
table.sort(altData.gamesOrder, function(a, b)
return gamesUtil.isBefore(string.lower(a), string.lower(b))
end)
end
return list.makeFormsLabelledBoxes({
name = name,
makeBox = GlitchEffTable.new,
printBoxes = GlitchEffTable.printEffTables,
altData = altData,
})
end
dr.DebRes, dr.debres = dr.debRes, dr.debRes
return dr