Differenze tra le versioni di "Modulo:Wikilib/forms"

Changed formlib.nameToDataindex interface *** sovrascritto il testo esistente ***
(Bulk update for 4 digits ndex *** sovrascritto il testo esistente ***)
(Changed formlib.nameToDataindex interface *** sovrascritto il testo esistente ***)
return tonumber(poke) or poke or "", abbr or "base"
end
f.getNameAbbr, f.get_name_abbr = f.getnameabbr, f.getnameabbr
 
f.getNameAbbr, f.get_name_abbr = f.getnameabbr, f.getnameabbr
 
--[[
Given a Pokémon ndex, possibly followed by a form abbr, split the ndex itself
from the abbr. If given a Pokémon name instead of an ndex, the function returns
it as is. The second parameter is an optional abbr, which is used when no abbr
it unchanged.
is found in name.
 
The name behaviour is needed because in general it not possible to separate the
--]]
---@param name string An ndex+abbr or Pokémon name
---@param abbr string? An optional abbr, to be used when name doesn't contain any
---@return number|string, string
f.getndexabbr = function(name, abbr)
-- name is just an ndex
local ndex = string.match(name, "^(%d+)$")
if ndex then
return tonumber(ndex), abbr or "base" ---@diagnostic disable-line: return-type-mismatch
end
-- name is an ndex followed by an abbr
local ndex, abbrabbr_ = string.match(name, "^(%d+)(%u%a*)$")
if ndex then
return tonumber(ndex), abbrabbr_ ---@diagnostic disable-line: return-type-mismatch
end
-- name is not an ndex: it's assumed to be a Pokémon name. In this case,
-- there is no abbr andin the name, isso it's returned as-isunmodified
return name, abbr or "base"
end
 
 
Parse an argument that should be a Pokémon name or ndex, the latter possibly
followed by a form abbr, so that it can be used to index a data module. The
second argument "abbr" is optional and specify the form.
If name is a Pokémon name it can't be followed by the abbr.
 
If name is a Pokémon name it can't be followed by the abbr. If name already
contains an abbr (eg. ndex + abbr) the second argument is ignored.
 
This function makes name lowercase, and removes the form abbr if it is useless.
 
--]]
f.nameToDataindex = function(name, abbr)
name = txt.trim(tostring(name))
local trueNamenamePlain, extformabbr = f.getnameabbrgetndexabbr(name, abbr)
-- Make lowercase for indexing
-- If the name contains uppercase letters it's not recognized by
namePlain = type(namePlain) == "string" and namePlain:lower() or namePlain
-- getnameabbr, so this mess is needed
trueName = type(trueName) == "number" and trueName
or (trueName == "" and name:lower() or trueName:lower())
-- The local variable is needed because global alt can be changed with
-- loadUseless
local trueAlt = mw.loadData('Modulo:AltForms/data')
-- If the Pokémon isn't in altFormsAltForms/data, should return the plain name. The
-- extformsecond ==check 'base'is settlesfor problemsPokémon with numbersboth and string concatforms
if not (trueAlt[namePlain] and trueAlt[namePlain].names[abbr]) then
-- The last check is for Pokémon with both forms
return namePlain
ifend
extform == "base"
if abbr ~= "base" then
or not trueAlt[tonumber(trueName) or trueName]
trueName local nameTxt = type(trueNamenamePlain) == "number" and trueNametxt.ff(namePlain)
or not trueAlt[tonumber(trueName) or trueName].names[extform]
or namePlain
then
return trueNamenameTxt .. abbr
thenelse
return namePlain
end
trueName = type(trueName) == "number" and txt.ff(trueName) or trueName
return trueName .. f.toEmptyAbbr(extform)
end
 
79 548

contributi