Module:Tableau Objet

De Poképédia
Aller à la navigation Aller à la recherche
Cette section est vide, pas assez détaillée ou incomplète. Vous pouvez la modifier pour l’améliorer.

local p = {}
local ressources = {
	["infosPokemon"] = require("Module:Ressources/infosPokemon")
}

-- Extrait le contenu d'une fonction de la forme "fun_name(argument)" dans une expression.
function extract_argument(fun_name, expression, default)
	-- le tiret est un caractère utilisé pour les noms de fonctions, mais aussi spécial pour les expressions rationnelles
	fun_name_rat = string.gsub(fun_name, "%-", "%%-")
	if (string.match(expression, fun_name_rat .. "%([^)]*%)"))
	then return string.sub(string.match(expression, fun_name_rat .. "%([^)]*%)"), string.len(fun_name) + 2, -2)
	else return default
	end
end

function p.antre(frame)
	local resultat = {"<table class='tableaustandard centre' style='max-width: 100%;'><tr><th rowspan='2'>Objet</th><th colspan='5'>Taux</th></tr>"
		.. "<tr><td class='raid1' width='80px'>★</td><td class='raid2' width='80px'>★★</td><td class='raid3' width='80px'>★★★</td>"
		.. "<td class='raid4' width='80px'>★★★★</td><td class='raid5' width='80px'>★★★★★</td></tr>"}
	
	local objets = frame.args[1]
	if objets ~= nil then objets = mw.text.split(objets, "\n") else objets = {} end
	
	local i = 1
	while objets[i] do
		infos = mw.text.split(objets[i], " / ")
		if infos[1] and infos[2] then
			local nom = infos[1]
			nom = mw.text.split(nom, ", ")
			nom[1] = nom[1]:gsub("{{!}}", "|")
			
			local image = extract_argument("image", infos[2], nil)
			if image == nil
			then if nom[1]:find("|") == nil
				then image = nom[1]
				else image = nom[1]:sub(nom[1]:find("|")+1, nom[1]:len())
				end
			end
			image = "Miniature " .. image .. " EB.png"
			
			table.insert(resultat, "<tr><td style='text-align:left'>[[Fichier:" .. image .. "|class=miniature_objet_EB|link=" .. nom[1] .. "]] [[" .. nom[1] .. "]]")
			if nom[2]
			then table.insert(resultat, " ([[" .. nom[2]:gsub("{{!}}", "|") .. "]])")
			end
			table.insert(resultat, "</td>")
			
			local taux = extract_argument("taux", infos[2], "—")
			local union_taux = (taux ~= "—")
			if taux == "—"
			then
				local j = 1
				while j <= 5 do
					local taux_j = extract_argument(j, infos[2], "—")
					if taux_j ~= "—"
					then union_taux = false	break
					end
					j = j + 1
				end
			end
			
			if union_taux
			then taux = mw.text.split(taux, ", ")
				local taux_text = taux[1]:gsub("%%", "&nbsp;%%")
				k = 2
				while taux[k] do
					taux_k_number = taux[k]:gsub("%%", "")
					if tonumber(taux_k_number)
					then taux_text = taux_text .. "<br>" .. taux[k]:gsub("%%", "&nbsp;%%")
					else taux_text = taux_text .. frame:expandTemplate{title='Sup', args={taux[k]}}
					end
					k = k + 1
				end
				table.insert(resultat, "<td colspan='5'>" .. taux_text .. "</td>")
			else
				local j = 1
				while j <= 5 do
					local taux_j = extract_argument(j, infos[2], "—")
					taux_j = mw.text.split(taux_j, ", ")
					local taux_j_text = taux_j[1]:gsub("%%", "&nbsp;%%")
					k = 2
					while taux_j[k] do
						taux_jk_number = taux_j[k]:gsub("%%", "")
						if tonumber(taux_jk_number)
						then taux_j_text = taux_j_text .. "<br>" .. taux_j[k]:gsub("%%", "&nbsp;%%")
						else taux_j_text = taux_j_text .. frame:expandTemplate{title='Sup', args={taux_j[k]}}
						end
						k = k + 1
					end
					table.insert(resultat, "<td class='raid" .. j .. "'>" .. taux_j_text .. "</td>")
					j = j + 1
				end
			end
			table.insert(resultat, "</tr>")
			
		elseif infos[1] ~= "" then
			local ligne = mw.text.split(infos[1], " // ")
			if ligne[2]
			then
				l1 = mw.text.split(ligne[1], ", ")
				l2 = mw.text.split(ligne[2], ", ")
				table.insert(resultat, '<tr><td colspan="6" style="padding:0px;">'
					.. '<table style="width:100%;text-align:center;background-color:white;border-radius:3px;">'
					.. '<tr><td class="épée" width="50%"><small><i>Épée</i></small><br>')
				
				local j = 1
				while l1[j] do
					if l1[j]:find("★")
					then table.insert(resultat, "<sup>" .. l1[j] .. "</sup>")
					else table.insert(resultat, ressources.infosPokemon(l1[j], "miniature"))
					end
					j = j + 1
				end
				table.insert(resultat, '</td><td class="bouclier" width="50%"><small><i>Bouclier</i></small><br>')
				local j = 1
				while l2[j] do
					if l2[j]:find("★")
					then table.insert(resultat, "<sup>" .. l2[j] .. "</sup>")
					else table.insert(resultat, ressources.infosPokemon(l2[j], "miniature"))
					end
					j = j + 1
				end
				table.insert(resultat, "</td></tr></table></th></tr>")
				
			else
				if infos[1]:sub(1,5) == "<big>"
					then table.insert(resultat, "<tr><th colspan='6' class='transition'>" .. infos[1] .. "</td></tr>")
				elseif infos[1] == "Épée"
					then table.insert(resultat, "<tr><td colspan='6' class='épée'>"
						.. frame:expandTemplate{title='Jeu', args={"Ep"}} .. "</td></tr>")
				elseif infos[1] == "Bouclier"
					then table.insert(resultat, "<tr><td colspan='6' class='bouclier'>"
						.. frame:expandTemplate{title='Jeu', args={"Bo"}} .. "</td></tr>")
				else table.insert(resultat, "<tr><th colspan='6'>" .. infos[1] .. "</th></tr>")
				end
			end
		end
		
		i = i + 1
	end
	
	table.insert(resultat, "</table>")
	return table.concat(resultat, "")
