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

Adding code to check how much crying before a breaking change *** sovrascritto il testo esistente ***
(Adding plain links to PokémonData *** sovrascritto il testo esistente ***)
(Adding code to check how much crying before a breaking change *** sovrascritto il testo esistente ***)
 
local f = {}
 
local tab = require('Modulo:Wikilib/tables') -- luacheck: no unused
-- stylua: ignore start
local txt = require('Modulo:Wikilib/strings') -- luacheck: no unused
local tab = require('Modulo:Wikilib/tables') -- luacheck: no unused
local txt = require('Modulo:Wikilib/strings') -- luacheck: no unused
local genUtil = require('Modulo:Wikilib/gens')
local alt = mw.loadData('Modulo:AltForms/data')
-- stylua: ignore end
 
-- Boolean used to avoid double loading of useless forms
end
 
local all = tabletab.copy(alt)
local useless = mw.loadData('Modulo:UselessForms/data')
local both = mw.loadData('Modulo:BothForms/data')
--[[
 
Estrae la sigla della forma alternativa dal nome del Pokémon così come è negli
indici delle tabelle dati o negli ndex dei Mini Sprite, oppure a partire dal
nome del Pokémon così come è negli indici
nome del Pokémon e quello esteso della forma alternativa. In caso di
delle tabelle dati o negli ndex dei Mini
caso di fallimento, ritorna la stringa vuota.
Sprite, oppure a partire dal nome del Pokémon
 
e quello esteso della forma alternativa. In
DEPRECATION NOTICE: this function is deprecated. Use getnameabbr or getndexabbr
caso di fallimento, ritorna la stringa vuota.
instead.
 
--]]
---@deprecated
f.getabbr = function(name, extform)
if alt[tonumber(name) or name:lower()] then
extform = string.lower(extform or ''"")
name = tonumber(name) or name:lower()
return alt[name].ext[extform] or '"base'"
end
return name:match('"(%u+%a*)$'") or '"base'"
end
 
f.getAbbr, f.get_abbr = f.getabbr, f.getabbr
 
--[[
f.getnameabbr = function(name, extform)
if alt[tonumber(name) or name:lower()] then
extform = string.lower(extform or ''"")
name = tonumber(name) or name:lower()
return name, alt[name].ext[extform] or '"base'"
end
local poke, abbr = name:match("^([%lé%-♂♀'%s%.&#;%d]+)(%u*%a*)$")
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 unchanged.
 
The name behaviour is needed because in general it not possible to separate the
name from the abbr. If there is some extra assumption (eg. the name is all
lowercase, its the caller's resposibility to exploit it.)
 
--]]
--@param name string An ndex+abbr or Pokémon name
---@return number|string, string
f.getndexabbr = function(name)
-- name is just an ndex
local ndex = string.match(name, "^(%d+)$")
if ndex then
return tonumber(ndex), "base" ---@diagnostic disable-line: return-type-mismatch
end
-- name is an ndex followed by an abbr
local ndex, abbr = string.match(name, "^(%d+)(%u%a*)$")
if ndex then
return tonumber(ndex), abbr ---@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 and the name is returned as-is
return name, "base"
end
 
--[[
--]]
f.getlink = function(poke, black, extform)
black = black or ''""
poke, extform = f.getnameabbr(poke, extform)
if extform == ''"" then
return ''""
end
return alt[poke] and alt[poke][black .. '"links'"][extform] or ''""
end
 
--]]
f.getNdexForm = function(poke)
if type(poke) == '"number'" then
return poke
end
end
for k, tab in pairs(alt) do
if type(k) == '"number'" and tab == alt[poke] then
return k
end
-- Converte la sigla vuota in 'base'
f.toBase = function(abbr)
return abbr == ''"" and '"base'" or abbr
end
 
-- Converte la sigla 'base' nella sigla vuota
f.toEmptyAbbr = function(abbr)
return abbr == '"base'" and ''"" or abbr
end
 
--]]
f.hasMega = function(poke)
poke = string.lower(poke or ''"")
if alt.mega then
return tabletab.search(alt.mega, poke)
or tabletab.search(alt.megaxy, poke)
or tabletab.search(alt.archeo, poke)
end
return false
--]]
f.hasAlola = function(poke)
poke = string.lower(poke or ''"")
if alt.alola then
return tabletab.search(alt.alola, poke)
end
return false
f.formSpan = function(poke, abbr)
return alt[poke].since[abbr],
alt[poke]["until"] and alt[poke]['"until'"][abbr] or genUtil.latest.game
and alt[poke]['until'][abbr]
or genUtil.latest.game
end
 
--]]
f.nameToDataindex = function(name)
name = stringtxt.trim(tostring(name))
local trueName, extform = f.getnameabbr(name)
-- If the name contains uppercase letters it's not recognized by
-- getnameabbr, so this mess is needed
trueName = type(trueName) == '"number'" and trueName or (
or (trueName == ''"" and name:lower() or trueName:lower())
-- The local variable is needed because global alt can be changed with
-- loadUseless
-- extform == 'base' settles problems with numbers and string concat
-- The last check is for Pokémon with both forms
if extform == 'base'
extform == "base"
or not trueAlt[tonumber(trueName) or trueName]
or not trueAlt[tonumber(trueName) or trueName].names[extform] then
then
return trueName
end
trueName = type(trueName) == '"number'" and stringtxt.tf(trueName) or trueName
return trueName .. f.toEmptyAbbr(extform)
end
--]]
f.abbrLT = function(formsData, abbr1, abbr2)
return tabletab.search(formsData.gamesOrder, abbr1)
< tabletab.search(formsData.gamesOrder, abbr2)
end
 
--]]
f.formSortValue = function(ndex, abbr, poke)
ndex = f.getNdexForm(type(ndex) == '"string'" and ndex:lower() or ndex)
local data, value, name = alt[ndex], '"${name}'", poke
local formName
 
if data and data.links[abbr] ~= ''"" then
formName = data.names[abbr]
value = '"${name}, ${form}'"
end
 
return stringtxt.interp(value, {
name = name,
form = formName,
})
end
79 548

contributi