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