jshint and initial corrections
This leaves issues that involve actual logic changes unresolved. It also raises an issue with the `Map` class, which is defined in ES6, and so will have to be renamed.master
parent
93f3008740
commit
47e022b555
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"eqeqeq": true,
|
||||
"esnext": true,
|
||||
"forin": true,
|
||||
"freeze": true,
|
||||
"futurehostile": true,
|
||||
"latedef": true,
|
||||
"laxbreak": true,
|
||||
"maxcomplexity": 100,
|
||||
"maxdepth": 3,
|
||||
"maxparams": 5,
|
||||
"noarg": true,
|
||||
"nocomma": true,
|
||||
"node": true,
|
||||
"nonbsp": true,
|
||||
"nonew": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"varstmt": true
|
||||
}
|
|
@ -31,7 +31,12 @@ modindex: $(nsindex)
|
|||
|
||||
standalone: lasertank.js
|
||||
lasertank.js: modindex
|
||||
./node_modules/.bin/browserify -s lasertank --debug src/index.js > "$@"
|
||||
./node_modules/.bin/browserify \
|
||||
-t strictify \
|
||||
-s lasertank \
|
||||
--debug \
|
||||
src/index.js \
|
||||
> "$@"
|
||||
|
||||
test: check
|
||||
check:
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
"devDependencies": {
|
||||
"chai": ">=1.9.1",
|
||||
"mocha": ">=1.18.2",
|
||||
"browserify": "~12"
|
||||
"browserify": "~12",
|
||||
"strictify": "~0.2"
|
||||
},
|
||||
|
||||
"licenses": [
|
||||
|
|
|
@ -18,17 +18,17 @@
|
|||
*/
|
||||
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Game = require( './Game' ),
|
||||
ClassicGameObjectFactory = require( './ClassicGameObjectFactory' ),
|
||||
ClassicMap = require( './ClassicMap' ),
|
||||
ClassicTileDfn = require( './ClassicTileDfn' ),
|
||||
LtgLoader = require( './LtgLoader' ),
|
||||
MapBounds = require( './MapBounds' ),
|
||||
MapRender = require( './MapRender' ),
|
||||
MapSet = require( './MapSet' ),
|
||||
MapState = require( './MapState' ),
|
||||
TileMasker = require( './TileMasker' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
Game = require( './Game' ),
|
||||
ClassicGameObjectFactory = require( './ClassicGameObjectFactory' ),
|
||||
ClassicMap = require( './ClassicMap' ),
|
||||
ClassicTileDfn = require( './ClassicTileDfn' ),
|
||||
LtgLoader = require( './LtgLoader' ),
|
||||
MapBounds = require( './MapBounds' ),
|
||||
MapRender = require( './MapRender' ),
|
||||
MapSet = require( './MapSet' ),
|
||||
MapState = require( './MapState' ),
|
||||
TileMasker = require( './TileMasker' );
|
||||
|
||||
/**
|
||||
* Facade for the classic (original) game of LaserTank
|
||||
|
@ -92,7 +92,7 @@ module.exports = Class( 'ClassicGame' )
|
|||
*/
|
||||
__construct: function( ltg_data, lvl_data )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
this._ltgLoader = LtgLoader();
|
||||
this._masker = TileMasker( ClassicTileDfn() );
|
||||
|
@ -127,9 +127,9 @@ module.exports = Class( 'ClassicGame' )
|
|||
this._render.clearCanvas();
|
||||
}
|
||||
|
||||
var map = this._mapSet.getMapByNumber( 1 ),
|
||||
map_state = MapState( map, this._gameObjFactory ),
|
||||
bounds = MapBounds( map );
|
||||
const map = this._mapSet.getMapByNumber( 1 ),
|
||||
map_state = MapState( map, this._gameObjFactory ),
|
||||
bounds = MapBounds( map );
|
||||
|
||||
// render the first map (hardcoded for now)
|
||||
this._render = MapRender( ctx, this._tileSet )
|
||||
|
@ -138,7 +138,7 @@ module.exports = Class( 'ClassicGame' )
|
|||
// POC
|
||||
window.onkeydown = function( event )
|
||||
{
|
||||
var dir;
|
||||
let dir;
|
||||
|
||||
switch ( event.keyCode )
|
||||
{
|
||||
|
@ -171,8 +171,8 @@ module.exports = Class( 'ClassicGame' )
|
|||
'public setTileData': function( data, callback )
|
||||
{
|
||||
// get tile metadata
|
||||
var _self = this,
|
||||
meta = this._ltgLoader.fromString( data );
|
||||
const _self = this,
|
||||
meta = this._ltgLoader.fromString( data );
|
||||
|
||||
this._masker.getMaskedTiles( meta.tiles, meta.mask, function( tdata )
|
||||
{
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' ),
|
||||
Tank = require( './gameobjs/Tank' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' ),
|
||||
Tank = require( './gameobjs/Tank' );
|
||||
|
||||
|
||||
module.exports = Class( 'ClassicGameObjectFactory' )
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
* display.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -170,8 +170,8 @@ module.exports = Class( 'ClassicMap' )
|
|||
*/
|
||||
'public getObjects': function()
|
||||
{
|
||||
var tiles = this._getDataSegment( '_GOSIZE', false ).split( '' ),
|
||||
i = tiles.length;
|
||||
const tiles = this._getDataSegment( '_GOSIZE', false ).split( '' );
|
||||
let i = tiles.length;
|
||||
|
||||
while ( i-- )
|
||||
{
|
||||
|
@ -192,8 +192,8 @@ module.exports = Class( 'ClassicMap' )
|
|||
{
|
||||
stripnull = ( arguments.length < 2 ) ? true : !!stripnull;
|
||||
|
||||
var s = this.__self.$( name ),
|
||||
data = this._data.substr( ( this._offset + s[ 0 ] ), s[ 1 ] );
|
||||
const s = this.__self.$( name ),
|
||||
data = this._data.substr( ( this._offset + s[ 0 ] ), s[ 1 ] );
|
||||
|
||||
return ( stripnull )
|
||||
? data.split( '\0' )[ 0 ]
|
||||
|
@ -247,7 +247,7 @@ module.exports = Class( 'ClassicMap' )
|
|||
{
|
||||
// get the tunnel id by stripping off the tunnel bitmask and then grab
|
||||
// the associated color
|
||||
var tunnel_id = ( ( +oid ^ this.__self.$( '_TMASK' ) ) / 2 );
|
||||
const tunnel_id = ( ( +oid ^ this.__self.$( '_TMASK' ) ) / 2 );
|
||||
|
||||
return this.__self.$( '_TCOLORS' )[ tunnel_id ] || 'black';
|
||||
},
|
||||
|
@ -311,9 +311,10 @@ module.exports = Class( 'ClassicMap' )
|
|||
*/
|
||||
'public getMapDifficulty': function()
|
||||
{
|
||||
var val = this._getDataSegment( '_DIFFSIZE', false ),
|
||||
i = val.length,
|
||||
n = 0;
|
||||
const val = this._getDataSegment( '_DIFFSIZE', false );
|
||||
|
||||
let i = val.length,
|
||||
n = 0;
|
||||
|
||||
// first, convert the value to an integer (from little-endian)
|
||||
while ( i-- ) n += ( val.charCodeAt( i ) << ( 8 * i ) );
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* specs, as it depends on FileReader.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
const Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -100,12 +100,12 @@ module.exports = Class( 'FileLoader',
|
|||
*/
|
||||
'private _loadFile': function( event )
|
||||
{
|
||||
var _self = this,
|
||||
files = event.target.files;
|
||||
const _self = this,
|
||||
files = event.target.files;
|
||||
|
||||
if ( files.length === 0 ) return;
|
||||
|
||||
var reader = new FileReader();
|
||||
const reader = new FileReader();
|
||||
reader.onload = function( revent )
|
||||
{
|
||||
_self._callback.call( this.__inst, null, revent.target.result );
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
const Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
const Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
module.exports = Interface( 'GameObjectFactory',
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
* identify the file as a bitmap image.)
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
const Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ module.exports = Class( 'LtgLoader',
|
|||
*/
|
||||
'public fromString': function( ltg_data )
|
||||
{
|
||||
var mask_offset = this._getMaskOffsetFromData( ltg_data );
|
||||
const mask_offset = this._getMaskOffsetFromData( ltg_data );
|
||||
|
||||
return {
|
||||
name: this._getNameFromData( ltg_data ),
|
||||
|
@ -112,7 +112,7 @@ module.exports = Class( 'LtgLoader',
|
|||
sgmt = this.__self.$( sgmt );
|
||||
}
|
||||
|
||||
var data = String.prototype.substr.apply( ltg_data, sgmt );
|
||||
const data = String.prototype.substr.apply( ltg_data, sgmt );
|
||||
|
||||
return ( stripnull )
|
||||
? data.split( '\x00' )[ 0 ]
|
||||
|
@ -187,8 +187,9 @@ module.exports = Class( 'LtgLoader',
|
|||
// grab the data and don't bother stripping off the null bytes (it would
|
||||
// function the same with them stripped, but let's avoid the confusion
|
||||
// since we are supposed to be working with a 32-bit value)
|
||||
var data = this._getDataSegment( ltg_data, '_POS_MOFF', false ),
|
||||
i = data.length,
|
||||
const data = this._getDataSegment( ltg_data, '_POS_MOFF', false );
|
||||
|
||||
let i = data.length,
|
||||
offset = 0;
|
||||
|
||||
// convert the DWORD entry (little-endian format, 32-bit) into an
|
||||
|
@ -234,7 +235,7 @@ module.exports = Class( 'LtgLoader',
|
|||
*/
|
||||
'private _getGameBitmap': function( ltg_data, mask_offset )
|
||||
{
|
||||
var bmp_offset = this.__self.$( '_OFFSET_HEADER_END' );
|
||||
const bmp_offset = this.__self.$( '_OFFSET_HEADER_END' );
|
||||
|
||||
// return the bitmap data up until the mask offset
|
||||
return ltg_data.substr( bmp_offset, ( mask_offset - bmp_offset ) );
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* tunnel identified by index 0 is 0x40, index 1 is 0x42, and so on.
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
const Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapBounds = require( './MapBounds' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
MapBounds = require( './MapBounds' );
|
||||
|
||||
|
||||
module.exports = Class( 'MapAction',
|
||||
|
@ -57,7 +57,7 @@ module.exports = Class( 'MapAction',
|
|||
|
||||
'public move': function()
|
||||
{
|
||||
var method = [
|
||||
const method = [
|
||||
'getLeftPos',
|
||||
'getUpperPos',
|
||||
'getRightPos',
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
Map = require( './Map' );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,8 @@ module.exports = Class( 'MapBounds',
|
|||
}
|
||||
|
||||
// we are only interested in the dimensions of the map
|
||||
var dimen = map.getDimensions();
|
||||
const dimen = map.getDimensions();
|
||||
|
||||
this._mw = dimen[ 0 ];
|
||||
this._mh = dimen[ 1 ];
|
||||
},
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapState = require( './MapState' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
MapState = require( './MapState' );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -97,8 +97,8 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _lockCanvas': function()
|
||||
{
|
||||
var o = this._ctx,
|
||||
l = this.__self.$( '_LOCK' );
|
||||
const o = this._ctx,
|
||||
l = this.__self.$( '_LOCK' );
|
||||
|
||||
// simple one-line check to both set the lock and fail if the lock is
|
||||
// already set (implying that something else is already rendering to the
|
||||
|
@ -127,7 +127,7 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'public freeCanvas': function()
|
||||
{
|
||||
var c = this._ctxObj.canvas;
|
||||
const c = this._ctxObj.canvas;
|
||||
|
||||
// clear any running animations
|
||||
this._clearAnimation();
|
||||
|
@ -148,8 +148,8 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _getObjCanvas': function()
|
||||
{
|
||||
var canvas = this._ctx.canvas,
|
||||
canvas_obj = document.createElement( 'canvas' );
|
||||
const canvas = this._ctx.canvas,
|
||||
canvas_obj = document.createElement( 'canvas' );
|
||||
|
||||
// mimic the dimensions and positions of the original canvas
|
||||
canvas_obj.style.position = 'absolute';
|
||||
|
@ -179,33 +179,31 @@ module.exports = Class( 'MapRender',
|
|||
throw TypeError( 'Invalid MapState provided' );
|
||||
}
|
||||
|
||||
var objs = map.getObjects(),
|
||||
size = map.getDimensions(),
|
||||
omap = map.getObjectTileMap(),
|
||||
sizex = size[ 0 ],
|
||||
sizey = size[ 1 ],
|
||||
i = objs.length,
|
||||
const objs = map.getObjects(),
|
||||
size = map.getDimensions(),
|
||||
sizex = size[ 0 ],
|
||||
sizey = size[ 1 ],
|
||||
|
||||
// tiles to animate
|
||||
anim = [],
|
||||
// tiles to animate
|
||||
anim = [],
|
||||
|
||||
// get the width and height from one of the tiles
|
||||
t = this._tiles.dirt.data,
|
||||
w = t.width,
|
||||
h = t.height;
|
||||
// get the width and height from one of the tiles
|
||||
t = this._tiles.dirt.data,
|
||||
w = t.width,
|
||||
h = t.height;
|
||||
|
||||
this._clearCanvases();
|
||||
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
map_state.onChange( function( obj, pos )
|
||||
{
|
||||
var oid = objs[ pos ],
|
||||
tid = ( obj ) ? obj.getTid() : 'dirt',
|
||||
tile = ( _self._tiles[ tid ] || {} ).first,
|
||||
const oid = objs[ pos ],
|
||||
tid = ( obj ) ? obj.getTid() : 'dirt',
|
||||
tile = ( _self._tiles[ tid ] || {} ).first,
|
||||
|
||||
v = _self._getTileVector( pos, sizex, sizey, w, h ),
|
||||
x = v[ 0 ],
|
||||
y = v[ 1 ];
|
||||
v = _self._getTileVector( pos, sizex, sizey, w, h ),
|
||||
x = v[ 0 ],
|
||||
y = v[ 1 ];
|
||||
|
||||
if ( obj === null )
|
||||
{
|
||||
|
@ -280,8 +278,8 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _clearCanvases': function()
|
||||
{
|
||||
var ctx = this._ctxObj,
|
||||
c = ctx.canvas;
|
||||
const ctx = this._ctxObj,
|
||||
c = ctx.canvas;
|
||||
|
||||
// we need only clear the overlay (to which masked tiles are rendered)
|
||||
ctx.clearRect( 0, 0, c.width, c.height );
|
||||
|
@ -297,7 +295,7 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _canAnimate': function( tid )
|
||||
{
|
||||
var tdata = this._tiles[ tid ];
|
||||
const tdata = this._tiles[ tid ];
|
||||
return ( tdata.next !== tdata );
|
||||
},
|
||||
|
||||
|
@ -317,7 +315,7 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _drawTile': function( tile, x, y )
|
||||
{
|
||||
var ctx = ( tile.masked ) ? this._ctxObj : this._ctx;
|
||||
const ctx = ( tile.masked ) ? this._ctxObj : this._ctx;
|
||||
|
||||
ctx.putImageData( tile.data, x, y );
|
||||
|
||||
|
@ -349,7 +347,7 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _renderTunnel': function( x, y, color )
|
||||
{
|
||||
var tdata = this._tiles.tunnel.data;
|
||||
const tdata = this._tiles.tunnel.data;
|
||||
|
||||
// fill tile with the appropriate background color for this tile
|
||||
this._ctx.fillStyle = color;
|
||||
|
@ -373,24 +371,24 @@ module.exports = Class( 'MapRender',
|
|||
*/
|
||||
'private _beginAnimation': function( anim )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
// clear any existing rendering animations
|
||||
this._clearAnimation();
|
||||
|
||||
return this._animTimer = setInterval( function()
|
||||
return ( this._animTimer = setInterval( function()
|
||||
{
|
||||
var i = anim.length;
|
||||
let i = anim.length;
|
||||
|
||||
while ( i-- )
|
||||
{
|
||||
var cur = anim[ i ];
|
||||
const cur = anim[ i ];
|
||||
|
||||
// draw next frame
|
||||
cur[ 0 ] = cur[ 0 ].next;
|
||||
_self._drawTile.apply( _self, anim[ i ] );
|
||||
}
|
||||
}, this.__self.$( '_ANIM_INTERVAL' ) );
|
||||
}, this.__self.$( '_ANIM_INTERVAL' ) ) );
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* file.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
const Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
|
||||
|
@ -85,7 +85,7 @@ module.exports = Class( 'MapSet',
|
|||
*/
|
||||
'private _mapDataCheck': function()
|
||||
{
|
||||
var n = ( this._data.length / this._mapCtor.getMapSize() );
|
||||
const n = ( this._data.length / this._mapCtor.getMapSize() );
|
||||
|
||||
// if the result is not an integer, then it is either not an LVL, the
|
||||
// file is corrupt, or we were given the wrong Map constructor
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
MapAction = require( './MapAction' ),
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
MapAction = require( './MapAction' ),
|
||||
GameObjectFactory = require( './GameObjectFactory' ),
|
||||
GameObject = require( './gameobjs/GameObject' );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,7 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'public flush': function()
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
// emit the change event for each game object
|
||||
this._forEachObj( function( obj, pos )
|
||||
|
@ -143,8 +143,8 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _emitChange': function( obj, pos )
|
||||
{
|
||||
var i = -1,
|
||||
l = this._stateCallbacks.length;
|
||||
const l = this._stateCallbacks.length;
|
||||
let i = -1;
|
||||
|
||||
while ( ++i < l )
|
||||
{
|
||||
|
@ -153,7 +153,7 @@ module.exports = Class( 'MapState',
|
|||
|
||||
if ( obj === null )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
this._objs[ pos ].forEach( function( o )
|
||||
{
|
||||
if ( o === null ) return;
|
||||
|
@ -178,12 +178,12 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _initObjects': function( objs, objmap )
|
||||
{
|
||||
var i = objs.length;
|
||||
let i = objs.length;
|
||||
|
||||
while ( i-- )
|
||||
{
|
||||
var val = objs[ i ],
|
||||
obj = this._createObj( objmap[ val ] );
|
||||
const val = objs[ i ],
|
||||
obj = this._createObj( objmap[ val ] );
|
||||
|
||||
this._objs[ i ] = [];
|
||||
this._addObj( obj, i );
|
||||
|
@ -214,7 +214,7 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _createObj': function( tid, from )
|
||||
{
|
||||
var obj = this._objFactory.createObject( tid );
|
||||
const obj = this._objFactory.createObject( tid );
|
||||
|
||||
// if a previous object was provided, copy over its mutable attributes
|
||||
if ( from )
|
||||
|
@ -301,8 +301,7 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _replaceObj': function( cur, newobj, pos )
|
||||
{
|
||||
var o = this._objs[ pos ],
|
||||
i = o.length;
|
||||
const o = this._objs[ pos ];
|
||||
|
||||
// type checks
|
||||
if ( !( Array.isArray( o ) ) )
|
||||
|
@ -316,29 +315,27 @@ module.exports = Class( 'MapState',
|
|||
throw TypeError( "Invalid GameObject or null provided: " + newobj );
|
||||
}
|
||||
|
||||
var free = null;
|
||||
let i = o.length,
|
||||
free = null;
|
||||
|
||||
( function()
|
||||
while ( i-- )
|
||||
{
|
||||
while ( i-- )
|
||||
if ( o[ i ] === cur )
|
||||
{
|
||||
if ( o[ i ] === cur )
|
||||
{
|
||||
o[ i ] = newobj;
|
||||
return;
|
||||
}
|
||||
else if ( o[ i ] === null )
|
||||
{
|
||||
// record this as a free position for additions
|
||||
free = i;
|
||||
}
|
||||
o[ i ] = newobj;
|
||||
return;
|
||||
}
|
||||
else if ( o[ i ] === null )
|
||||
{
|
||||
// record this as a free position for additions
|
||||
free = i;
|
||||
}
|
||||
}
|
||||
|
||||
// not found; add
|
||||
if ( newobj === null ) return;
|
||||
else if ( free ) o[ i ] = newobj;
|
||||
else o.push( newobj );
|
||||
} )();
|
||||
// not found; add
|
||||
if ( newobj === null ) return;
|
||||
else if ( free ) o[ i ] = newobj;
|
||||
else o.push( newobj );
|
||||
|
||||
// notify observers of the change
|
||||
this._emitChange( newobj, pos );
|
||||
|
@ -435,7 +432,7 @@ module.exports = Class( 'MapState',
|
|||
}
|
||||
|
||||
// replace game object with a new one
|
||||
var newobj = this._createObj( state, cur );
|
||||
const newobj = this._createObj( state, cur );
|
||||
this._replaceObj( cur, newobj, pos );
|
||||
|
||||
return newobj;
|
||||
|
@ -460,11 +457,11 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _createStateCallback': function( cur, pos, c )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
return function( state )
|
||||
{
|
||||
var newobj = _self._changeState( cur, state, pos );
|
||||
const newobj = _self._changeState( cur, state, pos );
|
||||
|
||||
if ( typeof c === 'function' )
|
||||
{
|
||||
|
@ -493,7 +490,7 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'private _createMoveCallback': function( obj, pos, c )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
return function( dest )
|
||||
{
|
||||
|
@ -523,11 +520,11 @@ module.exports = Class( 'MapState',
|
|||
*/
|
||||
'public movePlayer': function( direction, bounds )
|
||||
{
|
||||
var _self = this,
|
||||
player = this._player;
|
||||
const _self = this,
|
||||
player = this._player;
|
||||
|
||||
// XXX: tightly coupled
|
||||
var action = MapAction(
|
||||
const action = MapAction(
|
||||
bounds,
|
||||
this._createMoveCallback( player, this._playerPos, function( pos )
|
||||
{
|
||||
|
@ -535,10 +532,14 @@ module.exports = Class( 'MapState',
|
|||
} )
|
||||
);
|
||||
|
||||
var sc = this._createStateCallback( player, this._playerPos, function( o )
|
||||
{
|
||||
_self._player = o;
|
||||
} );
|
||||
const sc = this._createStateCallback(
|
||||
player,
|
||||
this._playerPos,
|
||||
function( o )
|
||||
{
|
||||
_self._player = o;
|
||||
}
|
||||
);
|
||||
|
||||
action.direction = direction;
|
||||
action.srcPos = this._playerPos;
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
* thinice - thin ice
|
||||
*/
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
const Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,8 +63,8 @@
|
|||
* rendering.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
TileDfn = require( './TileDfn' );
|
||||
|
||||
/**
|
||||
* Slices tiles and applies masks
|
||||
|
@ -137,7 +137,7 @@ module.exports = Class( 'TileMasker',
|
|||
// rather than accepting a context, we will create our own canvas in
|
||||
// memory to perform our operations (it will not be added to the DOM, so
|
||||
// these operations will not be visible to the user)
|
||||
var context = document.createElement( 'canvas' ).getContext( '2d' );
|
||||
let context = document.createElement( 'canvas' ).getContext( '2d' );
|
||||
|
||||
// size the canvas so that it can fit the entire tileset
|
||||
context.canvas.width = this._setWidth;
|
||||
|
@ -161,8 +161,8 @@ module.exports = Class( 'TileMasker',
|
|||
'private _calcSetDimensions': function( tile_dfn )
|
||||
{
|
||||
// these vars are for clarity
|
||||
var sizes = tile_dfn.getTileDimensions(),
|
||||
n = this._tileDfn.length;
|
||||
const sizes = tile_dfn.getTileDimensions(),
|
||||
n = this._tileDfn.length;
|
||||
|
||||
// store values so that we do not have to make additional calls to our
|
||||
// TileDfn instance
|
||||
|
@ -201,7 +201,7 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'public getMaskedTiles': function( bmp_game, bmp_mask, callback )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
this._getImageData( bmp_mask, function( data_mask )
|
||||
{
|
||||
|
@ -248,26 +248,27 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'virtual protected getMaskedTileSet': function( data_mask, callback )
|
||||
{
|
||||
var tdata = this._tileDfn,
|
||||
tiles = {},
|
||||
i = -1,
|
||||
len = tdata.length,
|
||||
const tdata = this._tileDfn,
|
||||
len = tdata.length,
|
||||
|
||||
// shorten the names
|
||||
tw = this._tileWidth,
|
||||
th = this._tileHeight,
|
||||
xn = this._tilesPerRow;
|
||||
// shorten the names
|
||||
tw = this._tileWidth,
|
||||
th = this._tileHeight,
|
||||
xn = this._tilesPerRow;
|
||||
|
||||
let tiles = {},
|
||||
i = -1;
|
||||
|
||||
// create each tile (preserving order, thus no decrementing)
|
||||
while ( ++i < len )
|
||||
{
|
||||
var id = tdata[ i ][ 0 ],
|
||||
mask = tdata[ i ][ 1 ],
|
||||
const id = tdata[ i ][ 0 ],
|
||||
mask = tdata[ i ][ 1 ];
|
||||
|
||||
// calculate the X and Y position of this tile based on the tile
|
||||
// and bitmap dimensions
|
||||
x = ( ( i % xn ) * th ),
|
||||
y = ( ( Math.floor( i / xn ) ) * tw );
|
||||
// calculate the X and Y position of this tile based on the tile
|
||||
// and bitmap dimensions
|
||||
const x = ( ( i % xn ) * th ),
|
||||
y = ( ( Math.floor( i / xn ) ) * tw );
|
||||
|
||||
// the third index indicates whether or not a mask should be applied
|
||||
// to the tile
|
||||
|
@ -297,7 +298,7 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'protected appendTileFrame': function( set, id, mask, data )
|
||||
{
|
||||
var prev = set[ id ];
|
||||
const prev = set[ id ];
|
||||
|
||||
set[ id ] = {
|
||||
data: data,
|
||||
|
@ -314,7 +315,7 @@ module.exports = Class( 'TileMasker',
|
|||
|
||||
// if there was a previous entry, set its 'next' entry to our new frame,
|
||||
// expanding the linked list
|
||||
prev && ( prev.next = set[ id ] )
|
||||
if ( prev ) prev.next = set[ id ];
|
||||
},
|
||||
|
||||
|
||||
|
@ -347,18 +348,19 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'virtual protected getMaskedTileData': function( data_mask, x, y )
|
||||
{
|
||||
var raw = this.getTileData( x, y ),
|
||||
w = raw.width,
|
||||
h = raw.height,
|
||||
mw = data_mask.width,
|
||||
yi = h;
|
||||
const raw = this.getTileData( x, y ),
|
||||
w = raw.width,
|
||||
h = raw.height,
|
||||
mw = data_mask.width;
|
||||
|
||||
let yi = h;
|
||||
|
||||
// apply the mask to the raw tile data (simple and easy-to-understand
|
||||
// algorithm; we can refine it later if need be), looping through each
|
||||
// pixel
|
||||
while ( yi-- )
|
||||
{
|
||||
xi = w;
|
||||
let xi = w;
|
||||
|
||||
while ( xi-- )
|
||||
{
|
||||
|
@ -366,8 +368,8 @@ module.exports = Class( 'TileMasker',
|
|||
// (remember that, although we are dealing with applying the
|
||||
// mask to a single tile, the mask image contains all tiles, so
|
||||
// we must calculate its position accordingly)
|
||||
var mi = ( ( ( yi + y ) * ( mw * 4 ) ) + ( ( xi + x ) * 4 ) ),
|
||||
mr = data_mask.data[ mi ];
|
||||
const mi = ( ( ( yi + y ) * ( mw * 4 ) ) + ( ( xi + x ) * 4 ) ),
|
||||
mr = data_mask.data[ mi ];
|
||||
|
||||
// manipulate the alpha channel of our tile; if the R value for
|
||||
// the mask is not 0, then this pixel in our tile should be
|
||||
|
@ -414,8 +416,8 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'private _renderImage': function( bmp, callback )
|
||||
{
|
||||
var _self = this,
|
||||
img = new Image();
|
||||
const _self = this,
|
||||
img = new Image();
|
||||
|
||||
img.onload = function()
|
||||
{
|
||||
|
@ -437,7 +439,7 @@ module.exports = Class( 'TileMasker',
|
|||
*/
|
||||
'private _getImageData': function( bmp, callback )
|
||||
{
|
||||
var _self = this;
|
||||
const _self = this;
|
||||
|
||||
this._renderImage( bmp, function()
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
const Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
module.exports = Class( 'GameObject',
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
GameObject = require( './GameObject' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
GameObject = require( './GameObject' );
|
||||
|
||||
|
||||
module.exports = Class( 'Tank' )
|
||||
|
@ -26,12 +26,12 @@ module.exports = Class( 'Tank' )
|
|||
{
|
||||
'override public move': function( direction, c, sc )
|
||||
{
|
||||
var state = [ 'tleft', 'tup', 'tright', 'tdown' ][ direction ];
|
||||
const state = [ 'tleft', 'tup', 'tright', 'tdown' ][ direction ];
|
||||
|
||||
if ( state !== this.getTid() )
|
||||
{
|
||||
sc( state );
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
|
||||
// let parent handle the movement
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class,
|
||||
Tank = require( '../Tank' );
|
||||
const Class = require( 'easejs' ).Class,
|
||||
Tank = require( '../Tank' );
|
||||
|
||||
|
||||
module.exports = Class( 'TankDown' )
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
const Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -68,16 +68,15 @@ module.exports = Class( 'MenuBar',
|
|||
*/
|
||||
'private _initMenuActivation': function()
|
||||
{
|
||||
var _self = this,
|
||||
id = this._bar.id,
|
||||
menus = this._bar.parentNode.querySelectorAll( '#'+id+' > li > a' ),
|
||||
i = menus.length,
|
||||
const id = this._bar.id,
|
||||
menus = this._bar.parentNode.querySelectorAll( '#'+id+' > li > a' ),
|
||||
click = function( event )
|
||||
{
|
||||
event.target.parentNode.parentNode.className += ' focus';
|
||||
return false;
|
||||
};
|
||||
|
||||
click = function( event )
|
||||
{
|
||||
event.target.parentNode.parentNode.className += ' focus';
|
||||
return false;
|
||||
};
|
||||
let i = menus.length;
|
||||
|
||||
// on menu click, apply focus class (this allows the menu to be opened
|
||||
// properly on click rather than a simple CSS hover menu)
|
||||
|
@ -103,8 +102,8 @@ module.exports = Class( 'MenuBar',
|
|||
*/
|
||||
'private _hookMenuMouseOut': function()
|
||||
{
|
||||
var _self = this,
|
||||
bar = this._bar;
|
||||
const _self = this,
|
||||
bar = this._bar;
|
||||
|
||||
this._bar.addEventListener( 'mouseout', function( event )
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var major = @MAJOR@,
|
||||
let major = @MAJOR@,
|
||||
minor = @MINOR@,
|
||||
rev = @REV@,
|
||||
suffix = '@SUFFIX@',
|
||||
|
|
Loading…
Reference in New Issue