Differenze tra le versioni di "Modulo:PokémonInfo/BoxAbil"

Added event abilities
(Bugfix per Pikachu Cosplay *** sovrascritto il testo esistente ***)
(Added event abilities)
-- BoxAbilities dellebox abilitàfor per iltemplate PokémonInfo
 
local bj = {}
 
local l = require('Modulo:Links')
local w = require('Modulo:Wikilib')
local abillib = require('Modulo:Wikilib/abils')
local oop = require('Modulo:Wikilib/oop')
local list = require('Modulo:Wikilib/lists')
local txt = require('Modulo:Wikilib/strings') -- luacheck: no unused
local tab = require('Modulo:Wikilib/tables') -- luacheck: no unused
local abils = require('Modulo:PokéAbil/data')
local c = mw.loadData('Modulo:Colore/data')
 
-- Table holding Pikachu forms to be ignored
-- !!! ATTENZIONE !!!
local ignorableForms = {'pikachuR', 'pikachuD', 'pikachuCn', 'pikachuS',
--- Questo modulo modifica le copie cachate degli altri moduli dati
'pikachuW'}
local gre = require('Modulo:GreninjaDemo/data')
 
-- Table contenente le forme di Pikachu da ignorare
local ignorableForms = {'pikachuR', 'pikachuD',
'pikachuCn', 'pikachuS', 'pikachuW'}
 
--[[
 
This class represents a cell of the abilities box and contains information
Questa classe rappresenta una casella
about the abilities and the forms that share the same abilities combination.
del box delle abilità del PokémonInfo,
mantenendo informazioni sulle combinazioni
di abilità e sulle forme che le hanno.
 
--]]
--[[
 
Constructor: takes the name of the Pokémon, and an optionally extended name of
Costruttore della classe: ha in ingresso il
the form. The name is given in the form name/ndex + abbreviation,
nome del Pokémon, nella forma nome/ndex + sigla,
e, opzionalmente, il nome esteso della forma
 
--]]
AbilsBox.new = function(name, formName)
 
-- Meowstic e -- Pokémon conwhose ability abilitàis nonyet rivelataunknown
if abils[name].ability1 == '' then
return nil
end
 
-- Pikachu (@nalkio visto che questo Pokémon fa danni?)
if table.search(ignorableForms, name) then
return nil
end
 
local this = AbilsBox.super.new(formName)
 
this = table.merge(abillib.lastAbils(abils[name]), this)
 
return setmetatable(this, AbilsBox)
end
 
AbilsBox.__eq = function(a, b)
return a.ability1 == b.ability1
and a.ability2 == b.ability2
and a.abilityd == b.abilityd
and a.abilitye == b.abilitye
end
 
--[[
 
Wikicode for an abilities box cell: the standard abilities are on the left,
Wikicode per una cella del box delle abilità:
and the hidden one is on the right. The event ability takes the place of the
le abilità standard sono a sinistra, quella
hidden ability when there is none, otherwise it sits below. The form names
nascosta a destra, e le forme sopra.
are added at the top, if present.
 
--]]
AbilsBox.__tostring = function(this)
local stdAbils = l.aColor(this.ability1)
if this.ability2 then
stdAbils = table.concat({stdAbils, 'o',
l.aColor(this.ability2)}, ' ')
end
 
local hiddenAbil = ''
if this.abilityd then
hiddenAbil = table.concat{'<div class="width-xl-50">',
l.aColor(this.abilityd), '<div class="small-text">Abilit&agrave; nascosta</div></div>'}
end
 
local eventAbil = ''
return string.interp('<div class="flex flex-row flex-wrap flex-main-stretch flex-items-center width-xl-${boxWidth}" style="box-sizing: border-box; padding: 0.2em;">${forms}<div class="width-xl-${stdWidth}">${stdAbils}</div>${hiddenAbil}</div>',
if this.abilitye then
{
eventAbil = string.interp('<div class="width-xl-${width}">${abil}<div class="small-text">Abilit&agrave; evento</div></div>',
boxWidth = this.abilityd and '100' or '50',
{
stdWidth = this.abilityd and '50' or '100',
forms width = #this.labels < 1abilityd and '100' or table.concat{'50',
abil = l.aColor(this.abilitye)
'<div class="small-text width-xl-100" style="padding-bottom: 0.2em;">',
})
mw.text.listToText(this.labels, ', ', ' e '),
end
'</div>'
 
},
return string.interp('<div class="flex flex-row flex-wrap flex-main-stretch flex-items-center width-xl-${boxWidth}100" style="box-sizing: border-box; padding: 0.2em;">${forms}<div class="width-xl-${stdWidth}">${stdAbils}</div>${hiddenAbil}${eventAbil}</div>',
stdAbils = stdAbils,
{
hiddenAbil = hiddenAbil
boxWidth stdWidth = (this.abilityd or this.abilitye) and '10050' or '50100',
})
forms = #this.labels < 1 and '' or table.concat{
'<div class="small-text width-xl-100" style="padding-bottom: 0.2em;">',
mw.text.listToText(this.labels, ', ', ' e '),
'</div>'
},
stdAbils = stdAbils,
hiddenAbil = hiddenAbil,
eventAbil = eventAbil
})
end
 
-- HTML code for the forms cells
--[[
 
Stampa in HTML una table di AbilBoxes:
ogni forma ha una cella, che può
affiancarsi a quella di un'altra forma
in assenza di abilità nascosta.
 
--]]
local printBoxes = function(boxes)
local acc = table.map(boxes, tostring)
table.insert(acc, 1, '<div class="flex flex-row flex-wrap flex-main-stretch flex-items-center roundy text-center" style="background: #FFF; padding: 0.2em;">')
table.insert(acc, '</div>')
return table.concat(acc)
end
 
--[[
 
DatoGiven il nome di una Pokémon oname, ilor suoits ndex, returns the HTML code for the template
PokémonInfo abilities box. Every combination of abilities has its own cell,
ritorna il box delle abilità, con una
with the forms that have if displayed above.
cella per ogni diversa configurazione di
abilità delle forme alternative, con
sotto i nomi delle forme che la hanno.
 
--]]
bj.boxAbil = function(frame)
local name = string.trim(frame.args[1] or '')
name = string.parseInt(name) or mw.text.decode(name):lower()
 
return list.makeFormsLabelledBoxes({
name = name,
makeBox = AbilsBox.new,
printBoxes = printBoxes
})
end
 
bj.BoxAbil, bj.box_abil, bj.Box_abil = bj.boxAbil, bj.boxAbil, bj.boxAbil
 
return bj