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

Vai alla navigazione Vai alla ricerca
m
Annullate le modifiche di F3Bot (discussione), riportata alla versione precedente di Ff300
(Added multigen to Poké-data *** sovrascritto il testo esistente ***)
m (Annullate le modifiche di F3Bot (discussione), riportata alla versione precedente di Ff300)
--[[
 
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 formlibform = require('Modulo:Wikilib/forms')
local data
local multigen = require('Modulo:Wikilib/multigen')
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)
pokesdata = loadData(pokesdata, 'Poké-/data')
return string.tf(pokesdata[formlibstring.nameToDataindextrim(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)
pokesdata = loadData(pokesdata, 'Poké-/data')
returnlocal pokes[formlibndex = string.nameToDataindextrim(frame.args[1] or '')].name
return data[tonumber(ndex) or ndex].name
end
 
--[[
 
Return the form name given ndex with abbr. If the abbrndex doesn'tis havewithout a formabbr, namereturns
the Pokémon name even if it hasn't got alternate forms.
(or there's no abbr at all) it returns an empty string.
 
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 = formlib.allFormsDataloadData(forms, 'AltForms/data')
local name, abbr = formlibform.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.
or ndex. The optional third parameter is the generation.
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 abils[form.nameToDataindex(name)]['ability' .. abilityNumber]
return multigen.getGenValue(
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', frame.args.gen'1')
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', frame.args.gen'2')
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', frame.args.gen'd')
end
 
 
Returns a Pokémon's type (specified by the second parameter) given its name or
ndex.
ndex. The optional third parameter is the generation.
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)
pokesdata = loadData(pokesdata, 'Poké-/data')
return string.fu(multigendata[form.getGenValuenameToDataindex(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', frame.args.gen'1')
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', frame.args.gen'2')
end
 
 
--]]
 
b.ifTwoTypes = function(frame)
pokesdata = loadData(pokesdata, 'Poké-/data')
local poke = pokesdata[formlibform.nameToDataindex(frame.args[1])]
local isDualType = poke.type1 == poke.type2
return isDualType and string.trim(frame.args[2]) or string.trim(frame.args[3])
--[[
 
Frontend for wikilib/forms.getlink: returns the link to an'alternate form from
Returns the link to an alternative form. The Pokémon name (first parameter) can
module AltForms/data or UselessForms/data. The Pokémon name (first argument)
be both a name or a ndex followed by the abbr, the second argument is a flag
may be both a name or a ndex followed by the abbr, the second argument is a
to get black or normal link.
flag to get black or normal link.
The ndex may be the base form's one. If the ndex doesn't correspond to a
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])
local link = form.getLink(name, black)
-- Links also to UselessForms
if link ~= '' then
formlib.loadUseless(true)
return link
return formlib.getLink(name, black)
else
form.loadUseless(false)
return form.getLink(name, black)
end
end
 

Menu di navigazione