end






function p.teracristal(frame)
	local ressources = {
		["de"] = require("Module:Ressources/de")
	}
	local id_separator = "_"
	
	local resultat = {"<table class='tableaustandard centre'><tr><th>Objet</th><th width='80px'>Nombre</th><th>Objet</th><th width='80px'>Nombre</th></tr>"}
	
	local objets = frame.args[1]
	if objets ~= nil then objets = mw.text.split(objets, "\n") else objets = {} end
	
	local item_on_the_left = true
	local i = 1
	while objets[i] do
		infos = mw.text.split(objets[i], " / ")
		if infos[1] and infos[2] then
			local name_list = mw.text.split(infos[1], ", ")
			local name = name_list[1]
			name = name:gsub("{{!}}", "|")
			
			local image = name
			
			if name_list[2]
			then name = name_list[2] -- image stays the same
			end
			
			if image:find("|") ~= nil
			then image = image:sub(image:find("|")+1, image:len())
			end
			image = "Miniature " .. image .. " EV.png"
			
			if item_on_the_left then table.insert(resultat, "<tr>") end
			table.insert(resultat, "<td style='text-align:left; white-space:nowrap'>[[Fichier:" .. image .. "|class=miniature_objet_EV|link=" .. name .. "]] [[" .. name .. "]]")
			if name_list[3]
			then table.insert(resultat, " ([[" .. name_list[3]:gsub("{{!}}", "|") .. "]])")
			end
			table.insert(resultat, "</td>")
			
			local amount = infos[2]
			if amount == "" or amount == "-" then amount = "—"
			elseif tonumber(amount) then amount = "×" .. amount
			end
			
			if infos[3]
			then infos[3] = infos[3]:gsub("%%", "&nbsp;%%")
				if infos[3] == "hôte" or infos[3] == "h"
					then amount = amount .. "<br>(hôte)"
				elseif infos[3] == "invités" or infos[3] == "i"
					then amount = amount .. "<br>(invités)"
				else amount = amount .. "<br>(" .. infos[3] .. ")"
				end
			end
			table.insert(resultat, "<td>" .. amount .. "</td>")
			if not item_on_the_left then table.insert(resultat, "</tr>") end
			
			item_on_the_left = not item_on_the_left
			
		elseif infos[1] ~= "" then
			local id = infos[1]
			local id_split = mw.text.split(id, id_separator)
			local pokemon = id_split[1]
			local difficulty = id_split[2]
			
			local difficulty_stars = ""
			if tonumber(difficulty) ~= nil
			then difficulty_stars = " " .. difficulty .. "★"
			end
			
			table.insert(resultat, "<tr><th colspan='4' id='Objet" .. id_separator .. id .. "'>Récompenses " .. ressources.de(pokemon) .. pokemon .. difficulty_stars .. " ([[#Pokémon" .. id_separator .. id .. "|voir]])</th></tr>")
			
			item_on_the_left = true
		end
		
		i = i + 1
	end
	
	table.insert(resultat, "</table>")
	return table.concat(resultat, "")
end

return p