diff --git a/app/Game/Client/GameObjects/Item.js b/app/Game/Client/GameObjects/Item.js index c8a7a46..e96a1b6 100755 --- a/app/Game/Client/GameObjects/Item.js +++ b/app/Game/Client/GameObjects/Item.js @@ -8,8 +8,8 @@ define([ function (Parent, Settings, Nc, Layer) { function Item(physicsEngine, uid, options) { - Parent.call(this, physicsEngine, uid, options); this.layerId = Layer.ID.ITEM; + Parent.call(this, physicsEngine, uid, options); } Item.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/GameObjects/Tile.js b/app/Game/Client/GameObjects/Tile.js index 12bdfc3..90f3d40 100755 --- a/app/Game/Client/GameObjects/Tile.js +++ b/app/Game/Client/GameObjects/Tile.js @@ -8,8 +8,8 @@ define([ function (Parent, Settings, Nc, Layer) { function Tile(physicsEngine, uid, options) { - Parent.call(this, physicsEngine, uid, options); this.layerId = Layer.ID.TILE; + Parent.call(this, physicsEngine, uid, options); } Tile.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/Loader/Level.js b/app/Game/Client/Loader/Level.js index a17da02..7f491bb 100755 --- a/app/Game/Client/Loader/Level.js +++ b/app/Game/Client/Loader/Level.js @@ -89,13 +89,14 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) { }; Level.prototype.createItems = function(options) { - options.layer = AbstractLayer.ID.ITEM; - Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layer, 1, AbstractLayer.ID.SPAWN, true); + options.layerId = AbstractLayer.ID.ITEM; + Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true); Parent.prototype.createItems.call(this, options); }; Level.prototype.createTiles = function(options) { + console.log('client level createTiles'); options.layerId = AbstractLayer.ID.TILE; Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true); @@ -106,7 +107,7 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) { options.layerId = AbstractLayer.ID.SPAWN; Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1); - Parent.prototype.createTiles.call(this, options); + Parent.prototype.createSpawnPoints.call(this, options); }; return Level; diff --git a/app/Game/Client/Loader/TiledLevel.js b/app/Game/Client/Loader/TiledLevel.js index 9e1ce00..e930f01 100644 --- a/app/Game/Client/Loader/TiledLevel.js +++ b/app/Game/Client/Loader/TiledLevel.js @@ -6,8 +6,8 @@ define([ function (Parent, Settings) { function TiledLevel(uid, engine, gameObjects) { - Parent.call(this, uid, engine, gameObjects); this.layerId = "background"; + Parent.call(this, uid, engine, gameObjects); } TiledLevel.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/View/LayerManager.js b/app/Game/Client/View/LayerManager.js index c56d0e6..a128e16 100644 --- a/app/Game/Client/View/LayerManager.js +++ b/app/Game/Client/View/LayerManager.js @@ -6,9 +6,9 @@ define([ function (Nc, Exception, Layer) { - function LayerManager(stage) { + function LayerManager(container) { this.layers = []; - this.stage = stage; + this.container = container; this.ncTokens = [ Nc.on(Nc.ns.client.view.layer.createAndInsert, this.createAndInsert, this), @@ -40,14 +40,37 @@ function (Nc, Exception, Layer) { throw new Exception('Reference Layer (' + referenceId + ') could not be found'); } } else { - referenceIndex = behind ? 0 : this.stage.children.length; + referenceIndex = behind ? 0 : this.container.children.length; } var layer = new Layer(id, parallaxSpeed); var layerIndex = behind ? referenceIndex -1 : referenceIndex; this.layers.splice(layerIndex, 0, layer); - this.stage.addChildAt(layer.getContainer(), layerIndex); + + this.rearrangeLayers(); + }; + + LayerManager.prototype.rearrangeLayers = function() { + + var layer; + + for (var i = this.layers.length - 1; i >= 0; i--) { + layer = this.layers[i]; + if (this.container.children.indexOf(layer.getContainer()) !== -1) { + this.container.removeChild(layer.getContainer()); + } + }; + + if (this.container.children.length !== 0) { + console.warn('Unmanaged stuff in container... ', this.container.children); + //throw new Exception('Unmanaged dirt in container... '); + } + + for (var i = 0; i < this.layers.length; i++) { + layer = this.layers[i]; + this.container.addChildAt(layer.getContainer(), i); + }; }; LayerManager.prototype.getLayerById = function(id) { @@ -57,42 +80,59 @@ function (Nc, Exception, Layer) { return layer; } }; - throw new Exception('No such layer: ' + id); + return null; }; - LayerManager.prototype.delegate = function(methodName, layerId) { + LayerManager.prototype.delegate = function() { + var methodName = arguments[0]; + var layerId = arguments[1]; var layer = this.getLayerById(layerId); - var args = Array.prototype.splice.call(arguments, 0, 2); + + if (!layer) { + throw new Exception('Layer (' + layerId + ') does not exist.'); + } + + var args = arguments; + Array.prototype.splice.call(args, 0, 2); layer[methodName].apply(layer, args); }; LayerManager.prototype.createMesh = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createMesh')); + var args = arguments; + Array.prototype.splice.call(args, 0, 0, 'createMesh') + + this.delegate.apply(this, args); }; LayerManager.prototype.createAnimatedMesh = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createAnimatedMesh')); + Array.prototype.splice.call(arguments, 0, 0, 'createAnimatedMesh') + this.delegate.apply(this, arguments); }; LayerManager.prototype.addMesh = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addMesh')); + Array.prototype.splice.call(arguments, 0, 0, 'addMesh') + this.delegate.apply(this, arguments); }; LayerManager.prototype.removeMesh = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeMesh')); + Array.prototype.splice.call(arguments, 0, 0, 'removeMesh') + this.delegate.apply(this, arguments); }; LayerManager.prototype.updateMesh = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'updateMesh')); + Array.prototype.splice.call(arguments, 0, 0, 'updateMesh') + this.delegate.apply(this, arguments); }; LayerManager.prototype.addFilter = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addFilter')); + Array.prototype.splice.call(arguments, 0, 0, 'addFilter') + this.delegate.apply(this, arguments); }; LayerManager.prototype.removeFilter = function() { - this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeFilter')); + Array.prototype.splice.call(arguments, 0, 0, 'removeFilter') + this.delegate.apply(this, arguments); }; LayerManager.prototype.destroy = function() { diff --git a/app/Game/Client/View/Pixi/Layer.js b/app/Game/Client/View/Pixi/Layer.js index e416ebb..9f61633 100644 --- a/app/Game/Client/View/Pixi/Layer.js +++ b/app/Game/Client/View/Pixi/Layer.js @@ -1,13 +1,23 @@ define([ "Game/Client/View/Abstract/Layer", "Lib/Vendor/Pixi", + "Game/Client/View/Pixi/ColorRangeReplaceFilter", ], -function (Parent, PIXI) { +function (Parent, PIXI, ColorRangeReplaceFilter) { + + var AVAILABLE_MESH_FILTERS = { + "blur": PIXI.BlurFilter, + "desaturate": PIXI.GrayFilter, + "pixelate": PIXI.PixelateFilter, + "colorRangeReplace": ColorRangeReplaceFilter, + }; function Layer (name, parallaxSpeed) { Parent.call(this, name, parallaxSpeed); this.container = new PIXI.DisplayObjectContainer(); + this.container.x = 0; + this.container.y = 0; } Layer.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/View/Pixi/View.js b/app/Game/Client/View/Pixi/View.js index 466db45..19de504 100755 --- a/app/Game/Client/View/Pixi/View.js +++ b/app/Game/Client/View/Pixi/View.js @@ -2,7 +2,6 @@ define([ "Game/Client/View/Abstract/View", "Game/Client/View/DomController", "Lib/Vendor/Pixi", - "Game/Client/View/Pixi/ColorRangeReplaceFilter", "Game/Config/Settings", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Exception", @@ -10,14 +9,7 @@ define([ "Game/Client/View/LayerManager", ], -function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Exception, GameStats, LayerManager) { - - var AVAILABLE_MESH_FILTERS = { - "blur": PIXI.BlurFilter, - "desaturate": PIXI.GrayFilter, - "pixelate": PIXI.PixelateFilter, - "colorRangeReplace": ColorRangeReplaceFilter, - }; +function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager) { function PixiView () { @@ -56,9 +48,10 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex this.stage = new PIXI.Stage(0x333333); - this.layerManager = new LayerManager(this.stage); - this.initCamera(); + + this.layerManager = new LayerManager(this.container); + this.initLoader(); this.initCanvas(this.renderer.view); diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index 3033dab..7c450a5 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -52,6 +52,7 @@ define([ }; TiledLevel.prototype.createTiles = function(options) { + console.log('core tiledlevel createTiles'); var data = options.data; var tilesOptions = [];