Differenze tra le versioni di "Modulo:Evobox"

8 842 byte aggiunti ,  15:02, 21 ago 2018
nessun oggetto della modifica
m
 
eb.strings = {
BOX_CONTAINER = [=[<div class="text-center"><div class="inline-block-md inline-flex flex-row flex-nowrap flex-items-stretch roundy" style="padding: 0.5em; ${background}">${content}</div></div><br style="clear: both;">]=],
BOX_CONTAINER_UNRESPONSIVE = [=[<div class="text-center"><div class="inline-flex flex-row flex-nowrap flex-items-center roundy" style="padding: 0.5em; ${background}">${content}</div></div><br style="clear: both;">]=],
 
ROW_ONE = [=[<div class="vert-middle">${box}</div>]=],
ROW_TWO = [=[<div class="flex-md flex-row flex-nowrap flex-items-center"><div class="width-md-50 vert-middle" style="margin: 0 0.5ex; height: 50%;">${box1}</div><div class="width-md-50 vert-middle" style="margin: 0 0.5ex; height: 50%;">${box2}</div></div>]=],
ROW_THREE = [=[<div><div class="grid" style="border-collapse: separate; border-spacing: 0.5ex 0;">${boxes}</div></div>]=],
 
GRID_ROW = [=[<div><div class="align-middle">${arrow}</div><div class="align-middle">${pokebox}</div></div>]=],
 
BOX_POKEMON = [=[<div class="text-center" style="margin: 0.5ex;">${notes}
<div class="roundy-full inline-block img-fluid" style="padding: 1ex; background: #fff;"><div class="roundy-full" style="padding: 0.5ex; ${background}">[[File:${ndex}.png|150px]]</div></div>
<div class="small-text" style="padding-top: 0.5ex;">${phase}</div>
<div>
<div>[[${name}|<span style="color: #000;">${nameshownName}</span>]]</div>
<div class="small-text hidden-sm">${type1rect}${type2rect}</div>
</div>
</div>]=],
 
BOX_ARROWBOX_ARROW_INFOLESS = [=[${img}<div class="text-small inline-block width-xl-100">${evodesc}</div>${info}<div><span class="hidden-md">${desktoparrow}</span><span class="visible-md">${mobilearrow}</span></div>]=],
BOX_ARROW_UNRESPONSIVE = [=[${img}<div class="text-small inline-block width-xl-100">${evodesc}${info}${timegender}</div><div>${desktoparrow}</div>]=],
BOX_ARROW = [=[${img}<div class="text-small inline-block width-xl-100">${evodesc}${info}${timegender}</div><div><span class="hidden-md">${desktoparrow}</span><span class="visible-md">${mobilearrow}</span></div>]=],
 
SINGLE_ARROW = [=[<div style="margin: 1em 0.5em;">${boxarrow}</div>]=],
DOUBLE_ARROW = [=[<div class="inline-block-md"><div class="flex-md flex-row flex-nowrap flex-items-center" style="margin: 1em 0;"><div class="width-md-50" style="padding: 1em;">${boxarrow1}</div><div class="width-md-50" style="padding: 1em;">${boxarrow2}</div></div></div>]=],
 
ROW_ONE = [=[<div class="vert-middle">${box}</div>]=],
ROW_TWO = [=[<div class="flex-md flex-row flex-nowrap flex-items-center"><div class="width-md-50 vert-middle" style="margin: 0 0.5ex; height: 50%;">${box1}</div><div class="width-md-50 vert-middle" style="margin: 0 0.5ex; height: 50%;">${box2}</div></div>]=],
 
LITTLE_TEXT_NEWLINE = [=[<div class="small-text" >${text}</div>]=],
eb.strings.desktoparrows = {
normal = '&rarr;',
fixed = '&rarr;',
reverse = '&larr;',
double = '&harr;'
eb.strings.mobilearrows = {
normal = '&darr;',
fixed = '&rarr;',
reverse = '&uarr;',
double = '↕'
pokemon = function(param1, param2)
return table.concat{'<div>', ms.staticLua(param2), '</div>'}
end,
other = function(param1, param2)
return ''
end,
baby = boxArrowFunctionGenerator(ms.staticLua('Uovo')),
incenso = boxArrowFunctionGenerator(links.bag('${param1}')),
breedonly = boxArrowFunctionGenerator(ms.staticLua('132')),
formitem = boxArrowFunctionGenerator(links.bag('${param1}'))
}
 
' in [[squadra|<span style="color: #000;">squadra</span>]]'
}
end,
other = function(param1, param2)
return ''
end,
baby = boxArrowFunctionGenerator('[[Accoppiamento Pokémon|<span style="color: #000;">Accoppiamento</span>]]'),
incenso = boxArrowFunctionGenerator('[[Accoppiamento Pokémon|<span style="color: #000;">Accoppiamento</span>]] tenendo [[${param1}]]'),
breedonly = boxArrowFunctionGenerator('[[Accoppiamento Pokémon|<span style="color: #000;">Accoppiamento</span>]] con [[Ditto|<span style="color: #000;">Ditto</span>]]'),
formitem = boxArrowFunctionGenerator('[[${param1}|<span style="color: #000;">${param1}</span>]]')
}
 
