Binding of Isaac: Rebirth Wiki
Advertisement

local p = {}

local w_frame = require( 'module:frame' )
local w_table = require( 'module:table' )
local w_title = require( 'module:title' )


p.pageName     = w_title.main
p.rootPageName = w_title.root
p.subPageName  = w_title.subpage


function p.toNumber( f )
	local args = w_frame.args( f )
	return tonumber( args[1], args.base or 10 )
end


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


function p.font2( f )
    local args  = w_frame.args( f )
    local font  = 'font-' .. args[ 1 ]
    local intro = '<div' .. ( args.title and ' title="' .. args.title .. '"' or '' ) .. ' class="' .. font .. ' ' .. font .. '-'
	local text  = '<span style="white-space:nowrap">'
    for c in mw.text.gsplit( args[ 2 ] ) do
        text = text .. ( c == ' ' and '</span> &nbsp;<span style="white-space:nowrap">' or intro .. ( p.specialCharacters[c] or c ) .. '"></div>' )
    end
    return text .. '</span>'
end


function p.title2( f )
    local args  = w_frame.args( f )
    local scale = tonumber( args[ 3 ] or 1 )
    local space = '</span> ' .. ( scale > 1.5 and '&nbsp;' or '' ) .. ' <span style="white-space: nowrap">'
    local width = mw.loadData( 'module:text/' .. args[ 1 ] )
    local intro = '[[file:font_' .. args[ 1 ] .. '_'
    local outro = 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
    local text  = '<span style="white-space:nowrap">'
    for c in mw.text.gsplit( args[ 2 ] ) do
        text = text .. ( c == ' ' and space or intro .. ( p.specialCharacters[ c ] or c ) .. '.png|' .. math.floor( width[ c ] * scale ) .. outro )
    end
    return text .. '</span>'
end


-- 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 = w_frame.args( 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 = {}
	if args[2] then
		args[2]:gsub( '.', function( c ) table.insert( characters, c ) end )
	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.filesWidth = {
	["("] = 9,
	["“"] = 7,
	["."] = 7,
	["§"] = 11,
	["'"] = 8,
	["-"] = 12,
	["&"] = 14,
	["@"] = 17,
	["¤"] = 11,
	["©"] = 14,
	[")"] = 9,
	["°"] = 10,
	["$"] = 13,
	["%"] = 22,
	["£"] = 15,
	["®"] = 14,
	["~"] = 13,
	["!"] = 7,
	["¢"] = 11,
	["="] = 11,
	["¶"] = 11,
	["±"] = 18,
	["{"] = 13,
	["1"] = 8,
	["2"] = 12,
	["4"] = 11,
	["6"] = 13,
	["7"] = 13,
	["D"] = 13,
	["G"] = 15,
	["K"] = 15,
	["M"] = 17,
	["P"] = 14,
	["Q"] = 19,
	["S"] = 14,
	["U"] = 14,
	["b"] = 10,
	["e"] = 11,
	["f"] = 11,
	["m"] = 12,
	["o"] = 12,
	["}"] = 10,
	["0"] = 11,
	["8"] = 13,
	["9"] = 12,
	["I"] = 11,
	["J"] = 13,
	["L"] = 14,
	["O"] = 17,
	["V"] = 13,
	["Z"] = 15,
	["a"] = 10,
	["g"] = 12,
	["h"] = 11,
	["i"] = 5,
	["k"] = 11,
	["t"] = 12,
	["w"] = 14,
	["x"] = 10,
	["z"] = 13,
	["\\"] = 8,
	[">"] = 13,
	["#"] = 17,
	["["] = 9,
	[";"] = 7,
	["A"] = 14,
	["B"] = 14,
	["C"] = 12,
	["E"] = 12,
	["F"] = 13,
	["H"] = 14,
	["N"] = 17,
	["R"] = 15,
	["T"] = 15,
	["W"] = 19,
	["X"] = 16,
	["Y"] = 15,
	["c"] = 11,
	["d"] = 11,
	["j"] = 10,
	["l"] = 7,
	["n"] = 10,
	["p"] = 10,
	["q"] = 12,
	["r"] = 11,
	["s"] = 11,
	["u"] = 11,
	["v"] = 12,
	["y"] = 9,
	["]"] = 10,
	[":"] = 5,
	["?"] = 13,
	["<"] = 13,
	["+"] = 12,
	["/"] = 10,
	["*"] = 10,
	["3"] = 13,
	["5"] = 13,
}


function p.title( f )
	local args = w_frame.args( 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 '' ) .. ' <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
			-- Replace character with an image
			local fileName = 'Font_' .. args[1] .. '_' .. ( p.specialCharacters[characters[j]] or characters[j] ) .. '.png'
			local width = math.floor( p.filesWidth[characters[j]] * ( args[3] or 1 ) )
			_t = _t .. '[[file:' .. fileName .. '|' .. tostring( width ) .. 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
		end
		j = j + 1
	end

	return _t .. '</span>'
end


return p
Advertisement