From fc7866f11ed168efff1ef599825dc9da3a3d9e10 Mon Sep 17 00:00:00 2001 From: logsol Date: Sat, 1 Oct 2016 12:11:27 +0200 Subject: [PATCH] Hides playercontroller within player In order to not provide deep exposure to PlayerController, we refactored it so that it is not visible anymore outside Player. Also we renamed isInBetweenGames to inBetweenRounds. Moved creation of PlayerController from GameController(s) to The channel Player and client Me. --- app/Game/Channel/GameController.js | 6 ++---- app/Game/Channel/Player.js | 7 +++++-- app/Game/Client/GameController.js | 7 ++----- app/Game/Client/Me.js | 6 ++++-- app/Game/Client/Player.js | 2 +- app/Game/Core/Control/PlayerController.js | 8 ++++---- app/Game/Core/Player.js | 15 ++++++--------- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/app/Game/Channel/GameController.js b/app/Game/Channel/GameController.js index 318ffe8..4d0adbd 100755 --- a/app/Game/Channel/GameController.js +++ b/app/Game/Channel/GameController.js @@ -2,7 +2,6 @@ define([ "Game/Core/GameController", "Game/Channel/Physics/Engine", "Game/Config/Settings", - "Game/Channel/Control/PlayerController", "Lib/Utilities/RequestAnimFrame", "Lib/Utilities/NotificationCenter", "Lib/Vendor/Box2D", @@ -12,7 +11,7 @@ define([ "Game/Channel/GameObjects/Items/RubeDoll" ], -function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RubeDoll) { +function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RubeDoll) { "use strict"; @@ -62,7 +61,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N GameController.prototype.createPlayer = function(user) { var player = Parent.prototype.createPlayer.call(this, user); - player.setPlayerController(new PlayerController(player)) user.setPlayer(player); }; @@ -219,7 +217,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N this.roundHasEnded = true; for(var id in this.players) { - this.players[id].getPlayerController().setIsInBetweenGames(true); + this.players[id].setInBetweenRounds(true); } }; diff --git a/app/Game/Channel/Player.js b/app/Game/Channel/Player.js index eb0bf2b..6f3771c 100755 --- a/app/Game/Channel/Player.js +++ b/app/Game/Channel/Player.js @@ -1,14 +1,17 @@ define([ "Game/Core/Player", - "Lib/Utilities/NotificationCenter" + "Lib/Utilities/NotificationCenter", + "Game/Channel/Control/PlayerController" ], -function (Parent, Nc) { +function (Parent, Nc, PlayerController) { "use strict"; function Player(id, physicsEngine, user) { Parent.call(this, id, physicsEngine, user); + + this.playerController = new PlayerController(this); } Player.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 2651130..0ae5778 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -151,7 +151,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque }; GameController.prototype.setMe = function() { - this.me.setPlayerController(new PlayerController(this.me)); this.view.setMe(this.me); }; @@ -257,13 +256,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque }; GameController.prototype.beginRound = function() { - if (this.me.getPlayerController()) { - this.me.getPlayerController().setIsInBetweenGames(false); - } + this.me.setInBetweenRounds(false); }; GameController.prototype.endRound = function() { - this.me.getPlayerController().setIsInBetweenGames(true); + this.me.setInBetweenRounds(true); this.toggleGameStats(true); }; diff --git a/app/Game/Client/Me.js b/app/Game/Client/Me.js index 64d1e2f..f271f03 100644 --- a/app/Game/Client/Me.js +++ b/app/Game/Client/Me.js @@ -2,10 +2,11 @@ define([ "Game/Client/Player", "Game/Config/Settings", "Lib/Utilities/NotificationCenter", - "Lib/Utilities/Assert" + "Lib/Utilities/Assert", + "Game/Client/Control/PlayerController", ], -function (Parent, Settings, Nc, Assert) { +function (Parent, Settings, Nc, Assert, PlayerController) { "use strict"; @@ -27,6 +28,7 @@ function (Parent, Settings, Nc, Assert) { this.arrowMesh = null; this.createAndAddArrow(); + this.playerController = new PlayerController(this); } Me.prototype = Object.create(Parent.prototype); diff --git a/app/Game/Client/Player.js b/app/Game/Client/Player.js index 6f511ac..4ad6bac 100755 --- a/app/Game/Client/Player.js +++ b/app/Game/Client/Player.js @@ -8,7 +8,7 @@ function (Parent, Nc, Settings) { "use strict"; - function Player(id, physicsEngine, user) { + function Player(id, physicsEngine, user, isMe) { Parent.call(this, id, physicsEngine, user); this.healthBarView = null; diff --git a/app/Game/Core/Control/PlayerController.js b/app/Game/Core/Control/PlayerController.js index 3550f80..9286f4c 100755 --- a/app/Game/Core/Control/PlayerController.js +++ b/app/Game/Core/Control/PlayerController.js @@ -11,7 +11,7 @@ function () { this._isJumping; this._walkingDirectionStatus = 0; - this.isInBetweenGames = false; + this.inBetweenRounds = false; } PlayerController.prototype.moveLeft = function () { @@ -46,12 +46,12 @@ function () { if(options) this.player.lookAt(options.x, options.y); } - PlayerController.prototype.setIsInBetweenGames = function(isInBetweenGames) { - this.isInBetweenGames = !!isInBetweenGames; + PlayerController.prototype.setInBetweenRounds = function(inBetweenRounds) { + this.inBetweenRounds = !!inBetweenRounds; }; PlayerController.prototype.isPlayerInputAllowed = function() { - return !this.isInBetweenGames; + return !this.inBetweenRounds; }; PlayerController.prototype.update = function () { diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index bcca9db..49f3d28 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -1,5 +1,6 @@ define([ "Game/" + GLOBALS.context + "/GameObjects/Doll", + "Game/" + GLOBALS.context + "/Control/PlayerController", "Game/Config/Settings", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Exception", @@ -8,7 +9,7 @@ define([ "Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll" ], -function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) { +function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) { "use strict"; @@ -21,7 +22,7 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll this.user = user; this.physicsEngine = physicsEngine; - this.playerController = null; + this.playerController = null; // pre-initialise with null, because client/players don't get one this.doll; this.id = id; this.spawned = false; @@ -183,13 +184,9 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll } } - Player.prototype.setPlayerController = function(playerController) { - this.playerController = playerController; - } - - Player.prototype.getPlayerController = function() { - return this.playerController; - } + Player.prototype.setInBetweenRounds = function(inBetweenRounds) { + return this.playerController.setInBetweenRounds(inBetweenRounds); + }; return Player; });