Module:Text

De Binding of Isaac: Rebirth Wiki
Aller à : navigation, rechercher
Missing No. Icon.png
Ce module est lié au projet Modèles.
Ne l'utilisez pas sur des pages du wiki non-liées à ce projet tant que celui-ci n'est pas terminé.



local p = {}
local rtable = require( 'Module:Table' )

p.specialCharacters = {
	["“"] = "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",
}


-- Replace a text with div(s), with a special font on background
-- Available: TeamMeat (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat.png)
--            TeamMeat-Bold (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat_Bold.png)
function p.font( f )
	local args = rtable.trimAll( rtable.getArgs( f ) )
	local _t = '<span style="white-space:nowrap">'
	
	-- Get custom characters
	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
	
	-- Split string
	local characters = {}
	args[2]:gsub( ".", function(c) table.insert( characters, c ) end )
	local j = 1
	while characters[j] do
		-- Is a space ?
		if characters[j] == ' ' then
			_t = _t .. '</span> &nbsp;<span style="white-space:nowrap">'
		else
			-- Replace custom character
			for k, l in pairs( char ) do
				if characters[j] == l[1] then
					characters[j] = l[2]
					break
				end
			end
			-- Is a special character ?
			characters[j] = p.specialCharacters[characters[j]] or characters[j]
			-- Replace character with a div
			_t = _t .. '<div ' .. ( args.title and 'title="' .. args.title .. '"' or '' ) .. ' class="font-' .. args[1] .. ' font-' .. args[1] .. '-' .. characters[j] .. '"></div>'
		end
		j = j + 1
	end
	
	return _t .. '</span>'
end


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


function p.title( f )
	local args = rtable.trimAll( rtable.getArgs( f ) )
	local _t = '<span style="white-space:nowrap">'
	
	-- Get custom characters
	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
	
	-- Split string
	local characters = {}
	args[2]:gsub( ".", function(c) table.insert( characters, c ) end )
	local j = 1
	
	while characters[j] do
		-- Is a space ?
		if characters[j] == ' ' then
			_t = _t .. '</span> ' .. ( tonumber( args[3] or 1 ) > 1.5 and '&nbsp;' or '' ) .. '&nbsp;<span style="white-space:nowrap">'
		else
			-- Is a special character ?
			characters[j] = p.specialCharactersTitle[characters[j]] or characters[j]
			-- Replace custom character
			for k, l in pairs( char ) do
				if characters[j] == l[1] then
					characters[j] = l[2]
					break
				end
			end
			-- Replace character with an image
			local fileName = 'Font_' .. args[1] .. '_' .. characters[j] .. '.png'
			local width = math.floor( mw.getCurrentFrame():callParserFunction( '#imgw', fileName ) * ( args[3] or 1 ) )
			local height = math.floor( mw.getCurrentFrame():callParserFunction( '#imgh', fileName ) * ( args[3] or 1 ) )
			_t = _t .. '[[Image:' .. fileName .. '|' .. tostring( width ) .. 'x' .. tostring( height ) .. 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
		end
		j = j + 1
	end
	
	return _t .. '</span>'
end

return p
Promotional Content