types.
 
The parameters are the Pokémon ndex, the evolutionary phase and, the notes. and the
name to be displayed in place of the Pokémon name (optional, defaults to the
Pokémon's name).
 
--]]
eb.BoxPokemonLuaBoxPokemon = function(ndex, phase, notes, shownName)
--local name, abbr = form.getnameabbr(ndex)
local poke = pokes[form.nameToDataindex(ndex)]
 
phase = phase or 'Non si evolve',
name = poke.name,
shownName = shownName or poke.name,
type1rect = links.colorType(poke.type1, c[poke.type1].dark),
type2rect = poke.type2 ~= poke.type1
'normal'
- evotype (livello|felicita|posizione|pietra|mossa|held|scambio|pokémon
|other|baby|incenso|breedonly): states the evolutionary method
- evoinfo (string): additional notes, added as small between parenthesis
- time (string): the time of the day during which evolution can occur
- gender (string): the gender required in order for evolution to occur
- level: the level for evolution
- location: the location where the Pokémon can evolve
 
--]]
eb.BoxArrowLuaBoxArrow = function(args)
args.direction = args.direction
or (args.evotype == 'breedonly' and 'reverse' or 'normal')
or (movedata and movedata.name) or args.held or args.incense
local param2 = (movedata and string.fu(movedata.type)) or args.ms
local info = table.concat{args.evoinfo or '', args.time or '', args.gender or ''}
and table.concat{'<div>', args.evoinfo, '</div>'}
info = info == '' and ''
or string.interp(eb.strings.LITTLE_TEXT_NEWLINE, { or ''
local texttimegender = table.concat{args.time or '(', info,args.gender or ')'}
timegender = timegender == })''
and ''
or table.concat{'<div>(', timegender, ')</div>'}
 
local interpData = {
return string.interp(eb.strings.BOX_ARROW, {
img = eb.strings.boxArrowImg[args.evotype](param1, param2),
evodesc = eb.strings.boxArrowEvodesc[args.evotype](param1, param2),
info = info,
timegender = timegender,
desktoparrow = eb.strings.desktoparrows[args.direction],
mobilearrow = eb.strings.mobilearrows[args.direction]
})
local interpString = eb.strings.BOX_ARROW
 
if interpData.evodesc == ''
and interpData.info == ''
and interpData.timegender == '' then
interpString = eb.strings.BOX_ARROW_INFOLESS
elseif interpData.direction == 'fixed' then
interpString = eb.strings.BOX_ARROW_UNRESPONSIVE
end
return string.interp(interpString, interpData)
end
 
 
--]]
eb.SingleArrowLuaSingleArrow = function(args)
return string.interp(eb.strings.SINGLE_ARROW, {boxarrow = eb.BoxArrowLuaBoxArrow(args)})
end
 
