-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHelditemslist.lua
More file actions
182 lines (150 loc) · 4.6 KB
/
Helditemslist.lua
File metadata and controls
182 lines (150 loc) · 4.6 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
--[[
Module to create an entry in the list of Pokémon by wild held items.
--]]
local h = {}
-- stylua: ignore start
local txt = require('Wikilib-strings')
local tab = require('Wikilib-tables')
local oop = require('Wikilib-oop')
local list = require('Wikilib-lists')
local multigen = require('Wikilib-multigen')
local links = require('Links')
local ms = require('MiniSprite')
local pokes = require("Poké-data")
local blackabbrev = require("Blackabbrev-data")
local colorabbrev = require("Colorabbrev-data")
-- stylua: ignore end
h.Entry = oop.makeClass(list.PokeLabelledEntry)
-- Utility strings
h.Entry.strings = {
ENTRY_HEAD = [=[<div class="roundy text-center width-xl-100 flex flex-row flex-wrap flex-main-center flex-items-center horiz-grad-${type1}-${type2}" style="padding: 0.5ex; margin: 1ex 0">
<div class="roundy bg-white flex flex-row flex-nowrap flex-main-center flex-items-center" style="padding: 0 1ex; margin: 0.5ex;">
<div>'''${ndex}'''</div>
<div>${ms}</div>
<div>[[${name}]]${blacklink}</div>
</div>
<div class="flex-row-stretch-around flex-wrap">]=],
ENTRY_FOOT = [[</div></div>]],
BOX_HEAD = [[<div class="roundy bg-white flex-row-center-around flex-wrap" style="margin: 0.5ex;">]],
BOX_FOOT = [[</div>]],
PERC_BOX = [=[<div style="padding: 1ex;">
<div>${abbrev}</div>
<div>${img}</div>
<div>${percentage}%</div>
</div>]=],
}
-- Table to get colored abbrevs from type and game abbr
h.Entry.abbrevs = {
black = function(abbr)
return blackabbrev[abbr]
end,
color = function(abbr)
return table.concat({
" ",
colorabbrev[abbr],
" ",
})
end,
}
--[[
Create a single game box taking an array of item/game tables (element of the
data module array).
--]]
h.Entry.makeGameBox = function(this, itemsList, gen)
local percBoxes = tab.map(itemsList, function(v)
local abbrevs = table.concat(tab.map(v.games, function(abbr, index)
if v.abbrTypes then
return this.abbrevs[v.abbrTypes[index]](abbr)
else
return this.abbrevs.black(abbr)
end
end))
return txt.interp(this.strings.PERC_BOX, {
abbrev = abbrevs,
img = gen < 3
and txt.interp('<span class="black-text">[[${item}]]</span>', {
item = v.item == "Perla" and "Perla (strumento)|Perla"
or v.item,
})
or links.bag(v.item),
percentage = v.perc,
})
end)
if #percBoxes > 0 then
table.insert(percBoxes, this.strings.BOX_FOOT)
return this.strings.BOX_HEAD .. table.concat(percBoxes)
else
return ""
end
end
--[[
Constructor: the first argument is an entry from HeldItems/data, the second one
is its key.
--]]
h.Entry.new = function(helds, poke)
-- Skip empty entries
if #helds == 0 then
return
end
local this = h.Entry.super.new(poke, pokes[poke].ndex)
this.helds = helds
return setmetatable(this, h.Entry)
end
--[[
Equality operator for grouping. True iff the two entries have the exact same
this.helds
--]]
h.Entry.__eq = function(a, b)
return a.ndex == b.ndex and tab.equal(a.helds, b.helds)
end
--[[
Wikicode for a list entry.
--]]
h.Entry.__tostring = function(this)
local pokedata = multigen.getGen(pokes[this.name])
local form = "<div>"
.. table.concat(
tab.map(this.labels, function(label)
return this.formsData.blacklinks[label]:gsub(
"<(/?)div",
"<%1span"
)
end),
", "
)
.. "</div>"
local result = {
txt.interp(this.strings.ENTRY_HEAD, {
type1 = pokedata.type1,
type2 = pokedata.type2,
ndex = txt.ff(this.ndex),
ms = ms.staticLua({
txt.ff(this.ndex)
.. (this.formAbbr == "base" and "" or this.formAbbr or ""),
}),
name = pokedata.name,
blacklink = form,
}),
}
tab.map(this.helds, function(v, gen)
table.insert(result, this:makeGameBox(v, gen))
end, ipairs)
table.insert(result, this.strings.ENTRY_FOOT)
return table.concat(result)
end
--[[
Main wikicode interface.
--]]
h.helditem = function(_)
return list.makeGroupedList({
source = require("PokéItems-data"),
makeEntry = h.Entry.new,
iterator = list.pokeNames,
header = "",
separator = "",
footer = "",
fullGroupLabel = "",
})
end
h.Helditem = h.helditem
return h