Binding of Isaac: Rebirth Wiki
Aucun résumé des modifications
Aucun résumé des modifications
 
(Aucune différence)

Dernière version du 16 mars 2019 à 14:07

La documentation pour ce module peut être créée à Module:Texte/doc

local p = {}
local tableau = require( 'Module:Tableau' )

function p.nomPage( f )
	return mw.title.getCurrentTitle().text;
end

p.caracteresSpeciaux = {
	['"'] = "oquote",
	["“"] = "oquote",
	["”"] = "cquote",
	["*"] = "star",
	["+"] = "plus",
	["±"] = "pm",
	["="] = "equal",
	["~"] = "tilde",
	[":"] = "colon",
	[";"] = "scolon",
	["."] = "point",
	["!"] = "emark",
	["?"] = "qmark",
	["/"] = "slash",
	["|"] = "vbar",
	["\\"] = "bslash",
	["("] = "oparen",
	[")"] = "cparen",
	["["] = "obrkt",
	["]"] = "cbrkt",
	["{"] = "obrace",
	["}"] = "cbrace",
	["<"] = "lthan",
	[">"] = "gthan",
	["¶"] = "pilcrow",
	["&"] = "and",
	["§"] = "ss",
	["%"] = "percent",
	["†"] = "dagger",
	["‡"] = "diesis",
	["#"] = "hash",
	["°"] = "degree",
	["$"] = "dol",
	["€"] = "euro",
	["¢"] = "cent",
	["£"] = "pound",
	["@"] = "at",
	["©"] = "copy",
	["®"] = "regtm",
	["¤"] = "curren",
}


-- Remplace un texte par un/des conteneur(s) (div), avec une police d'écriture particulière en fond
-- Disponibles : TeamMeat (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat.png)
--               TeamMeat-Bold (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat_Bold.png)
function p.fonte( f )
	local args = tableau.toutRogner( f.args )
	local _t = '<span style="white-space:nowrap">'
	
	-- Cherche les caractères personnalisés
	local char = {}
	if args.var1 then
		local i = 1
		repeat
			char[i] = mw.text.split( args['var'..i], '-' )
			i = i + 1
		until not args['var'..i]
	end
	
	-- Découpe la chaîne de caractères
	local caracteres = {}
	args[2]:gsub( ".", function(c) table.insert( caracteres, c ) end )
	local j = 1
	while caracteres[j] do
		-- Est un espace ?
		if caracteres[j] == ' ' then
			_t = _t .. '</span> &nbsp;<span style="white-space:nowrap">'
		else
			-- Remplace les caractères personnalisés
			for k, l in pairs( char ) do
				if caracteres[j] == l[1] then
					caracteres[j] = l[2]
					break
				end
			end
			-- Est un caractère spécial ?
			caracteres[j] = p.caracteresSpeciaux[caracteres[j]] or caracteres[j]
			-- Remplace chaque caractère par la balise correspondante
			_t = _t .. '<div ' .. ( args.titre and 'title="' .. args.titre .. '"' or '' ) .. ' class="font-' .. args[1] .. ' font-' .. args[1] .. '-' .. caracteres[j] .. '"></div>'
		end
		j = j + 1
	end
	
	return _t .. '</span>'
end


p.caracteresSpeciauxTitre = {
	["+"] = "plus",
	[":"] = "colon",
	[";"] = "scolon",
	["?"] = "qmark",
	["/"] = "slash",
	["|"] = "vbar",
	["\\"] = "bslash",
	["["] = "obrkt",
	["]"] = "cbrkt",
	["{"] = "obrace",
	["}"] = "cbrace",
	["<"] = "lthan",
	[">"] = "gthan",
	["#"] = "hash"
}


function p.titre( f )
	local args = tableau.toutRogner( tableau.obtenirArgs( f ) )
	local _t = '<span style="white-space:nowrap">'
	
	-- Cherche les caractères personnalisés
	local char = {}
	if args.var1 then
		local i = 1
		repeat
			char[i] = mw.text.split( args['var'..i], '-' )
			i = i + 1
		until not args['var'..i]
	end
	
	-- Découpe la chaîne de caractères
	local caracteres = {}
	args[2]:gsub( ".", function(c) table.insert( caracteres, c ) end )
	local j = 1
	
	while caracteres[j] do
		-- Est un espace ?
		if caracteres[j] == ' ' then
			_t = _t .. '</span> ' .. ( tonumber( args[3] or 1 ) > 1.5 and '&nbsp;' or '' ) .. '&nbsp;<span style="white-space:nowrap">'
		else
			-- Est un caractère spécial ?
			caracteres[j] = p.caracteresSpeciauxTitre[caracteres[j]] or caracteres[j]
			-- Remplace les caractères personnalisés
			for k, l in pairs( char ) do
				if caracteres[j] == l[1] then
					caracteres[j] = l[2]
					break
				end
			end
			-- Remplace chaque caractère par la balise correspondante
			local nomFichier = 'Font_' .. args[1] .. '_' .. caracteres[j] .. '.png'
			local largeur = math.floor( mw.getCurrentFrame():callParserFunction( '#imgw', nomFichier ) * ( args[3] or 1 ) )
			local hauteur = math.floor( mw.getCurrentFrame():callParserFunction( '#imgh', nomFichier ) * ( args[3] or 1 ) )
			_t = _t .. '[[fichier:' .. nomFichier .. '|' .. tostring( largeur ) .. 'x' .. tostring( hauteur ) .. 'px|lien=' .. ( args.lien or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
		end
		j = j + 1
	end
	
	return _t .. '</span>'
end

return p