- evotype (livello|felicita|posizione|pietra|mossa|held|scambio|pokémon
|baby|incenso|breedonly): states the evolutionary method
- evoinfo (string): additional notes, added as small between parenthesis
- time (string): the time of the day during which evolution can occur
- gender (string): the gender required in order for evolution to occur
- level: the level for evolution
- location: the location where the Pokémon can evolve
 
--]]
eb.DoubleArrowLuaDoubleArrow = function(args)
args.direction = 'normal'
local args2 = {
}
return string.interp(eb.strings.DOUBLE_ARROW, {
boxarrow1 = eb.BoxArrowLuaBoxArrow(args),
boxarrow2 = eb.BoxArrowLuaBoxArrow(args2),
})
end
those args whose keys ended with the passed ending. This ending is removed in
the keys of the result.
 
Adds also 'evotype' .. ending .. 'info' to the result with key 'evoinfo'.
 
--]]
end
end
newArgs.evoinfo = args['evotype' .. ending .. 'info']
return newArgs
end
 
--[[
 
Prints two rows, one with arrows and the other with Pokémon boxes.
 
The first parameter is a table that should contain all the values about the
phase, that are the ones about the evolutionary method with numer 'phase' - 1
and the ones about the Pokémons with number 'phase' . In fact, the first
parameter may be the frame.args processed. The second parameter is a number
that specify the phase to print. The phase should be the one of the Pokémon,
non of the evolutionary method.
 
This function only handles standard evolutions, maybe branched. It DOES NOT
handle baby/incense level evolutions with a couple of arrows or strange things
like that.
 
--]]
eb.makePhaseRows = function(p, phase)
local result = {}
local evotypePhase = tostring(phase - 1)
if p['evotype' .. evotypePhase] then
-- There is at least one evolution
if p['evotype' .. evotypePhase .. 'a'] then
-- There are two evolutions
table.insert(result, string.interp(eb.strings.ROW_TWO, {
box1 = eb.SingleArrow(argsEndingSubset(p, evotypePhase)),
box2 = eb.SingleArrow(argsEndingSubset(p, evotypePhase .. 'a'))
}))
table.insert(result, string.interp(eb.strings.ROW_TWO, {
box1 = eb.BoxPokemon(
p['sprite' .. tostring(phase)],
phaseName(phase, p.family),
p['form' .. tostring(phase)]
),
box2 = eb.BoxPokemon(
p['sprite' .. tostring(phase) .. 'a'],
phaseName(phase, p.family),
p['form' .. tostring(phase) .. 'a']
),
}))
else
-- There's only one evolution
table.insert(result, string.interp(eb.strings.ROW_ONE, {
box = eb.SingleArrow(argsEndingSubset(p, evotypePhase)),
}))
table.insert(result, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxPokemon(
p['sprite' .. tostring(phase)],
phaseName(phase, p.family),
p['form' .. tostring(phase)]
)
}))
end
end
 
return table.concat(result)
end
 
--[[
 
Creates the row for more than 2 evolutions, that doesn't switch to vertical
layout on small screen.
 
The first parameter is a table that should contain all the values about the
phases, that are the ones about the evolutionary method and the ones about the
Pokémons. In fact, the first parameter may be the frame.args processed.
 
--]]
eb.makeManyEvosRow = function(p)
local rowContent = {}
-- Creates the alphabet, starting with empty string
local letters = { '' }
for ascii = 97, 122 do
table.insert(letters, string.char(ascii))
end
 
rowContent = table.map(letters, function(letter)
if p['sprite2' .. letter] then
local arrowArgs = argsEndingSubset(p, '1' .. letter)
arrowArgs.direction = 'fixed'
return string.interp(eb.strings.GRID_ROW, {
arrow = eb.SingleArrow(arrowArgs),
pokebox = eb.BoxPokemon(
p['sprite2' .. letter],
phaseName(2, 'normale'),
p['form2' .. letter]
)
})
else
return ''
end
end)
 
