Path: blob/main/static/src/gs/public/radius-raid/js/util.js
1324 views
/*==============================================================================1Miscellaneous2==============================================================================*/3window['requestAnimFrame']=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();45$.util = {};6$.pi = Math.PI;7$.twopi = $.pi * 2;89/*==============================================================================10Random Range11==============================================================================*/12$.util.rand = function( min, max ) {13return Math.random() * ( max - min ) + min;14};1516/*==============================================================================17Calculations18==============================================================================*/19$.util.distance = function( p1x, p1y, p2x, p2y ) {20var xDistance = p1x - p2x,21yDistance = p1y - p2y;22return Math.sqrt( Math.pow( xDistance, 2 ) + Math.pow( yDistance, 2 ) );23};2425$.util.rectInRect = function( r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h ) {26return !( r2x > r1x + r1w ||27r2x + r2w < r1x ||28r2y > r1y + r1h ||29r2y + r2h < r1y );30};3132$.util.arcInRect = function( ax, ay, ar, rx, ry, rw, rh ) {33return !( ax + ar <= rx || ax - ar >= rx + rw || ay + ar <= ry || ay - ar >= ry + rh );34};3536$.util.arcIntersectingRect = function( ax, ay, ar, rx, ry, rw, rh ) {37return !( ax <= rx - ar || ax >= rx + rw + ar || ay <= ry - ar || ay >= ry + rh + ar );38};3940$.util.pointInRect = function( px, py, rx, ry, rw, rh ) {41return ( px >= rx && px <= rx + rw && py >= ry && py <= ry + rh );42};4344/*==============================================================================45Shapes46==============================================================================*/47$.util.circle = function( ctx, x, y, radius ) {48var radius = radius <= 0 ? 1 : radius;49ctx.beginPath();50ctx.arc( x, y, radius, 0, $.twopi, false );51};5253$.util.fillCircle = function( ctx, x, y, radius, fillStyle ) {54$.util.circle( ctx, x, y, radius );55ctx.fillStyle = fillStyle;56ctx.fill();57};5859$.util.strokeCircle = function( ctx, x, y, radius, strokeStyle, lineWidth ) {60$.util.circle( ctx, x, y, radius );61ctx.lineWidth = lineWidth;62ctx.strokeStyle = strokeStyle;63ctx.stroke();64};6566/*==============================================================================67Miscellaneous68==============================================================================*/69$.util.pad = function( amount, digits ){70amount += '';71if( amount.length < digits ) {72amount = '0' + amount;73return $.util.pad( amount, digits );74} else {75return amount;76}77};7879$.util.convertTime = function( seconds ) {80var minutes = Math.floor( seconds / 60 );81var seconds = Math.floor( seconds % 60 );82return $.util.pad( minutes, 2 ) + ':' + $.util.pad( seconds, 2 );83};8485$.util.commas = function( nStr ) {86nStr += '';87var x = nStr.split( '.' ),88x1 = x[ 0 ],89x2 = x.length > 1 ? '.' + x[ 1 ] : '',90rgx = /(\d+)(\d{3})/;91while( rgx.test( x1 ) ) {92x1 = x1.replace( rgx, '$1' + ',' + '$2' );93}94return x1 + x2;95};969798$.util.isset = function( prop ) {99return typeof prop != 'undefined';100};101102