Module:Data
Apparence
Le module data est le point d'entrée de différentes données enregistrées dans des sous-pages de ce module. La liste des données disponibles à l'heure actuelle est accessible à l'adresse Spécial:Index/Module:Data/.
Sur ce module est présente la fonction « obtenir » qui sert à afficher les données demandées sur une page classique (en wikitexte). Elle nécessite un seul paramètre qui est le nom des données. Par exemple, pour obtenir les données du Module:Data/NumérosPokémon, il faut taper :
{{#invoke:Data|obtenir|NumérosPokémon}}
local p = {}
function p.obtenir( frame )
local nom = frame.args[1]
if nom == nil then return "Erreur : pas de nom de données renseigné." end
local donnees = mw.loadData( "Module:Data/" .. nom )
if donnees == nil then return "Erreur : pas de données avec ce nom." end
donnees = mw.dumpObject( donnees )
return "<pre>" .. donnees .. "</pre>"
end
function p.num( frame )
local numeros = mw.loadData('Module:Data/NumérosPokémon')
local resultat = numeros[frame.args[1]]
if resultat == nil then
return "[[Catégorie:Page avec un nom de Pokémon incorrect]]"
else
return resultat
end
end
function p.nomsjeux(frame)
local data = mw.loadData("Module:Data/NomsJeux")
return data[frame.args[1]]
end
function p.nompokemon(frame)
local data = mw.loadData("Module:Data/NomsPokémon")
local langue = frame.args["langue"]
if not langue then langue = "fr" end
return data[tonumber(frame.args[1])][langue]
end
function p.gen( frame )
local generations = mw.loadData('Module:Data/GénérationJeux')
return generations[frame.args[1]]
end
-- Fonction de comptage des Pokémon par type, à lancer avec mw.logObject(p.comptagetypes({})) dans la console en bas de la page
function p.comptagetypes(frame)
local datatypes = mw.loadData("Module:Data/TypesPokémon")
local types = {"Normal", "Combat", "Vol", "Poison", "Sol", "Roche", "Insecte", "Spectre", "Acier", "Feu", "Eau", "Plante", "Électrik", "Psy", "Glace", "Dragon", "Ténèbres", "Fée"}
local d = {}
for _, t in pairs(types) do
d[t] = 0
end
for key, pokemon in pairs(datatypes) do
for _, current_type in pairs(types) do
local found = false
for _, form in pairs(pokemon) do
for _, pokemon_type in pairs(form) do
if current_type == pokemon_type
then found = true
d[current_type] = d[current_type] + 1
break
end
end
if found then break end
end
end
end
return d
end
-- Fonction de comptage des capacités par type et catégorie, à lancer avec mw.logObject(p.comptagetypescapacites({})) dans la console en bas de la page
function p.comptagetypescapacites(frame)
local datatypes = mw.loadData("Module:Data/Données Capacités Génération 9")
local types = {"Normal", "Combat", "Vol", "Poison", "Sol", "Roche", "Insecte", "Spectre", "Acier", "Feu", "Eau", "Plante", "Électrik", "Psy", "Glace", "Dragon", "Ténèbres", "Fée", "Obscur", "???", "Stellaire"}
local categories = {"Physique", "Spécial", "Statut", "variable"}
local d = {}
local d_cat = {}
local total = 0
for _, t in pairs(types) do
d[t] = 0
end
for _, c in pairs(categories) do
d_cat[c] = 0
end
for move_key, move_info in pairs(datatypes) do
move_type = move_info[1]
move_cat = move_info[2]
d[move_type] = d[move_type] + 1
d_cat[move_cat] = d_cat[move_cat] + 1
total = total + 1
end
return {["Total"] = total, ["Catégories"] = d_cat, ["Types"] = d}
end
function p.de(frame)
local s = frame.args[1]
local prefixe = frame.args["préfixe"]
if not prefixe then prefixe = "d" end
if not s then resultat = prefixe .. "e " end
local ressources = {
["de"] = require("Module:Ressources/de")
}
return string.gsub(ressources.de(s), "d", prefixe) .. ''
end
function p.premiertype(frame)
local pokemon = frame.args[1]
local form
-- Les apostrophes ne peuvent pas être capturées dans le PAGENAME, donc on les remplace par .-
local special_replacement_ids = {
["Kyurem Blanc"] = {"Kyurem", "Blanc"},
["Kyurem Noir"] = {"Kyurem", "Noir"},
["Necrozma Crinière du Couchant"] = {"Necrozma", "Crinière du Couchant"},
["Necrozma Ailes de l.-Aurore"] = {"Necrozma", "Ailes de l'Aurore"},
["Ultra%-Necrozma"] = {"Necrozma", "Ultra"},
["Sylveroy, le Cavalier du Froid"] = {"Sylveroy", "Cavalier du Froid"},
["Sylveroy, le Cavalier d.-Effroi"] = {"Sylveroy", "Cavalier d'Effroi"}
}
local replacement_ids = {
[" d.-Alola"] = "Alola",
[" de Galar"] = "Galar",
[" de Hisui"] = "Hisui",
[" de Paldea"] = "Paldea",
["Méga%-"] = "Méga",
["Primo%-"] = "Primo",
[" Gigamax"] = "Gigamax",
[" Infinimax"] = "Infinimax"
}
for replacing, replaced in pairs(special_replacement_ids) do
if pokemon:match(replacing) == pokemon
then pokemon = replaced[1]
form = replaced[2]
break
end
end
for replacing, replaced in pairs(replacement_ids) do
if mw.ustring.find(pokemon, replacing)
then pokemon = mw.ustring.gsub(pokemon, replacing, "")
form = replaced
end
end
local datatypes = require("Module:Data/TypesPokémon")
local form_arg = frame.args["forme"]
if form_arg == nil or form_arg == ""
then if form == nil
then form = 1
end
else form = form_arg
end
local types = datatypes[pokemon]
if types == nil
then return ""
end
local types_form = types[form]
if types_form == nil
then return ""
end
local first_type = types_form[1]
return first_type
end
return p