return string.interp(eb.strings.ROW_THREE, {
boxes = table.concat(rowContent)
})
end
 
 
eb.processInput = {}
 
This table holds the list of keys whose values should be mapped to lowercase
in the arguments of Evobox. Not all the keys should be lowered becausbecause some
arguments are case sensitive.
 
 
--]]
eb.processInput.mapToLower = { 'family', 'evotype%dad%a?', 'move%dad%a?', 'type%d' }
 
--[[
--[[
 
Processes an argument,: mappingmaps to lowercase thosewhen thatneeded needand it andparses parsingevotypes.
evotypes
 
--]]
eb.processInput.processprocessElement = function(v, k)
if type(k) == 'string' and table.any(eb.processInput.mapToLower, function(pattern)
return string.match(k, '^' .. pattern .. '$')
end) then
v = string.lower(v)
 
return v
end
 
--[[
 
Processes the entire arguments table: moves keys 'evotypeNinfo' to 'evoinfoN'.
This function modifies the table in place, and returns a reference to the table
itself.
 
--]]
eb.processInput.processTable = function(args)
for k, v in pairs(args) do
local num = type(k) == 'string' and string.match(k, 'evotype(%d%a?)info')
if num then
args['evoinfo' .. num] = v
end
end
return args
end
 
 
Parameters are named because of their number:
- pagename or 1: the page name, as returned by {{PAGENAME}}
- family (nessuna|normale|baby|incenso|breedonly): the kind of family.
Defaults to 'nessuna', that means no evolutions. 'normale' means an
'breedonly' means that there is a Pokémon that can be born by breeding
but doesn't evolve back in the parent Pokémon (only Phione and Manaphy)
- incense: the incese used to breed the baby form
- spriteN: the ndex of the N-th Pokémon (or form) to display
- formN: notes about the N-th Pokémon, put above the sprite
- evotypeNa: the evolutionary method from N-th to the second (N+1)-th
Pokémon, if any
- any parameterN-ed paired with evotypeNparameter, but with ana trailing "a" appended(for instance: 'evotypeNa'):
- incense: the incesesame usedinformation toof breedun-a-ed parameter, but for the babysecond formN-th
form (if any)
- any parameter paired with N = 1, but with a trailing letter. Following
alphabetical order, those parameters specify details of other first
evolutions (if any). It is possible not to use all the letters
sequentially (for instance: only sprite1, sprite1c and sprite1e) but I
STRONGLY ADVISE NOT TO.
--]]
eb.Evobox = function(frame)
local p = w.trimAll(mw.clone(frame.args))
local p = eb.processInput.processTable(table.map(p, eb.processInput.processprocessElement))
 
local pagename = string.fl(p.pagename or p[1] or mw.title.getCurrentTitle())
p[1] = nil
p.family = p.family or 'nessuna'
or {name = 'Sconosciuto', ndex = 0, type1 = 'sconosciuto', type2 = 'sconosciuto'}
 
local evoboxevoboxcontent = {}
local boxContainer = eb.strings.BOX_CONTAINER
table.insert(evobox, string.interp('<div class="text-center"><div class="inline-block-md inline-flex flex-row flex-nowrap flex-items-stretch roundy text-center" style="padding: 0.5em; ${background}>', {
background = css.horizGradLua{ type1 = pagepoke.type1, type2 = pagepoke.type2 }
}))
 
-- Insert the first phase Pokémon box
table.insert(evoboxevoboxcontent, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxPokemonLuaBoxPokemon(p.sprite1, phaseName(1, p.family), p.form1)
}))
 
