Differenze tra le versioni di "Modulo:Sandbox"

Prove modulo Box
(Prove modulo Box)
 
--[[
-- Gli entries dei learnlist di terza generazione
 
This module contains utility code for boxes: these are a link in a rounded
local z = {}
box, with a left-to-right gradient from the dark shade of a color to the
normal shade of the same color.
 
Other than this basic styles, the best way to style a box is via predefinite
configurations. For example, 'thick' creates a box with lots of whitespace
above and below the text, while 'tiny' returns a small box, with small text
and little whitespace around it. For more predefinite styles, check the
MANUALE DI STILE INTERMEDIO.
 
The basic function is called box, and has the following arguments:
 
- 1: displayed text.
- 2: link target, Defaults to text.
- 3: gradient color, from dark to normal, right-to-left.
- 4: Space-separated string of predefined configurations names. Optional,
defaults to no predefined configurations.
- 5: Space-separated list of CSS classes. Optional, defaults to no CSS classes.
- 6: CSS styles, in the format of an HTML style attribute values. Optional,
defaults to no CSS styles.
- 7: Text color, defaults to white-text
 
Example call:
 
{{#invoke: Box | box | erba | erba (Gruppo Uova) | erba_uova | thin |
inline-block width-sm-60 | padding: 2ex; margin-top: 0.5ex; | white-text }}
 
There is also a number of shorthands, with a rather similar call. They are
listed below:
 
- TypeBox: a box displaying a type, with its color as background. Arguments:
 
- 1: The type. Defaults to 'Sconosciuto'.
- 2: Space-separated string of predefined configurations names. Optional,
defaults to no predefined configurations.
- 3: Space-separated list of CSS classes. Optional, defaults to no CSS
classes.
- 4: CSS styles, in the format of an HTML style attribute values. Optional,
defaults to no CSS styles.
 
Example: {{#invoke: Box | typeBox | Elettro | thick | | margin: 3em; }}
 
- CatBox: a box displaying a move category, with its color as background. Arguments:
 
- 1: The category. Defaults to 'Stato'.
- 2: Space-separated string of predefined configurations names. Optional,
defaults to no predefined configurations.
- 3: Space-separated list of CSS classes. Optional, defaults to no CSS
classes.
- 4: CSS styles, in the format of an HTML style attribute values. Optional,
defaults to no CSS styles.
 
Example: {{#invoke: Box | catBox | Speciale | thin | | margin: 3em; }}
 
- EggBox: a box displaying an egg grup, in its color as a background. Arguments:
 
- 1: The egg group, without ' (Gruppo Uova)' suffix. Defaults to
'Sconosciuto (Gruppo Uova)'.
- 2: Space-separated string of predefined configurations names. Optional,
defaults to no predefined configurations.
- 3: Space-separated list of CSS classes. Optional, defaults to no CSS
classes.
- 4: CSS styles, in the format of an HTML style attribute values. Optional,
defaults to no CSS styles.
 
Example: {{#invoke: Box | eggBox | Erba | | inline-block | margin: 3em; }}
 
In addition to the single box versions, also multiple box version are provided
for the shorthands. Their name is the same as the shorthand, with 'box'
replaced by 'list'. They are invoked the same way, except that the first
argument is a comma-separated list of types, egg groups, etc. The other
arguments are applied to all generated boxes. Some example calls below:
 
- typeList: {{#invoke: Box | typeList | Elettro, Terra, Acciaio | |
inline-block | margin: 3em; }}
 
- eggList: {{#invoke: Box | eggList | Acqua 1, Campo, Magico | tiny }}
 
--]]
 
local b = {}
 
-- stylua: ignore start
local txt = require('Modulo:Wikilib/strings')
local libtab = require('Modulo:Wikilib/learnliststables')
local scss = mw.loadDatarequire('Modulo:Sup/dataCss')
local abbrLibw = require('Modulo:Wikilib/sigle')
-- stylua: ignore end
 
--[[
-- Funzione chiamata da tutti gli entry per generare le celle dalla seconda in poi
This table holds predefined styles configurations for boxes. Names of
such configurations are the keys, while values are tables with 'classes'
and 'styles' keys. These hold classes and styles respectively, and have as
values the same structures as arseClasses and parseStyles return.
--]]
local predefs = {
thick = {
classes = { "roundy-5", "text-center" },
styles = { ["padding"] = "0.5ex" },
},
 
thin = {
local entry = function(stab, mossa, notes, tipo, pw, acc, pp, gara, exib, inib)
classes = { "roundy-5", "text-center" },
return lib.basicentry(stab, mossa, notes, tipo, pw, acc, pp) ..
styles = { ["font-size"] = "90%", ["padding"] = "0 0.5ex" },
lib.contestentry(gara, exib, inib)
},
end
 
tiny = {
-- Entry per le mosse apprese aumentando di livello
classes = { "roundy-5", "text-center", "text-small" },
styles = { ["padding"] = "0 0.3ex" },
},
}
 
--[[
z.level = function(frame)
local p = lib.sanitize(mw.clone(frame.args))
return table.concat{'|-\n', lib.gameslevel(
p[1] or '—',
p[2] or '—'
),
entry(p[12] or '', p[3] or 'Stramontante', lib.makeNotes(p[11] or ''),
p[4] or 'Sconosciuto', p[5] or '0', p[6] or '0', p[7] or '0',
p[8] or 'Grinta', p[9] or '0', p[10] or '0')}
end
 
Aliases for auto-generated shorthands.
z.Level = z.level
 
Every top-level item relates to the shorthand with the same key, defined below
-- Entry per le mosse appprese tramite MT/MN
in b.shortHands.
 
Every alias has two subtables, one for box shorthands and the other one for
z.tm = function(frame)
the corresponding list shorthand. These can contain an arbitrary number of
local p = lib.sanitize(mw.clone(frame.args))
elements.
return string.interp(table.concat{[=[|-
| style="padding: 0.1em 0.3em;" | <span class="hidden-xs">[[File:${img} ${tipo} Sprite Zaino.png]]</span>[[${p1}|<span style="color:#000;">${p1}</span>]]${games}]=],
entry(p[11] or '', p[2] or 'Fuocobomba', lib.makeNotes(p[10] or ''),
p[3] or 'Sconosciuto', p[4] or '0', p[5] or '0', p[6] or '0',
p[7] or 'Grazia', p[8] or '0', p[9] or '0')},
{
img = string.match(p[1] or 'MT55', '^(M[TN])%d'),
p1 = p[1] or 'MT55',
tipo = p[3] or 'Sconosciuto',
games = abbrLib.concatAbbrs(p[12] or '', s)
})
end
 
--]]
z.Tm = z.tm
local aliases = {
type = {
box = { "boxTipo", "box_tipo" },
list = { "listTipo", "list_tipo" },
},
}
 
--[[
-- Entry per le mosse apprese tramite accoppiamento
 
This function exports the given pair of lua-wikicode interface, taking care of
z.breed = function(frame)
aliasing. Aliases are added for both lua and wikicode intefaces, in the
local p = lib.sanitize(mw.clone(frame.args))
CamelCase and snake_case flavor for the former and CamelCase only for the
return string.interp(table.concat{[=[|-
latter.
| style="padding: 0.1em 0.3em;" | ${fathers}]=],
entry(p[11] or '', p[2] or 'Fulmine', lib.makeNotes(p[10] or '',
abbrLib.concatAbbrs(p[12] or '', s)), p[3] or 'Sconosciuto',
p[4] or '0', p[5] or '0', p[6] or '0', p[7] or 'Classe',
p[8] or '0', p[9] or '0')},
{
fathers = lib.mslistToModal(p[1] or '', '3', nil, 6)
})
end
 
Arguments:
z.Breed = z.breed
- name: the name of the shorthand, as top-level key in aliases.
- suffix: the second-level key in the aliases table, also used as a suffix
for the non-alias exports.
- luaFunction: the lua function to be exported.
- wikicodeFunction: the wikicode companion of luaFunction.
 
--]]
-- Entry per le mosse apprese tramite esperto mosse
local export = function(name, suffix, luaFunction, wikicodeFunction)
suffix = suffix or "box"
local nameAliases = aliases[name] and aliases[name][suffix]
 
-- Aliases-independent names (eg. typeBoxLua)
z.tutor = function(frame)
local pluaNames = lib.sanitize(mw.clone(frame.args)){
return table.concat({lib name, txt.tutorgames{{'RFVF'fu(suffix), p[11]"Lua" }),
table.concat({ name, "_", suffix, "_lua" }),
{'S', p[12]}, {'XD', p[13]}}, ' ', entry(p[10] or '',
}
p[1] or 'Schianto', lib.makeNotes(p[9] or ''),
local wikicodeNames = { name .. txt.fu(suffix), txt.fu(name .. suffix) }
p[2] or 'Sconosciuto', p[3] or '0', p[4] or '0', p[5] or '0',
p[6] or 'Classe', p[7] or '0', p[8] or '0')}
end
 
-- Aliases-dependent names (eg, boxTipoLua)
z.Tutor = z.tutor
if nameAliases then
luaNames = tab.merge(
luaNames,
tab.flatMap(nameAliases, function(alias)
return { alias .. "Lua", alias .. "_lua" }
end)
)
wikicodeNames = tab.merge(
wikicodeNames,
tab.flatMap(nameAliases, function(alias)
return { alias, txt.fu(alias) }
end)
)
end
 
for _, luaName in pairs(luaNames) do
-- Entry per le mosse apprese tramite evoluzioni precedenti
b[luaName] = luaFunction
end
 
for _, wikicodeName in pairs(wikicodeNames) do
z.preevo = function(frame)
b[wikicodeName] = wikicodeFunction
local p = lib.sanitize(mw.clone(frame.args))
end
return table.concat{lib.preevodata(p, '3'), ' ', entry(p[15] or '',
p[7] or 'Scontro', lib.makeNotes(p[16] or ''),
p[8] or 'Sconosciuto', p[9] or '0', p[10] or '0', p[11] or '0',
p[12] or 'Grazia', p[13] or '0', p[14] or '0')}
end
 
--[[
z.Preevo, z.prevo, z.Prevo = z.preevo, z.preevo, z.preevo
 
This function returns the wikicode interface for a given lua one.
-- Entry per le mosse apprese tramite eventi
 
Unlike Wikilib.stdWikicodeInterface, it does not map the empty string to nil:
z.event = function(frame)
in fact, the predefinite styles list can be empty, and it is in such cases
local p = lib.sanitize(mw.clone(frame.args))
that classes and styles are more important. However, with empty string mapped
return string.interp(table.concat{[[|-
to nil, classes and styles wouldn't be unpacked and passed to the lua function,
| style="padding: 0.1em 0.3em;" | ${p1}${p12}]],
meaning that the box would basically be unstyled.
entry(p[11] or '', p[2] or 'Abisso', lib.makeNotes(p[10] or ''),
 
p[3] or 'Sconosciuto', p[4] or '0', p[5] or '0', p[6] or '0',
--]]
p[7] or 'Acume', p[8] or '0', p[9] or '0')},
local makeWikicodeIntreface = function(luaFunction)
{
return function(frame)
p1 = p[1] or 'Evento',
local p = w.trimAll(tab.copy(frame.args), false)
p12 = lib.makeLevel(p[12])
return luaFunction(table.unpack(p))
})
end
end
 
--[[
z.Event = z.event
 
Shorthands are wrapper around the main b.boxLua function. Generally, they
-- Entry per i Pokémon che non imparano mosse aumentando di livello
derive the arguments to the latter from a smaller set of arguments: for
example, a box displaying a type has the same displayed text, link target and
color, that is the name of the type itself.
 
In this table, every element is a function that from arbitrary arguments
z.levelnull = function(frame)
returns the b.boxLua arguments.
return lib.entrynull('level', '9')
end
 
--]]
z.Levelnull = z.levenull
b.shortHands = {
--[[
Box displaying a type. Arguments:
- tipo: The type, defaults to 'Sconosciuto'
- pdfs: Table or space-separated string of predefined
configurations names. Optional, defaults to {}.
- classes: Table/string of CSS classes, in the format parseClasses
and printClasses produce respectively. Optional, defaults to {}.
- styles: Table/string of CSS styles, in the format parseStyles and
printStyles produce respectively. Optional, defaults to {}.
--]]
type = function(tipo, pdfs, classes, styles)
tipo = txt.fu(txt.trim(tipo or "Sconosciuto"))
if type(classes) == "table" then
classes = tab.copy(classes)
table.insert(classes, "box-" .. tipo:lower())
else
classes = table.concat({ classes or "", " box-", tipo:lower() })
end
return tipo, tipo, nil, pdfs, classes, styles, "white-text"
end,
 
--[[
-- Entry per i Pokémon che non imparano mosse tramite MT/MN
Box displaying a damage category. Arguments:
- cat: The category. Defaults to 'Stato'
- pdfs: Table or space-separated string of predefined
configurations names. Optional, defaults to {}.
- classes: Table/string of CSS classes, in the format parseClasses
and printClasses produce respectively. Optional, defaults to {}.
- styles: Table/string of CSS styles, in the format parseStyles and
printStyles produce respectively. Optional, defaults to {}.
--]]
cat = function(cat, pdfs, classes, styles)
cat = txt.fu(txt.trim(cat or "Stato"))
return cat, "Categoria danno#" .. cat, cat, pdfs, classes, styles, "white-text"
end,
 
--[[
z.tmnull = function(frame)
Box displaying an egg group. Arguments:
return lib.entrynull('tm', '10')
- egg: The egg group, without ' (Gruppo Uova)' suffix. Defaults to
end
'Sconosciuto (Gruppo Uova)'
- pdfs: Table or space-separated string of predefined
configurations names. Optional, defaults to {}.
- classes: Table/string of CSS classes, in the format parseClasses
and printClasses produce respectively. Optional, defaults to {}.
- styles: Table/string of CSS styles, in the format parseStyles and
printStyles produce respectively. Optional, defaults to {}.
--]]
egg = function(egg, pdfs, classes, styles)
egg = txt.fu(txt.trim(egg or "Sconosciuto (Gruppo Uova)"))
return egg,
egg .. " (Gruppo Uova)",
egg .. "_uova",
pdfs,
classes,
styles,
"white-text"
end,
}
 
--[[
z.Tmnull = z.tmnull
 
Main function creating a box. Lua interface. Arguments:
-- Entry per i Pokémon che non imparano mosse tramite accoppiamento
 
- text: displayed text.
z.breednull = function(frame)
- link: link target, Defaults to text.
return lib.entrynull('breed', '9')
- color: gradient color, from dark to normal, right-to-left. If nil, doesn't
apply any background (leaving it to classes).
- pdfs: Table or space-separated string of predefined configurations names.
Optional, defaults to {}.
- classes: Table/string of CSS classes, in the format parseClasses and
printClasses produce respectively. Optional, defaults to {}.
- styles: Table/string of CSS styles, in the format parseStyles and
printStyles produce respectively. Optional, defaults to {}.
- textcolor: Text color, defaults to white-text
 
--]]
b.boxLua = function(text, link, color, pdfs, classes, styles, textcolor)
classes, styles = css.classesStyles(predefs, pdfs, classes, styles)
 
return txt.interp(
[=[<div class="${class} ${tc}" style="${bg}; ${style}">[[${link}|${text}]]</div>]=],
{
class = css.printClasses(classes),
bg = color
and css.horizGradLua({ color, "dark", color, "normale" })
or "",
tc = textcolor or "white-text",
link = link or text,
text = text,
style = css.printStyles(styles),
}
)
end
b.box_lua = b.boxLua
 
--[[
z.Breednull = z.breednull
 
Wikicode interface to boxLua. More info (but you won't likely need it if you
-- Entry per i Pokémon che non imparano mosse dall'esperto mosse
read till here ;) ), in the top comment.
 
--]]
z.tutornull = function(frame)
b.box = makeWikicodeIntreface(b.boxLua)
return lib.entrynull('tutor', '12')
b.Box = b.box
end
 
--[[
z.Tutornull = z.tutornull
Generating exports for the shorthands: both lua and wikicode interfaces,
both for list and single boxes.
--]]
for name, makeBoxArgs in pairs(b.shortHands) do
--[[
Lua interface: just calls b.boxLua with wathever the shorthand returns,
given arbitrary arguments.
--]]
local luaFunction = function(...)
return b.boxLua(makeBoxArgs(...))
end
local wikicodeFunction = makeWikicodeIntreface(luaFunction)
 
-- Exporting single box interfaces
-- Entry per i Pokémon che non imparano mosse tramite evoluzioni precedenti
export(name, "box", luaFunction, wikicodeFunction)
 
--[[
z.preevonull = function(frame)
List-of-boxes lua interface: the first argument is a sequence: from
return lib.entrynull('preevo', '9')
each item a box is generted, passing along the resto fo the arguments,
end
that are therefore the same for every item in the sequence.
 
The sequence can be a table of strings or a comma-separated string.
z.Preevonull, z.prevonull, z.Prevonull = z.preevonull, z.preevonull, z.preevonull
--]]
local luaList = function(items, ...)
local args = { ... }
if type(items) == "string" then
items = items == "" and {} or mw.text.split(items, ",%s*")
end
return w.mapAndConcat(items, function(item)
return luaFunction(item, table.unpack(args))
end)
end
local wikicodeList = makeWikicodeIntreface(luaList)
 
-- Exporting list interfaces
export(name, "list", luaList, wikicodeList)
end
 
return zb
46 258

contributi