-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMTCompatto.lua
More file actions
186 lines (157 loc) · 5.56 KB
/
MTCompatto.lua
File metadata and controls
186 lines (157 loc) · 5.56 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
--[[
Tabella contenente le MT e le MN delle varie generazioni
Può essere chiamato con il nome della pagina
{{#invoke: MTCompatto | MTCompatto | {{BASEPAGENAME}} }}
oppure con il nome di una mossa
{{#invoke: MTCompatto | MTCompatto | Surf }}
oppure specificando le generazioni da mostrare
{{#invoke: MTCompatto | MTCompatto | 123 | tipo = pcwiki }}
Si può anche usare MTGen per avere la tabella di una sola generazione
{{#invoke: MTCompatto | MTGen | 4 | width = 65% }}
--]]
local m = {}
-- stylua: ignore start
local mw = require('mw')
local w = require('Wikilib')
local tab = require('Wikilib-tables')
local txt = require('Wikilib-strings')
local multigen = require('Wikilib-multigen')
local links = require('AbbrLink')
local css = require('Css')
local cc = require('ChooseColor')
local machines = require("Machines-data")
local gens = require("Gens-data")
local moves = require("Move-data")
-- stylua: ignore end
local strings = {
MAIN_BOX = [=[
<br class="clear-all" />
<div class="roundy pull-center text-center mw-collapsible${collapsed} width-xl-55 width-md-75 width-sm-100" style="${bg} padding: 0.5ex; padding-bottom: 0.01ex;">
<div class="roundy text-center ${text}" style="font-weight: bold; margin-bottom: 0.5ex;">[[MT]] nelle varie generazioni</div>
<div class="mw-collapsible-content">${mtGens}
</div></div>
[[Categoria:Mosse Macchina]]]=],
GEN_BOX = [=[
<div class="roundy text-center pull-center text-small" style="${bg} width: ${wd}; padding: 0.5ex; margin-bottom: 0.5ex;">
${listmt}${listmn}${listdt}
</div>]=],
LIST_BOX = [=[
<div class="black-text" style="margin-top: 2px; font-weight: bold;">[[${kind}]] di [[${gen} generazione]]</div>
<div class="${roundy}" style="background: #eaeaea; margin-bottom: 2px; padding: 0px 2px;">${list}</div>
]=],
}
--[[
A partire da una lista di MT/MN del Modulo:Machines/data,
ritorna una stringa che contiene i link a
tutte le mosse in essa contenuta
--]]
local function makeMachinesList(list)
local mapped = tab.map(list, function(move, num)
num = string.format("%02d", num)
if type(move) == "table" then
return txt.interp("${num} (${games})", {
num = num,
games = table.concat(
tab.map(move, function(movegame)
local games, locmove = movegame[1], movegame[2]
games = mw.text.split(games, " ")
local keyGame = table.remove(games, 1)
return links[keyGame .. "Lua"]({
games = games,
multigen.getGenValue(moves[locmove].name),
})
end),
" | "
),
})
else
return txt.interp("[[${mv}|${num}]]", {
mv = multigen.getGenValue(moves[move].name),
num = num,
})
end
end)
if mapped[0] then
return mapped[0] .. " | " .. table.concat(mapped, " | ")
else
return table.concat(mapped, " | ")
end
end
--[[
Ritorna un div che contente le MT e MN
di una certa generazione.
width è opzionale, default 65%
--]]
local function MTGen(gen, width)
return txt.interp(strings.GEN_BOX, {
--bg = css.horizGradLua{type = gens[gen].region},
bg = txt.interp("background: #{{#invoke: colore | ${color} | light}};", {
color = gens[gen].region,
}),
wd = width or "65%",
gen = gens[gen].ext,
listmt = txt.interp(strings.LIST_BOX, {
kind = "MT",
roundy = (machines[gen].MN or machines[gen].DT) and ""
or "roundybottom",
list = makeMachinesList(machines[gen].MT),
gen = gens[gen].ext,
}),
listmn = machines[gen].MN and txt.interp(strings.LIST_BOX, {
kind = "MN",
roundy = "roundybottom",
list = makeMachinesList(machines[gen].MN),
gen = gens[gen].ext,
}) or "",
listdt = machines[gen].DT and txt.interp(strings.LIST_BOX, {
kind = "DT",
roundy = "roundybottom",
list = makeMachinesList(machines[gen].DT),
gen = gens[gen].ext,
}) or "",
})
end
--[[
Come il template MT compatto:
Prende in input il nome della pagina e restituisce la
tabella contenente le sottotabelle delle generazioni
in cui la mossa è un'MT o MN
--]]
m.MTCompatto = function(frame)
local params = w.trimAndMap(frame.args, string.lower)
local gens = {}
local color
local move = params[1] or mw.getCurrentTitle().text
local moveData = moves[move]
if not moveData then
move = mw.text.decode(move)
moveData = moves[move]
end
if moveData then
color = multigen.getGenValue(moveData.type)
for gen, genMc in ipairs(machines) do
if tab.deepSearch(genMc, move) then
table.insert(gens, MTGen(gen, "auto"))
end
end
else
color = params.tipo or "pcwiki"
gens = mw.text.split(params[1], "", true)
table.sort(gens)
gens = tab.map(gens, function(gen)
return MTGen(tonumber(gen), "auto")
end)
end
return txt.interp(strings.MAIN_BOX, {
bg = css.horizGradLua({ type = color }),
collapsed = #gens > 1 and " mw-collapsed" or "",
mtGens = table.concat(gens),
text = cc.forModGradBgLua(color),
})
end
m.MTGen = function(frame)
local params = w.trimAll(frame.args)
return MTGen(tonumber(params[1]), params.width)
.. "[[Categoria:Mosse Macchina]]"
end
return m