mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
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.
This commit is contained in:
parent
8d8a55cc8c
commit
fc7866f11e
7 changed files with 24 additions and 27 deletions
|
|
@ -2,7 +2,6 @@ define([
|
||||||
"Game/Core/GameController",
|
"Game/Core/GameController",
|
||||||
"Game/Channel/Physics/Engine",
|
"Game/Channel/Physics/Engine",
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Game/Channel/Control/PlayerController",
|
|
||||||
"Lib/Utilities/RequestAnimFrame",
|
"Lib/Utilities/RequestAnimFrame",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"Lib/Utilities/NotificationCenter",
|
||||||
"Lib/Vendor/Box2D",
|
"Lib/Vendor/Box2D",
|
||||||
|
|
@ -12,7 +11,7 @@ define([
|
||||||
"Game/Channel/GameObjects/Items/RubeDoll"
|
"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";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -62,7 +61,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
||||||
|
|
||||||
GameController.prototype.createPlayer = function(user) {
|
GameController.prototype.createPlayer = function(user) {
|
||||||
var player = Parent.prototype.createPlayer.call(this, user);
|
var player = Parent.prototype.createPlayer.call(this, user);
|
||||||
player.setPlayerController(new PlayerController(player))
|
|
||||||
user.setPlayer(player);
|
user.setPlayer(player);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -219,7 +217,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
||||||
this.roundHasEnded = true;
|
this.roundHasEnded = true;
|
||||||
|
|
||||||
for(var id in this.players) {
|
for(var id in this.players) {
|
||||||
this.players[id].getPlayerController().setIsInBetweenGames(true);
|
this.players[id].setInBetweenRounds(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/Player",
|
"Game/Core/Player",
|
||||||
"Lib/Utilities/NotificationCenter"
|
"Lib/Utilities/NotificationCenter",
|
||||||
|
"Game/Channel/Control/PlayerController"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, Nc) {
|
function (Parent, Nc, PlayerController) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Player(id, physicsEngine, user) {
|
function Player(id, physicsEngine, user) {
|
||||||
Parent.call(this, id, physicsEngine, user);
|
Parent.call(this, id, physicsEngine, user);
|
||||||
|
|
||||||
|
this.playerController = new PlayerController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype = Object.create(Parent.prototype);
|
Player.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.setMe = function() {
|
GameController.prototype.setMe = function() {
|
||||||
this.me.setPlayerController(new PlayerController(this.me));
|
|
||||||
this.view.setMe(this.me);
|
this.view.setMe(this.me);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -257,13 +256,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.beginRound = function() {
|
GameController.prototype.beginRound = function() {
|
||||||
if (this.me.getPlayerController()) {
|
this.me.setInBetweenRounds(false);
|
||||||
this.me.getPlayerController().setIsInBetweenGames(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.endRound = function() {
|
GameController.prototype.endRound = function() {
|
||||||
this.me.getPlayerController().setIsInBetweenGames(true);
|
this.me.setInBetweenRounds(true);
|
||||||
this.toggleGameStats(true);
|
this.toggleGameStats(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ define([
|
||||||
"Game/Client/Player",
|
"Game/Client/Player",
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"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";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ function (Parent, Settings, Nc, Assert) {
|
||||||
|
|
||||||
this.arrowMesh = null;
|
this.arrowMesh = null;
|
||||||
this.createAndAddArrow();
|
this.createAndAddArrow();
|
||||||
|
this.playerController = new PlayerController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Me.prototype = Object.create(Parent.prototype);
|
Me.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ function (Parent, Nc, Settings) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Player(id, physicsEngine, user) {
|
function Player(id, physicsEngine, user, isMe) {
|
||||||
Parent.call(this, id, physicsEngine, user);
|
Parent.call(this, id, physicsEngine, user);
|
||||||
|
|
||||||
this.healthBarView = null;
|
this.healthBarView = null;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function () {
|
||||||
this._isJumping;
|
this._isJumping;
|
||||||
this._walkingDirectionStatus = 0;
|
this._walkingDirectionStatus = 0;
|
||||||
|
|
||||||
this.isInBetweenGames = false;
|
this.inBetweenRounds = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.moveLeft = function () {
|
PlayerController.prototype.moveLeft = function () {
|
||||||
|
|
@ -46,12 +46,12 @@ function () {
|
||||||
if(options) this.player.lookAt(options.x, options.y);
|
if(options) this.player.lookAt(options.x, options.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.setIsInBetweenGames = function(isInBetweenGames) {
|
PlayerController.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
||||||
this.isInBetweenGames = !!isInBetweenGames;
|
this.inBetweenRounds = !!inBetweenRounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.isPlayerInputAllowed = function() {
|
PlayerController.prototype.isPlayerInputAllowed = function() {
|
||||||
return !this.isInBetweenGames;
|
return !this.inBetweenRounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.update = function () {
|
PlayerController.prototype.update = function () {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
define([
|
define([
|
||||||
"Game/" + GLOBALS.context + "/GameObjects/Doll",
|
"Game/" + GLOBALS.context + "/GameObjects/Doll",
|
||||||
|
"Game/" + GLOBALS.context + "/Control/PlayerController",
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"Lib/Utilities/NotificationCenter",
|
||||||
"Lib/Utilities/Exception",
|
"Lib/Utilities/Exception",
|
||||||
|
|
@ -8,7 +9,7 @@ define([
|
||||||
"Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll"
|
"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";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll
|
||||||
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.physicsEngine = physicsEngine;
|
this.physicsEngine = physicsEngine;
|
||||||
this.playerController = null;
|
this.playerController = null; // pre-initialise with null, because client/players don't get one
|
||||||
this.doll;
|
this.doll;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.spawned = false;
|
this.spawned = false;
|
||||||
|
|
@ -183,13 +184,9 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.setPlayerController = function(playerController) {
|
Player.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
||||||
this.playerController = playerController;
|
return this.playerController.setInBetweenRounds(inBetweenRounds);
|
||||||
}
|
};
|
||||||
|
|
||||||
Player.prototype.getPlayerController = function() {
|
|
||||||
return this.playerController;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Player;
|
return Player;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue