From 222fd09f3f7c9fbf7595a7da4c257bcfba5272d2 Mon Sep 17 00:00:00 2001 From: Jeena Date: Sat, 30 Aug 2014 16:27:05 +0200 Subject: [PATCH] non working layers --- app/Game/Client/GameObjects/Doll.js | 40 ++++++++++++-------- app/Game/Client/GameObjects/Item.js | 13 +++++-- app/Game/Client/GameObjects/Items/RagDoll.js | 14 +++++-- app/Game/Client/GameObjects/Tile.js | 12 ++++-- app/Game/Client/Loader/TiledLevel.js | 3 ++ app/Game/Client/View/LayerManager.js | 3 +- app/Lib/Utilities/Exception.js | 3 +- 7 files changed, 58 insertions(+), 30 deletions(-) diff --git a/app/Game/Client/GameObjects/Doll.js b/app/Game/Client/GameObjects/Doll.js index 19fd078..69695ed 100755 --- a/app/Game/Client/GameObjects/Doll.js +++ b/app/Game/Client/GameObjects/Doll.js @@ -3,12 +3,14 @@ define([ "Game/Config/Settings", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Exception", - "Lib/Utilities/ColorConverter" + "Lib/Utilities/ColorConverter", + "Game/Client/View/Abstract/Layer", ], -function (Parent, Settings, Nc, Exception, ColorConverter) { +function (Parent, Settings, Nc, Exception, ColorConverter, Layer) { - function Doll(physicsEngine, uid, player) { + function Doll(physicsEngine, uid, player) { + this.layerId = Layer.ID.SPAWN; this.animationDef = { "stand": [1,1], "walk": [2,28], @@ -46,11 +48,13 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { if(this.animatedMeshes[this.actionState]) { Nc.trigger( Nc.ns.client.view.mesh.update, + this.layerId, this.animatedMeshesContainer.withArms[this.actionState], { visible: false } ); Nc.trigger( Nc.ns.client.view.mesh.update, + this.layerId, this.animatedMeshesContainer.withoutArms[this.actionState], { visible: false } ); @@ -60,6 +64,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { Nc.trigger( Nc.ns.client.view.mesh.update, + this.layerId, this.animatedMeshes[this.actionState], { visible: true, @@ -73,7 +78,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { var self = this; var setShirtColor = function (mesh) { - Nc.trigger(Nc.ns.client.view.mesh.addFilter, mesh, 'colorRangeReplace', { + Nc.trigger(Nc.ns.client.view.mesh.addFilter, self.layerId, mesh, 'colorRangeReplace', { minColor: 0x3b4a31, maxColor: 0x657f54, newColor: self.primaryColor, @@ -112,12 +117,12 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { var callback = function(mesh) { self.animatedMeshesContainer[arm][key] = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); setShirtColor(mesh); }; - Nc.trigger(Nc.ns.client.view.animatedMesh.create, texturePaths, callback, { + Nc.trigger(Nc.ns.client.view.animatedMesh.create, this.layerId, texturePaths, callback, { visible: false, pivot: { x: 35/2 * 4, @@ -135,9 +140,9 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png"; var callback = function (mesh) { self.headMesh = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); } - Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, { + Nc.trigger(Nc.ns.client.view.mesh.create, this.layerId, texturePath, callback, { pivot: { x: 5, y: 12 @@ -151,11 +156,10 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/holdingArm.png"; var callback = function (mesh) { self.holdingArmMesh = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); - + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); setShirtColor(mesh); } - Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, { + Nc.trigger(Nc.ns.client.view.mesh.create, this.layerId, texturePath, callback, { visible: false, pivot: { x: 35/2 * 4, @@ -175,6 +179,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { if(oldLookDirection != this.lookDirection) { for(var key in this.animatedMeshes) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.animatedMeshes[key], { xScale: this.lookDirection @@ -183,6 +188,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { } Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.holdingArmMesh, { xScale: this.lookDirection @@ -193,6 +199,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45° Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.headMesh, { xScale: this.lookDirection, @@ -205,22 +212,22 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { Parent.prototype.grab.call(this, item); this.animatedMeshes = this.animatedMeshesContainer.withoutArms; this.setActionState(this.actionState, true); - Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: true }); + Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: true }); }; Doll.prototype.throw = function(item, x, y) { Parent.prototype.throw.call(this, item, x, y); this.animatedMeshes = this.animatedMeshesContainer.withArms; this.setActionState(this.actionState, true); - Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: false }); + Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: false }); }; Doll.prototype.destroy = function () { for (var key in this.animatedMeshes) { - Nc.trigger(Nc.ns.client.view.mesh.remove, this.animatedMeshes[key]); + Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.animatedMeshes[key]); } - Nc.trigger(Nc.ns.client.view.mesh.remove, this.headMesh); + Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.headMesh); Parent.prototype.destroy.call(this); } @@ -228,6 +235,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { Doll.prototype.render = function() { if(this.actionState) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.animatedMeshes[this.actionState], { x: this.body.GetPosition().x * Settings.RATIO, @@ -237,6 +245,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { ); Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.headMesh, { x: this.body.GetPosition().x * Settings.RATIO, @@ -245,6 +254,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) { ) Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.holdingArmMesh, { x: this.body.GetPosition().x * Settings.RATIO, diff --git a/app/Game/Client/GameObjects/Item.js b/app/Game/Client/GameObjects/Item.js index 71bc2e7..c8a7a46 100755 --- a/app/Game/Client/GameObjects/Item.js +++ b/app/Game/Client/GameObjects/Item.js @@ -1,13 +1,15 @@ define([ "Game/Core/GameObjects/Item", "Game/Config/Settings", - "Lib/Utilities/NotificationCenter" + "Lib/Utilities/NotificationCenter", + "Game/Client/View/Abstract/Layer" ], -function (Parent, Settings, Nc) { +function (Parent, Settings, Nc, Layer) { function Item(physicsEngine, uid, options) { Parent.call(this, physicsEngine, uid, options); + this.layerId = Layer.ID.ITEM; } Item.prototype = Object.create(Parent.prototype); @@ -22,10 +24,11 @@ function (Parent, Settings, Nc) { var callback = function(mesh) { self.mesh = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); } Nc.trigger(Nc.ns.client.view.mesh.create, + this.layerId, texturePath, callback, { @@ -40,13 +43,14 @@ function (Parent, Settings, Nc) { }; Item.prototype.destroy = function() { - Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh); + Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.mesh); Parent.prototype.destroy.call(this); }; Item.prototype.render = function() { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.mesh, { x: this.body.GetPosition().x * Settings.RATIO, @@ -63,6 +67,7 @@ function (Parent, Settings, Nc) { if(oldFlipDirection != direction) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.mesh, { xScale: direction diff --git a/app/Game/Client/GameObjects/Items/RagDoll.js b/app/Game/Client/GameObjects/Items/RagDoll.js index 70d4117..d24b04c 100644 --- a/app/Game/Client/GameObjects/Items/RagDoll.js +++ b/app/Game/Client/GameObjects/Items/RagDoll.js @@ -2,12 +2,14 @@ define([ "Game/Core/GameObjects/Items/RagDoll", "Game/Core/GameObjects/Item", "Game/Config/Settings", - "Lib/Utilities/NotificationCenter" + "Lib/Utilities/NotificationCenter", + "Game/Client/View/Abstract/Layer" ], -function (Parent, CoreItem, Settings, Nc) { +function (Parent, CoreItem, Settings, Nc, Layer) { function RagDoll(physicsEngine, uid, options) { + this.layerId = Layer.ID.SPAWN; this.limbMeshes = {}; this.baseMeshName = "chest"; this.characterName = "Chuck"; @@ -36,10 +38,11 @@ function (Parent, CoreItem, Settings, Nc) { self.limbMeshes[name] = mesh; } - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); } Nc.trigger(Nc.ns.client.view.mesh.create, + this.layerId, texturePath + name + ".png", callback, { @@ -60,6 +63,7 @@ function (Parent, CoreItem, Settings, Nc) { for(var name in this.limbMeshes) { if(this.limbs[name]) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.limbMeshes[name], { x: this.limbs[name].GetPosition().x * Settings.RATIO, @@ -80,6 +84,7 @@ function (Parent, CoreItem, Settings, Nc) { if(oldFlipDirection != direction) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.mesh, { xScale: direction @@ -88,6 +93,7 @@ function (Parent, CoreItem, Settings, Nc) { for (var name in this.limbMeshes) { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.limbMeshes[name], { xScale: direction @@ -100,7 +106,7 @@ function (Parent, CoreItem, Settings, Nc) { RagDoll.prototype.destroy = function() { for (var name in this.limbMeshes) { - Nc.trigger(Nc.ns.client.view.mesh.remove, this.limbMeshes[name]); + Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.limbMeshes[name]); }; Parent.prototype.destroy.call(this); diff --git a/app/Game/Client/GameObjects/Tile.js b/app/Game/Client/GameObjects/Tile.js index 4319c4d..12bdfc3 100755 --- a/app/Game/Client/GameObjects/Tile.js +++ b/app/Game/Client/GameObjects/Tile.js @@ -1,13 +1,15 @@ define([ "Game/Core/GameObjects/Tile", "Game/Config/Settings", - "Lib/Utilities/NotificationCenter" + "Lib/Utilities/NotificationCenter", + "Game/Client/View/Abstract/Layer" ], -function (Parent, Settings, Nc) { +function (Parent, Settings, Nc, Layer) { function Tile(physicsEngine, uid, options) { Parent.call(this, physicsEngine, uid, options); + this.layerId = Layer.ID.TILE; } Tile.prototype = Object.create(Parent.prototype); @@ -27,10 +29,11 @@ function (Parent, Settings, Nc) { var callback = function(mesh) { self.mesh = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh); } Nc.trigger(Nc.ns.client.view.mesh.create, + this.layerId, texturePath, callback, { @@ -45,13 +48,14 @@ function (Parent, Settings, Nc) { }; Tile.prototype.destroy = function() { - Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh); + Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.mesh); Parent.prototype.destroy.call(this); }; Tile.prototype.render = function() { Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, this.mesh, { x: this.body.GetPosition().x * Settings.RATIO, diff --git a/app/Game/Client/Loader/TiledLevel.js b/app/Game/Client/Loader/TiledLevel.js index c70618f..9e1ce00 100644 --- a/app/Game/Client/Loader/TiledLevel.js +++ b/app/Game/Client/Loader/TiledLevel.js @@ -7,6 +7,7 @@ function (Parent, Settings) { function TiledLevel(uid, engine, gameObjects) { Parent.call(this, uid, engine, gameObjects); + this.layerId = "background"; } TiledLevel.prototype = Object.create(Parent.prototype); @@ -63,6 +64,7 @@ function (Parent, Settings) { TiledLevel.prototype.addBackground = function(options) { var texturePath = Settings.GRAPHICS_PATH + options.image; +/* var callback = function (mesh) { Nc.trigger(Nc.ns.client.view.mesh.add, mesh, 0); // FIXME: add at z layer -1 or so } @@ -72,6 +74,7 @@ function (Parent, Settings) { x: -(4000 - Settings.STAGE_WIDTH) / 2, y: -(2959 + Settings.STAGE_HEIGHT + 700) / 2 }); +*/ } TiledLevel.prototype.getLayer = function(levelData, name) { diff --git a/app/Game/Client/View/LayerManager.js b/app/Game/Client/View/LayerManager.js index 0e86852..c56d0e6 100644 --- a/app/Game/Client/View/LayerManager.js +++ b/app/Game/Client/View/LayerManager.js @@ -44,7 +44,6 @@ function (Nc, Exception, Layer) { } var layer = new Layer(id, parallaxSpeed); - var layerIndex = behind ? referenceIndex -1 : referenceIndex; this.layers.splice(layerIndex, 0, layer); @@ -58,7 +57,7 @@ function (Nc, Exception, Layer) { return layer; } }; - console.warn('No such layer: ' + id); + throw new Exception('No such layer: ' + id); }; LayerManager.prototype.delegate = function(methodName, layerId) { diff --git a/app/Lib/Utilities/Exception.js b/app/Lib/Utilities/Exception.js index affd2c9..49cfc2b 100755 --- a/app/Lib/Utilities/Exception.js +++ b/app/Lib/Utilities/Exception.js @@ -17,7 +17,8 @@ function() { this.message = message.join(" "); - Error.call(this, this.message); + var e = Error.call(this, this.message); + console.log(e.stack) } Exception.prototype = Object.create(Error.prototype);