From 93b61596b33bcad9ffd557b4f8bfa273d5237ed9 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 22 Dec 2015 23:45:00 -0500 Subject: [PATCH] Decouple TileMasker from window.document --- scripts/game.js | 2 +- src/ClassicGame.js | 9 +++++++-- src/TileMasker.js | 8 ++++++-- test/ltgloader-demo.html | 5 ++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/game.js b/scripts/game.js index d2dde29..ca3eba6 100644 --- a/scripts/game.js +++ b/scripts/game.js @@ -66,7 +66,7 @@ function gamechk() // temporary if ( ele_game.className.search( 'opening' ) > -1 ) return; - lasertank.ClassicGame( ltg_data, lvl_data ) + lasertank.ClassicGame( document, ltg_data, lvl_data ) .on( 'ready', function() { this.renderTo( ctx, window ); diff --git a/src/ClassicGame.js b/src/ClassicGame.js index 6324e4b..ac6adb6 100644 --- a/src/ClassicGame.js +++ b/src/ClassicGame.js @@ -88,15 +88,20 @@ module.exports = Class( 'ClassicGame' ) * the constructor because they are needed in order for the game to be * functional. * + * DOCUMENT is used internally for creating elements; the DOM will not + * be manipulated. + * + * @param {HTMLDocument} document DOM document + * * @param {string} ltg_data binary string containing LTG file data * @param {string} lvl_data binary string containing LVL file data */ - __construct: function( ltg_data, lvl_data ) + __construct: function( document, ltg_data, lvl_data ) { const _self = this; this._ltgLoader = LtgLoader(); - this._masker = TileMasker( ClassicTileDfn() ); + this._masker = TileMasker( ClassicTileDfn(), document ); this._gameObjFactory = ClassicGameObjectFactory(); diff --git a/src/TileMasker.js b/src/TileMasker.js index 8f76c8f..4bd93d3 100644 --- a/src/TileMasker.js +++ b/src/TileMasker.js @@ -121,9 +121,13 @@ module.exports = Class( 'TileMasker', * allows us to support *any* type of tile set -- not just those that are * defined by the original game. * - * @param {TileDfn} tile_dfn tile definition object + * DOCUMENT is used internally for creating elements; the DOM will not + * be manipulated. + * + * @param {TileDfn} tile_dfn tile definition object + * @param {HTMLDocument} document DOM document */ - __construct: function( tile_dfn ) + __construct: function( tile_dfn, document ) { if ( !( Class.isA( TileDfn, tile_dfn ) ) ) { diff --git a/test/ltgloader-demo.html b/test/ltgloader-demo.html index e16b965..0808e71 100644 --- a/test/ltgloader-demo.html +++ b/test/ltgloader-demo.html @@ -104,8 +104,11 @@ reader.onload = function( event ) { var loader = lasertank.LtgLoader(), - masker = lasertank.TileMasker( lasertank.ClassicTileDfn() ), meta = loader.fromString( event.target.result ), + masker = lasertank.TileMasker( + lasertank.ClassicTileDfn(), + document + ), bmp_game = document.getElementById( 'bmp_game' ), bmp_mask = document.getElementById( 'bmp_mas' );