79 548
contributi
(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
--[[
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
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,
if ndex then
return tonumber(ndex),
end
-- name is not an ndex: it's assumed to be a Pokémon name. In this case,
-- there is no abbr
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
-- Make lowercase for indexing
namePlain = type(namePlain) == "string" and namePlain:lower() or namePlain
trueName = type(trueName) == "number" and trueName▼
-- 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
--
if not (trueAlt[namePlain] and trueAlt[namePlain].names[abbr]) then
return namePlain
if abbr ~= "base" then
or namePlain
then▼
return
return namePlain
end
end
|