Path: blob/main/static/src/gs/public/radius-raid/js/text.js
1324 views
$.textLine = function( opt ) {1var textLength = opt.text.length,2size = 5;3for( var i = 0; i < textLength; i++ ) {4var letter = $.definitions.letters[ ( opt.text.charAt( i ) ) ] || $.definitions.letters[ 'unknown' ];5for( var y = 0; y < size; y++ ) {6for( var x = 0; x < size; x++ ) {7if( letter[ y ][ x ] === 1 ) {8opt.ctx.rect( opt.x + ( x * opt.scale ) + ( ( size * opt.scale ) + opt.hspacing ) * i, opt.y + y * opt.scale, opt.scale, opt.scale );9}10}11}12}13};1415$.text = function( opt ) {16var size = 5,17letterSize = size * opt.scale,18lines = opt.text.split('\n'),19linesCopy = lines.slice( 0 ),20lineCount = lines.length,21longestLine = linesCopy.sort( function ( a, b ) { return b.length - a.length; } )[ 0 ],22textWidth = ( longestLine.length * letterSize ) + ( ( longestLine.length - 1 ) * opt.hspacing ),23textHeight = ( lineCount * letterSize ) + ( ( lineCount - 1 ) * opt.vspacing );2425var sx = opt.x,26sy = opt.y,27ex = opt.x + textWidth,28ey = opt.y + textHeight;2930if( opt.halign == 'center' ) {31sx = opt.x - textWidth / 2;32ex = opt.x + textWidth / 2;33} else if( opt.halign == 'right' ) {34sx = opt.x - textWidth;35ex = opt.x;36}3738if( opt.valign == 'center' ) {39sy = opt.y - textHeight / 2;40ey = opt.y + textHeight / 2;41} else if( opt.valign == 'bottom' ) {42sy = opt.y - textHeight;43ey = opt.y;44}4546var cx = sx + textWidth / 2,47cy = sy + textHeight / 2;4849if( opt.render ) {50for( var i = 0; i < lineCount; i++ ) {51var line = lines[ i ],52lineWidth = ( line.length * letterSize ) + ( ( line.length - 1 ) * opt.hspacing ),53x = opt.x,54y = opt.y + ( letterSize + opt.vspacing ) * i;5556if( opt.halign == 'center' ) {57x = opt.x - lineWidth / 2;58} else if( opt.halign == 'right' ) {59x = opt.x - lineWidth;60}6162if( opt.valign == 'center' ) {63y = y - textHeight / 2;64} else if( opt.valign == 'bottom' ) {65y = y - textHeight;66}6768if( opt.snap ) {69x = Math.floor( x );70y = Math.floor( y );71}7273$.textLine( {74ctx: opt.ctx,75x: x,76y: y,77text: line,78hspacing: opt.hspacing,79scale: opt.scale80} );81}82}8384return {85sx: sx,86sy: sy,87cx: cx,88cy: cy,89ex: ex,90ey: ey,91width: textWidth,92height: textHeight93}94};9596