-- If there are more than 2 phase one evolutions the module assumes there
-- Insert -the death- the first arrow box
-- aren't higher level evolutions and uses the unresponsive layout
if p.evotype1 then
if p.sprite2b then
-- There is at least one evolution
boxContainer = eb.strings.BOX_CONTAINER_UNRESPONSIVE
table.insert(evoboxcontent, eb.makeManyEvosRow(p))
-- If the family is 'baby' or 'incenso' the second phase shouldbe handled
-- "by hand", otherwise there's the function that creates the row.
elseif p.family == 'baby' or p.family == 'incenso' then
-- There is one phase one evolution, but with double arrow
local firstArrowArgs = argsEndingSubset(p, '1')
iffirstArrowArgs.evotype2 = p.evotype1a thenfamily
firstArrowArgs.incense = p.incense
-- There are two phase one evolutions
table.insert(evoboxevoboxcontent, string.interp(eb.strings.ROW_TWOROW_ONE, {
box1box = eb.SingleArrowLuaDoubleArrow(firstArrowArgs),
}))
box2 = eb.SingleArrowLua(argsEndingSubset(p, '1a'))
table.insert(evoboxcontent, string.interp(eb.strings.ROW_ONE, {
}))
tablebox = eb.insertBoxPokemon(evoboxp.sprite2, string.interpphaseName(eb.strings2, p.ROW_TWOfamily), {p.form2)
}))
box1 = eb.BoxPokemonLua(p.sprite2, phaseName(2, p.family), p.form2),
else
box2 = eb.BoxPokemonLua(p.sprite2a, phaseName(2, p.family), p.form2a),
table.insert(evoboxcontent, eb.makePhaseRows(p, 2))
}))
elseif p.family == 'baby' or p.family == 'incenso' then
-- There is one phase one evolution, but with double arrow
firstArrowArgs.evotype2 = p.family
firstArrowArgs.incense = p.incense
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.DoubleArrowLua(firstArrowArgs)
}))
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxPokemonLua(p.sprite2, phaseName(2, p.family), p.form2)
}))
else
-- There is one phase one evolution, with single arrow
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.SingleArrowLua(firstArrowArgs)
}))
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxPokemonLua(p.sprite2, phaseName(2, p.family), p.form2)
}))
end
end
-- This if should be nested inside the previous one, but I'm not doing it
-- in order to avoid excessive indentation
if p.evotype2 then
-- There is at least one phase two evolution
if p.evotype2a then
-- There are two phase two evolutions
table.insert(evobox, string.interp(eb.strings.ROW_TWO, {
box1 = eb.SingleArrowLua(argsEndingSubset(p, '2')),
box2 = eb.SingleArrowLua(argsEndingSubset(p, '2a'))
}))
table.insert(evobox, string.interp(eb.strings.ROW_TWO, {
box1 = eb.BoxPokemonLua(p.sprite3, phaseName(3, p.family), p.form3),
box2 = eb.BoxPokemonLua(p.sprite3a, phaseName(3, p.family), p.form3a),
}))
else
-- At this level there can't be double arrows
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.SingleArrowLua(argsEndingSubset(p, '2'))
}))
table.insert(evobox, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxPokemonLua(p.sprite3, phaseName(3, p.family), p.form3)
}))
end
end
table.insert(evoboxcontent, eb.makePhaseRows(p, 3))
 
table.insert(local evobox, '</div></div>')= {
string.interp(boxContainer, {
background = css.horizGradLua{ type1 = pagepoke.type1, type2 = pagepoke.type2 },
content = table.concat(evoboxcontent)
})
}
 
-- Adds the categories
if p.evotype2 then
table.insert(evobox, '[[Categoria:Pokémon appartenenentiappartenenti a una linea di evoluzione a tre stadi]]')
elseif p.evotype1 then
table.insert(evobox, '[[Categoria:Pokémon appartenenentiappartenenti a una linea di evoluzione a due stadi]]')
else
table.insert(evobox, '[[Categoria:Pokémon che non fanno parte di una linea di evoluzione]]')
return table.concat(evobox)
end
 
eb.evobox = eb.Evobox
 
 
 
-- ============================== Alternate forms box =========================
 
