Differenze tra le versioni di "Modulo:PokémonData"

Preparing for multigen in Poké/data *** sovrascritto il testo esistente ***
m (Annullate le modifiche di F3Bot (discussione), riportata alla versione precedente di Ff300)
(Preparing for multigen in Poké/data *** sovrascritto il testo esistente ***)
--[[
 
Module used as a frontend to wikicode for data modules.
 
Each interface function is documented in its own comment, with examples.
 
--]]
 
local txt = require('Modulo:Wikilib/strings') -- luacheck: no unused
local formformlib = require('Modulo:Wikilib/forms')
local multigen = require('Modulo:Wikilib/multigen')
local data
local pokes
local abils
local forms
if not tab then
local loadFunction = useRequire and require or mw.loadData
return loadFunction(moduleName) --loadFunction('Modulo:' .. moduleName)
end
return tab
 
 
--[[
-- Returns ndex given the name
 
Returns ndex given the name.
 
--]]
 
b.getNdex = function(frame)
datapokes = loadData(datapokes, 'Poké/-data')
return string.tf(datapokes[stringformlib.trimnameToDataindex(frame.args[1] or '')].ndex)
end
 
b.get_ndex = b.getNdex
 
--[[
-- Returns the name given ndex
 
Returns the name given ndex. The argument can be an alternative forms' ndex.
 
Ex:
{{#invoke: PokémonData | getNdex | 398 }} --> Staraptor
{{#invoke: PokémonData | getNdex | 65 }} --> Alakazam
{{#invoke: PokémonData | getNdex | 487O }} --> Giratina
 
--]]
 
b.getName = function(frame)
datapokes = loadData(datapokes, 'Poké/-data')
localreturn ndex = stringpokes[formlib.trimnameToDataindex(frame.args[1] or '')].name
return data[tonumber(ndex) or ndex].name
end
 
--[[
 
Return the form name given ndex with abbr. If the ndexabbr isdoesn't withouthave abbr,a form returnsname
(or there's no abbr at all) it returns an empty string.
the Pokémon name even if it hasn't got alternate forms.
 
Ex:
{{#invoke: PokémonData | getFormName | 800A }} --> Ali dell'Aurora
{{#invoke: PokémonData | getFormName | 422E }} --> Mare Est
{{#invoke: PokémonData | getFormName | 422 }} --> Mare Ovest
{{#invoke: PokémonData | getFormName | 28 }} --> (empty string)
 
--]]
 
b.getFormName = function(frame)
forms = loadDataformlib.allFormsData(forms, 'AltForms/data')
local name, abbr = formformlib.getnameabbr(string.trim(frame.args[1]))
return forms[name] and forms[name].names[formlib.toBase(abbr)] or b.getName{args={name}}''
end
 
 
Returns a Pokémon's ability (specified by the second parameter) given its name
or ndex. The optional third parameter is the generation.
or ndex.
The name can contain a form abbreviation, and if it's a Pokémon name (not an
ndex) it should be lowercase but the first letter, that can be both upper or
--]]
 
local getAbil = function(name, abilityNumber, gen)
abils = loadData(abils, 'PokéAbil/-data')
return multigen.getGenValue(
return abils[form.nameToDataindex(name)]['ability' .. abilityNumber]
abils[formlib.nameToDataindex(name)]['ability' .. abilityNumber] or '',
tonumber(gen)
)
end
 
--[[
-- Returns a Pokémon's first ability given its name or ndex
 
Returns a Pokémon's first ability given its name or ndex. An optional 'gen'
parameter specifies the generation.
 
Ex:
{{#invoke: PokémonData | getAbil1 | 065 }} --> Sincronismo
{{#invoke: PokémonData | getAbil1 | 487O }} --> Levitazione
{{#invoke: PokémonData | getAbil1 | 094 | gen = 5 }} --> Levitazione
 
--]]
 
b.getAbil1 = function(frame)
return getAbil(frame.args[1] or, '1', '1'frame.args.gen)
end
 
b.get_abil_1 = b.getAbil1
 
--[[
-- Returns a Pokémon's second ability given its name or ndex
 
Returns a Pokémon's second ability given its name or ndex. If the Pokémon
has no second ability, it returns an empty string. An optional 'gen'
parameter specifies the generation.
 
Ex:
{{#invoke: PokémonData | getAbil2 | 65 }} --> Forza Interiore
{{#invoke: PokémonData | getAbil2 | 398 }} --> (empty string)
 
--]]
 
b.getAbil2 = function(frame)
return getAbil(frame.args[1] or, '2', '2'frame.args.gen)
end
 
b.get_abil_2 = b.getAbil2
 
--[[
-- Returns a Pokémon's hidden ability given its name or ndex
 
Returns a Pokémon's hidden ability given its name or ndex. If the Pokémon
has no second ability, it returns an empty string. An optional 'gen'
parameter specifies the generation.
 
Ex:
{{#invoke: PokémonData | getAbild | 65 }} --> Magicscudo
{{#invoke: PokémonData | getAbild | 487O }} --> (empty string)
 
--]]
 
b.getAbild = function(frame)
return getAbil(frame.args[1] or, 'd', 'd'frame.args.gen)
end
 
 
Returns a Pokémon's type (specified by the second parameter) given its name or
ndex. The optional third parameter is the generation.
ndex.
The name can contain a form abbreviation, and if it's a Pokémon name (not an
ndex) it should be lowercase but the first letter, that can be both upper or
--]]
 
local getType = function(name, typeNumber, gen)
datapokes = loadData(datapokes, 'Poké/-data')
return string.fu(data[formmultigen.nameToDataindexgetGenValue(name)]['type' .. typeNumber])
pokes[formlib.nameToDataindex(name)]['type' .. typeNumber],
tonumber(gen)
))
end
 
--[[
-- Returns a Pokémon's first type given its name or ndex
 
Returns a Pokémon's first type given its name or ndex. An optional 'gen'
parameter specifies the generation.
 
Ex:
{{#invoke: PokémonData | getType1 | 398 }} --> Normale
{{#invoke: PokémonData | getType1 | 493Fu }} --> Fuoco
 
--]]
 
b.getType1 = function(frame)
return getType(frame.args[1] or, '1', '1'frame.args.gen)
end
 
b.get_type_1 = b.getType1
 
--[[
-- Returns a Pokémon's second type given its name or ndex. If the Pokémon has
 
-- only one type, it returns the first type instead
Returns a Pokémon's second type given its name or ndex. If the Pokémon has
only one type, it returns the first type instead. An optional 'gen' parameter
specifies the generation.
 
Ex:
{{#invoke: PokémonData | getType2 | 398 }} --> Volante
{{#invoke: PokémonData | getType2 | 65 }} --> Psico
{{#invoke: PokémonData | getType2 | 479L }} --> Acqua
{{#invoke: PokémonData | getType2 | 082 | gen = 1 }} --> Elettro
 
--]]
 
b.getType2 = function(frame)
return getType(frame.args[1] or, '2', '2'frame.args.gen)
end
 
 
--]]
 
b.ifTwoTypes = function(frame)
datapokes = loadData(datapokes, 'Poké/-data')
local poke = datapokes[formformlib.nameToDataindex(frame.args[1])]
local isDualType = poke.type1 == poke.type2
return isDualType and string.trim(frame.args[2]) or string.trim(frame.args[3])
--[[
 
Returns the link to an alternative form. The Pokémon name (first parameter) can
Frontend for wikilib/forms.getlink: returns the link to an'alternate form from
be both a name or a ndex followed by the abbr, the second argument is a flag
module AltForms/data or UselessForms/data. The Pokémon name (first argument)
to get black or normal link.
may be both a name or a ndex followed by the abbr, the second argument is a
The ndex may be the base form's one. If the ndex doesn't correspond to a
flag to get black or normal link.
Pokémon with alternative forms, it returns an empty string.
 
Ex:
{{#invoke: PokémonData | getLink | 487 }}
{{#invoke: PokémonData | getLink | 487O }}
{{#invoke: PokémonData | getLink | 028A }}
{{#invoke: PokémonData | getLink | 028 }}
{{#invoke: PokémonData | getLink | 774R }}
{{#invoke: PokémonData | getLink | 398 }}
 
--]]
b.getLink = function(frame)
local name, black = string.trim(frame.args[1]), string.trim(frame.args[2])
-- Links also to UselessForms
local link = form.getLink(name, black)
formlib.loadUseless(true)
if link ~= '' then
return formlib.getLink(name, black)
return link
else
form.loadUseless(false)
return form.getLink(name, black)
end
end
 
79 547

contributi