From ec7ce459cb3d076ac2b67cce8eec15ad93a9b09c Mon Sep 17 00:00:00 2001 From: logsol Date: Wed, 6 May 2015 20:13:13 +0200 Subject: [PATCH] added swapMeshes method to swap textures of 2 meshes --- app/Game/Client/View/LayerManager.js | 8 +++++++- app/Game/Client/View/Pixi/Layer.js | 16 ++++++++++++++++ app/Lib/Utilities/NotificationCenter.js | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/Game/Client/View/LayerManager.js b/app/Game/Client/View/LayerManager.js index 7adec2f..8245e3f 100644 --- a/app/Game/Client/View/LayerManager.js +++ b/app/Game/Client/View/LayerManager.js @@ -21,7 +21,8 @@ function (Nc, Exception, Layer) { Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this), Nc.on(Nc.ns.client.view.mesh.addFilter, this.addFilter, this), Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this), - Nc.on(Nc.ns.client.view.mesh.swapMeshIndexes, this.swapMeshIndexes, this) + Nc.on(Nc.ns.client.view.mesh.swapMeshIndexes, this.swapMeshIndexes, this), + Nc.on(Nc.ns.client.view.mesh.swapMeshes, this.swapMeshes, this) ]; } @@ -163,6 +164,11 @@ function (Nc, Exception, Layer) { this.delegate.apply(this, arguments); }; + LayerManager.prototype.swapMeshes = function() { + Array.prototype.splice.call(arguments, 0, 0, 'swapMeshes') + this.delegate.apply(this, arguments); + }; + LayerManager.prototype.destroy = function() { for (var i = 0; i < this.ncTokens.length; i++) { Nc.off(this.ncTokens[i]); diff --git a/app/Game/Client/View/Pixi/Layer.js b/app/Game/Client/View/Pixi/Layer.js index 58a0fd8..4d6465f 100644 --- a/app/Game/Client/View/Pixi/Layer.js +++ b/app/Game/Client/View/Pixi/Layer.js @@ -103,6 +103,22 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter, Nc) { this.container.setChildIndex(meshB, indexA); }; + Layer.prototype.swapMeshes = function(meshA, meshB) { + var textureA = meshA.texture; + var textureB = meshB.texture; + + meshA.setTexture(textureB); + meshA.onTextureUpdate(); + meshA.scale.x = 1; + meshA.scale.y = 1; + + meshB.setTexture(textureA); + meshB.onTextureUpdate(); + meshB.scale.x = 1; + meshB.scale.y = 1; + + }; + Layer.prototype.createMesh = function (texturePath, callback, options) { var texture = (options && options.fromFrame) diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index ec4beb3..62496ba 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -42,7 +42,8 @@ function (Exception) { update: null, addFilter: null, removeFilter: null, - swapMeshIndexes: null + swapMeshIndexes: null, + swapMeshes: null }, animatedMesh: { create: null