--[[
 
Returns the box of a single Pokémon form given its ndex with abbr. Notes may be
added using the second parameter.
 
--]]
eb.BoxForm = function(ndex, notes)
local name, abbr = form.getnameabbr(ndex)
local altdata = forms[name]
return eb.BoxPokemon(ndex, '', notes, altdata.names[abbr])
end
 
--[[
 
Returns a single form arrow.
 
Parameters are named to make easier a possible future extension that exploits
the whole interface of the underlying eb.BoxArrow:
- item: the name of the item required to change form
- evoinfo: additional notes
 
--]]
eb.FormArrow = function(args)
args.evotype = args.item and 'formitem' or 'other'
args.held = args.item
args.direction = 'double'
return string.interp(eb.strings.SINGLE_ARROW, {boxarrow = eb.BoxArrow(args)})
end
 
--[[
 
Prints two rows, one with arrows and the other with form boxes.
 
The first parameter is a table that should contain all the values about the
row, that are the ones about the form change method with numer 'index' - 1
and the ones about the form with number 'index'. In fact, the first parameter
may be the frame.args processed. The second parameter is a number that specify
the row to print. The row should be the one of the form, non of the form change
method.
 
--]]
eb.makeFormRows = function(p, index)
local result = {}
local evotypeIdx = tostring(index - 1)
if p['sprite' .. tostring(index)] then
-- There is at least one evolution
if p['sprite' .. tostring(index) .. 'a'] then
-- There are two evolutions
table.insert(result, string.interp(eb.strings.ROW_TWO, {
box1 = eb.FormArrow(argsEndingSubset(p, evotypeIdx)),
box2 = eb.FormArrow(argsEndingSubset(p, evotypeIdx .. 'a'))
}))
table.insert(result, string.interp(eb.strings.ROW_TWO, {
box1 = eb.BoxForm(
p['sprite' .. tostring(index)],
p['loc' .. tostring(index)]
),
box2 = eb.BoxForm(
p['sprite' .. tostring(index) .. 'a'],
p['loc' .. tostring(index) .. 'a']
),
}))
else
-- There's only one evolution
table.insert(result, string.interp(eb.strings.ROW_ONE, {
box = eb.FormArrow(argsEndingSubset(p, evotypeIdx)),
}))
table.insert(result, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxForm(
p['sprite' .. tostring(index)],
p['loc' .. tostring(index)]
)
}))
end
end
 
return table.concat(result)
end
 
--[[
 
Wikicode interface function to create a box for alternatives forms
transformation methods.
 
Parameters are named because of their number:
- 1: the page name, as returned by {{PAGENAME}}. This parameter is used
only to determine the colors of the background gradient.
- spriteN: the ndex of the N-th form
- locN: any additional note for the N-th form
- itemN: the item needed to change from N-th to (N+1)-th form
- evoinfoN: any additional info for form change from N-th to (N+1)-th
- any N-ed parameter, but with an "a" appended (for instance spriteNa): the
same information, but for the second N-th form (if any)
--]]
eb.Formbox = function(frame)
local p = w.trimAll(mw.clone(frame.args))
 
local pagename = string.fl(p[1] or mw.title.getCurrentTitle())
p[1] = nil
p.family = p.family or 'nessuna'
local pagepoke = pokes[form.nameToDataindex(pagename)]
or {name = 'Sconosciuto', ndex = 0, type1 = 'sconosciuto', type2 = 'sconosciuto'}
 
local formboxcontent = {}
 
-- Insert the first phase Pokémon box
table.insert(formboxcontent, string.interp(eb.strings.ROW_ONE, {
box = eb.BoxForm(p.sprite1, p.loc1)
}))
 
-- Adds any form passed as argument
local i = 2
while p['sprite' .. tostring(i)] do
table.insert(formboxcontent, eb.makeFormRows(p, i))
i = i + 1
end
 
return string.interp(eb.strings.BOX_CONTAINER, {
background = css.horizGradLua{ type1 = pagepoke.type1, type2 = pagepoke.type2 },
content = table.concat(formboxcontent)
})
end
 
eb.formbox = eb.Formbox
 
return eb