From dba743cd7b8248f459225e7194b5c40f7ba8abaa Mon Sep 17 00:00:00 2001 From: logsol Date: Sun, 9 Oct 2016 12:46:07 +0200 Subject: [PATCH] Updates obsolete/broken way of clearing fingerprints When a user leaves the channel, some items need to be cleared of their fingerprints (lastTouchedBy). This feature was broken because it used the this.gameObjects pool which was no longer in use. The channel GameController now triggers an event to which all items are subscribed to and if it is triggered, all items with that users fingerprints clear themselves off those. Fixes #170 --- app/Game/Channel/GameController.js | 11 ++++++++++- app/Game/Channel/GameObjects/Item.js | 16 ++++++++++++++-- app/Game/Client/GameController.js | 4 ---- app/Game/Core/GameController.js | 22 +--------------------- app/Lib/Utilities/NotificationCenter.js | 6 ++++-- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/Game/Channel/GameController.js b/app/Game/Channel/GameController.js index 69f04dd..4e85302 100755 --- a/app/Game/Channel/GameController.js +++ b/app/Game/Channel/GameController.js @@ -36,7 +36,6 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player, console.checkpoint('starting game controller for channel (' + options.channelName + ')'); } - GameController.prototype = Object.create(Parent.prototype); GameController.prototype.update = function () { @@ -59,6 +58,16 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player, this.createPlayer(user); } + GameController.prototype.onUserLeft = function (userId) { + var player = this.players[userId]; + this.clearItemsOfPlayerFingerPrints(player); + Parent.prototype.onUserLeft.call(this, userId); + }; + + GameController.prototype.clearItemsOfPlayerFingerPrints = function(player) { + Nc.trigger(Nc.ns.channel.events.game.player.clearFingerPrints, player); + }; + GameController.prototype.createPlayer = function(user) { var revealedGameController = { diff --git a/app/Game/Channel/GameObjects/Item.js b/app/Game/Channel/GameObjects/Item.js index b28a0b5..c335182 100755 --- a/app/Game/Channel/GameObjects/Item.js +++ b/app/Game/Channel/GameObjects/Item.js @@ -1,8 +1,9 @@ define([ - "Game/Core/GameObjects/Item" + "Game/Core/GameObjects/Item", + "Lib/Utilities/NotificationCenter", ], -function (Parent) { +function (Parent, Nc) { "use strict"; @@ -10,6 +11,10 @@ function (Parent) { Parent.call(this, physicsEngine, uid, options); this.heldByPlayers = []; this.lastMoved = null; + + this.ncTokens = (this.ncTokens || []).concat([ + Nc.on(Nc.ns.channel.events.game.player.clearFingerPrints, this.clearOfPlayerFingerPrints, this) + ]); } Item.prototype = Object.create(Parent.prototype); @@ -59,6 +64,13 @@ function (Parent) { } }; + Item.prototype.clearOfPlayerFingerPrints = function(player) { + if (this.getLastMovedBy() && this.getLastMovedBy().player === player) { + console.checkpoint('Removing fingerprints from ' + this.options.image); + this.setLastMovedBy(null); + } + }; + Item.prototype.onCollisionChange = function(isColliding, fixture) { if(isColliding) { diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 8671e6f..1447520 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -55,10 +55,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque this.mePositionStateOverride(); } - //for (var uid in this.gameObjects.animated) { - // this.gameObjects.animated[uid].render(); - //} - Nc.trigger(Nc.ns.client.game.events.render); this.view.render(); diff --git a/app/Game/Core/GameController.js b/app/Game/Core/GameController.js index 0450c42..58b4454 100755 --- a/app/Game/Core/GameController.js +++ b/app/Game/Core/GameController.js @@ -92,20 +92,12 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert) this.loadLevel(this.level.uid); }; - /* - GameController.prototype.userJoined = function (user) { - this.players[user.id] = this.createPlayer(user); - } - */ - GameController.prototype.onUserLeft = function (userId) { var player = this.players[userId]; if(!player) { console.warn("User (", userId ,") left who has not joined"); return; } - - this.clearItemsOfPlayerFingerPrints(player); player.destroy(); delete this.players[userId]; @@ -117,25 +109,13 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert) return player; }; - GameController.prototype.clearItemsOfPlayerFingerPrints = function(player) { - for (var key in this.gameObjects) { - for (var i = 0; i < this.gameObjects[key].length; i++) { // to go through animated and fixed. - var gameObject = this.gameObjects[key][i]; - if (gameObject instanceof Item) { - - if (gameObject.getLastMovedBy() && gameObject.getLastMovedBy().player === player) { - gameObject.setLastMovedBy(null); - } - } - } - } - }; GameController.prototype.destroy = function () { for(var player in this.players) { this.players[player].destroy(); } + // FIXME ns.client in core? Nc.trigger(Nc.ns.client.game.events.destroy); // Testing after destroy if worldUpdateObjects is empty diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index 9c707c5..33b4be2 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -138,8 +138,10 @@ function (Exception) { }, game: { player: { - killed: null - } + killed: null, + clearFingerPrints: null + }, + } }, engine: {