1
0
Fork 0

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
Mike Gerwitz 2015-12-20 23:34:50 -05:00
parent 93f3008740
commit 47e022b555
24 changed files with 219 additions and 190 deletions

20
.jshintrc 100644
View File

@ -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
}

View File

@ -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:

View File

@ -20,7 +20,8 @@
"devDependencies": {
"chai": ">=1.9.1",
"mocha": ">=1.18.2",
"browserify": "~12"
"browserify": "~12",
"strictify": "~0.2"
},
"licenses": [

View File

@ -18,7 +18,7 @@
*/
var Class = require( 'easejs' ).Class,
const Class = require( 'easejs' ).Class,
Game = require( './Game' ),
ClassicGameObjectFactory = require( './ClassicGameObjectFactory' ),
ClassicMap = require( './ClassicMap' ),
@ -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,7 +127,7 @@ module.exports = Class( 'ClassicGame' )
this._render.clearCanvas();
}
var map = this._mapSet.getMapByNumber( 1 ),
const map = this._mapSet.getMapByNumber( 1 ),
map_state = MapState( map, this._gameObjFactory ),
bounds = MapBounds( map );
@ -138,7 +138,7 @@ module.exports = Class( 'ClassicGame' )
// POC
window.onkeydown = function( event )
{
var dir;
let dir;
switch ( event.keyCode )
{
@ -171,7 +171,7 @@ module.exports = Class( 'ClassicGame' )
'public setTileData': function( data, callback )
{
// get tile metadata
var _self = this,
const _self = this,
meta = this._ltgLoader.fromString( data );
this._masker.getMaskedTiles( meta.tiles, meta.mask, function( tdata )

View File

@ -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,
GameObjectFactory = require( './GameObjectFactory' ),
GameObject = require( './gameobjs/GameObject' ),
Tank = require( './gameobjs/Tank' );

View File

@ -40,7 +40,7 @@
* display.
*/
var Class = require( 'easejs' ).Class,
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,7 +192,7 @@ module.exports = Class( 'ClassicMap' )
{
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 ] );
return ( stripnull )
@ -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,8 +311,9 @@ module.exports = Class( 'ClassicMap' )
*/
'public getMapDifficulty': function()
{
var val = this._getDataSegment( '_DIFFSIZE', false ),
i = val.length,
const val = this._getDataSegment( '_DIFFSIZE', false );
let i = val.length,
n = 0;
// first, convert the value to an integer (from little-endian)

View File

@ -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,
TileDfn = require( './TileDfn' );

View File

@ -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,
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 );

View File

@ -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;
/**

View File

@ -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',

View File

@ -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 ) );

View File

@ -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;
/**

View File

@ -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,
MapBounds = require( './MapBounds' );
@ -57,7 +57,7 @@ module.exports = Class( 'MapAction',
'public move': function()
{
var method = [
const method = [
'getLeftPos',
'getUpperPos',
'getRightPos',

View File

@ -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,
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 ];
},

View File

@ -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,
MapState = require( './MapState' );
@ -97,7 +97,7 @@ module.exports = Class( 'MapRender',
*/
'private _lockCanvas': function()
{
var o = this._ctx,
const o = this._ctx,
l = this.__self.$( '_LOCK' );
// 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()
{
var c = this._ctxObj.canvas;
const c = this._ctxObj.canvas;
// clear any running animations
this._clearAnimation();
@ -148,7 +148,7 @@ module.exports = Class( 'MapRender',
*/
'private _getObjCanvas': function()
{
var canvas = this._ctx.canvas,
const canvas = this._ctx.canvas,
canvas_obj = document.createElement( 'canvas' );
// mimic the dimensions and positions of the original canvas
@ -179,12 +179,10 @@ module.exports = Class( 'MapRender',
throw TypeError( 'Invalid MapState provided' );
}
var objs = map.getObjects(),
const objs = map.getObjects(),
size = map.getDimensions(),
omap = map.getObjectTileMap(),
sizex = size[ 0 ],
sizey = size[ 1 ],
i = objs.length,
// tiles to animate
anim = [],
@ -196,10 +194,10 @@ module.exports = Class( 'MapRender',
this._clearCanvases();
var _self = this;
const _self = this;
map_state.onChange( function( obj, pos )
{
var oid = objs[ pos ],
const oid = objs[ pos ],
tid = ( obj ) ? obj.getTid() : 'dirt',
tile = ( _self._tiles[ tid ] || {} ).first,
@ -280,7 +278,7 @@ module.exports = Class( 'MapRender',
*/
'private _clearCanvases': function()
{
var ctx = this._ctxObj,
const ctx = this._ctxObj,
c = ctx.canvas;
// we need only clear the overlay (to which masked tiles are rendered)
@ -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' ) ) );
},

View File

@ -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

View File

@ -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,
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,11 +178,11 @@ module.exports = Class( 'MapState',
*/
'private _initObjects': function( objs, objmap )
{
var i = objs.length;
let i = objs.length;
while ( i-- )
{
var val = objs[ i ],
const val = objs[ i ],
obj = this._createObj( objmap[ val ] );
this._objs[ 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,10 +315,9 @@ module.exports = Class( 'MapState',
throw TypeError( "Invalid GameObject or null provided: " + newobj );
}
var free = null;
let i = o.length,
free = null;
( function()
{
while ( i-- )
{
if ( o[ i ] === cur )
@ -338,7 +336,6 @@ module.exports = Class( 'MapState',
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,
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 )
const sc = this._createStateCallback(
player,
this._playerPos,
function( o )
{
_self._player = o;
} );
}
);
action.direction = direction;
action.srcPos = this._playerPos;

View File

@ -75,7 +75,7 @@
* thinice - thin ice
*/
var Interface = require( 'easejs' ).Interface;
const Interface = require( 'easejs' ).Interface;
/**

View File

@ -63,7 +63,7 @@
* rendering.
*/
var Class = require( 'easejs' ).Class,
const Class = require( 'easejs' ).Class,
TileDfn = require( './TileDfn' );
/**
@ -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,7 +161,7 @@ module.exports = Class( 'TileMasker',
'private _calcSetDimensions': function( tile_dfn )
{
// these vars are for clarity
var sizes = tile_dfn.getTileDimensions(),
const sizes = tile_dfn.getTileDimensions(),
n = this._tileDfn.length;
// 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 )
{
var _self = this;
const _self = this;
this._getImageData( bmp_mask, function( data_mask )
{
@ -248,9 +248,7 @@ module.exports = Class( 'TileMasker',
*/
'virtual protected getMaskedTileSet': function( data_mask, callback )
{
var tdata = this._tileDfn,
tiles = {},
i = -1,
const tdata = this._tileDfn,
len = tdata.length,
// shorten the names
@ -258,15 +256,18 @@ module.exports = Class( 'TileMasker',
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 ),
const x = ( ( i % xn ) * th ),
y = ( ( Math.floor( i / xn ) ) * tw );
// 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 )
{
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 ),
const raw = this.getTileData( x, y ),
w = raw.width,
h = raw.height,
mw = data_mask.width,
yi = h;
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,7 +368,7 @@ 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 ) ),
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
@ -414,7 +416,7 @@ module.exports = Class( 'TileMasker',
*/
'private _renderImage': function( bmp, callback )
{
var _self = this,
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()
{

View File

@ -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',

View File

@ -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,
GameObject = require( './GameObject' );
@ -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

View File

@ -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,
Tank = require( '../Tank' );

View File

@ -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,17 +68,16 @@ module.exports = Class( 'MenuBar',
*/
'private _initMenuActivation': function()
{
var _self = this,
id = this._bar.id,
const id = this._bar.id,
menus = this._bar.parentNode.querySelectorAll( '#'+id+' > li > a' ),
i = menus.length,
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)
while ( i-- )
@ -103,7 +102,7 @@ module.exports = Class( 'MenuBar',
*/
'private _hookMenuMouseOut': function()
{
var _self = this,
const _self = this,
bar = this._bar;
this._bar.addEventListener( 'mouseout', function( event )

View File

@ -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@',