Module:Data

De Poképédia
Aller à la navigation Aller à la recherche

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")
	return data[tonumber(frame.args[1])]["fr"]
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]
	if not s then return "de " end
	
	local ressources = {
		["de"] = require("Module:Ressources/de")
	}
	return ressources.de(s)
end

function p.premiertype(frame)
	local pokemon = frame.args[1]
	local form
	
	local replacement_ids = {
		[" d'Alola"] = "Alola",
		[" de Galar"] = "Galar",
		[" de Hisui"] = "Hisui",
		[" de Paldea"] = "Paldea",
		["Méga%-"] = "Méga",
		[" Gigamax"] = "Gigamax"
	}
	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