Merge branch 'restructuring' of github.com:logsol/chuck.js into restructuring

This commit is contained in:
Jeena Paradies 2012-07-21 23:03:43 +02:00
commit 26662567dc
9 changed files with 102 additions and 88 deletions

14
app/Game/Client/Collision/Detector.js Normal file → Executable file
View file

@ -1,6 +1,12 @@
define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) { define([
"Lib/Vendor/Box2D",
"Game/Core/Collision/Detector"
],
function(Box2D, Parent) {
function Detector(me) { function Detector(me) {
Parent.call(this);
this.me = me; this.me = me;
this.listener = new Box2D.Dynamics.b2ContactListener(); this.listener = new Box2D.Dynamics.b2ContactListener();
@ -10,13 +16,15 @@ define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) {
this.listener.EndContact = this.EndContact; this.listener.EndContact = this.EndContact;
} }
Detector.prototype = Object.create(Parent);
Detector.prototype.getListener = function() { Detector.prototype.getListener = function() {
return this.listener; return this.listener;
} }
Detector.prototype.handleStand = function(point, isColliding) { Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR
|| point.GetFixtureB().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR) { || point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) {
this.me.onFootSensorDetection(isColliding); this.me.onFootSensorDetection(isColliding);
} }

View file

@ -1,8 +1,8 @@
define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], function(InputController, KeyboardInput){ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"], function(InputController, KeyboardInput){
function InputControlUnit(me, clientProcessor) { function KeyboardController(me, gameController) {
this.clientProcessor = clientProcessor; this.gameController = gameController;
this.inputController = new InputController(me); this.inputController = new InputController(me);
this.keyboardInput = new KeyboardInput(this); this.keyboardInput = new KeyboardInput(this);
@ -22,7 +22,7 @@ define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], functio
this.init(keys); this.init(keys);
} }
InputControlUnit.prototype.init = function(keys) { KeyboardController.prototype.init = function(keys) {
this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft'); this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft');
this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft'); this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft');
@ -40,55 +40,55 @@ define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], functio
this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift'); this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
} }
InputControlUnit.prototype.moveLeft = function() { KeyboardController.prototype.moveLeft = function() {
this.inputController.moveLeft(); this.inputController.moveLeft();
this.clientProcessor.sendGameCommand('moveLeft'); this.gameController.sendGameCommand('moveLeft');
} }
InputControlUnit.prototype.moveRight = function() { KeyboardController.prototype.moveRight = function() {
this.inputController.moveRight(); this.inputController.moveRight();
this.clientProcessor.sendGameCommand('moveRight'); this.gameController.sendGameCommand('moveRight');
} }
InputControlUnit.prototype.stop = function() { KeyboardController.prototype.stop = function() {
this.inputController.stop(); this.inputController.stop();
this.clientProcessor.sendGameCommand('stop'); this.gameController.sendGameCommand('stop');
} }
InputControlUnit.prototype.jump = function() { KeyboardController.prototype.jump = function() {
this.inputController.jump(); this.inputController.jump();
this.clientProcessor.sendGameCommand('jump'); this.gameController.sendGameCommand('jump');
} }
InputControlUnit.prototype.jumped = function() { KeyboardController.prototype.jumped = function() {
this.inputController.jumped(); this.inputController.jumped();
} }
InputControlUnit.prototype.jumping = function() { KeyboardController.prototype.jumping = function() {
this.inputController.jumping(); this.inputController.jumping();
} }
InputControlUnit.prototype.duck = function() { KeyboardController.prototype.duck = function() {
this.inputController.duck(); this.inputController.duck();
this.clientProcessor.sendGameCommand('duck'); this.gameController.sendGameCommand('duck');
} }
InputControlUnit.prototype.standUp = function() { KeyboardController.prototype.standUp = function() {
this.inputController.standUp(); this.inputController.standUp();
} }
InputControlUnit.prototype.activateShift = function() { KeyboardController.prototype.activateShift = function() {
this.inputController.activateShift(); this.inputController.activateShift();
this.clientProcessor.sendGameCommand('activateShift'); this.gameController.sendGameCommand('activateShift');
} }
InputControlUnit.prototype.deactivateShift = function() { KeyboardController.prototype.deactivateShift = function() {
this.inputController.deactivateShift(); this.inputController.deactivateShift();
} }
InputControlUnit.prototype.update = function() { KeyboardController.prototype.update = function() {
this.keyboardInput.update(); this.keyboardInput.update();
} }
return InputControlUnit; return KeyboardController;
}); });

View file

@ -1,9 +1,9 @@
define(["Chuck/Control/Key"], function(Key){ define(["Game/Client/Control/Key"], function(Key){
function KeyboardInput (inputControlUnit) { function KeyboardInput (keyboardController) {
this._registry = {}; this._registry = {};
this._inputControlUnit = inputControlUnit; this._keyboardController = keyboardController;
this.init(); this.init();
} }
@ -61,12 +61,12 @@ define(["Chuck/Control/Key"], function(Key){
} }
if (callback) { if (callback) {
self._inputControlUnit[callback](); self._keyboardController[callback]();
} else { } else {
if (key.getActive()) { if (key.getActive()) {
callback = key.getKeyFrameFunction(); callback = key.getKeyFrameFunction();
if (callback) { if (callback) {
self._inputControlUnit[callback](); self._keyboardController[callback]();
} }
} }
} }

View file

@ -1,30 +1,29 @@
var requires = [ var requires = [
"Chuck/View/ViewController", "Game/Client/View/ViewController",
"Chuck/Physics/Engine", "Game/Core/Physics/Engine",
"Chuck/Player", "Game/Core/Player",
"Chuck/Control/InputControlUnit", "Game/Client/Control/KeyboardController",
"Chuck/Settings", "Game/Config/Settings",
"Vendor/Box2D", "Game/Core/Loader/Level",
"Chuck/Loader/Level", "Lib/Vendor/Box2D",
"RequestAnimationFrame" "Lib/Utilities/RequestAnimFrame"
]; ];
define(requires, define(requires, function(ViewController, PhysicsEngine, Player, KeyboardController, Settings, Level, Box2D, requestAnimFrame) {
function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame) {
function ClientProcessor (clientGame) { function GameController (clientGame) {
this.clientGame = clientGame; this.clientGame = clientGame;
this.init(); this.init();
}; };
ClientProcessor.prototype.init = function() { GameController.prototype.init = function() {
this.viewController = new ViewController(); this.viewController = new ViewController();
this.physicsEngine = new PhysicsEngine(); this.physicsEngine = new PhysicsEngine();
this.update(); this.update();
} }
ClientProcessor.prototype.loadLevel = function(path) { GameController.prototype.loadLevel = function(path) {
if (this.level) { if (this.level) {
this.level.unload(); this.level.unload();
} }
@ -33,15 +32,15 @@ define(requires,
this.level.loadLevelInToEngine(); this.level.loadLevelInToEngine();
} }
ClientProcessor.prototype.getPhysicsEngine = function() { GameController.prototype.getPhysicsEngine = function() {
return this.physicsEngine; return this.physicsEngine;
} }
ClientProcessor.prototype.getMe = function() { GameController.prototype.getMe = function() {
return this.me; return this.me;
} }
ClientProcessor.prototype.update = function() { GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this)); requestAnimFrame(this.update.bind(this));
@ -49,32 +48,32 @@ define(requires,
this.viewController.update(); this.viewController.update();
if(this.me) { if(this.me) {
this.inputControlUnit.update(); this.KeyboardController.update();
this.me.update(); this.me.update();
} }
} }
ClientProcessor.prototype.destruct = function() { GameController.prototype.destruct = function() {
} }
ClientProcessor.prototype.spawnNewPlayerWithId = function(id) { GameController.prototype.spawnNewPlayerWithId = function(id) {
var player = new Player(this.physicsEngine, id, null); var player = new Player(this.physicsEngine, id, null);
player.spawn(100, 0); player.spawn(100, 0);
this.physicsEngine.setCollisionDetector(player); this.physicsEngine.setCollisionDetector(player);
return player; return player;
} }
ClientProcessor.prototype.spawnMeWithId = function(id) { GameController.prototype.spawnMeWithId = function(id) {
this.me = this.spawnNewPlayerWithId(id); this.me = this.spawnNewPlayerWithId(id);
this.inputControlUnit = new InputControlUnit(this.me, this); this.KeyboardController = new KeyboardController(this.me, this);
} }
ClientProcessor.prototype.sendGameCommand = function(command, options) { GameController.prototype.sendGameCommand = function(command, options) {
this.clientGame.sendGameCommand(command, options); this.clientGame.sendGameCommand(command, options);
} }
ClientProcessor.prototype.processGameCommand = function(command, options) { GameController.prototype.processGameCommand = function(command, options) {
if (command == "worldUpdate") { if (command == "worldUpdate") {
@ -98,5 +97,5 @@ define(requires,
} }
return ClientProcessor; return GameController;
}); });

20
app/Game/Client/Networker.js Normal file → Executable file
View file

@ -1,8 +1,8 @@
define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientGame) { define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(ProtocolHelper, GameController) {
function Networker(socketLink) { function Networker(socketLink) {
this.socketLink = socketLink; this.socketLink = socketLink;
this.clientGame = null; this.GameController = null;
this.init(); this.init();
} }
@ -36,8 +36,8 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
} }
Networker.prototype.onDisconnect = function() { Networker.prototype.onDisconnect = function() {
this.clientGame.destruct(); this.GameController.destruct();
this.clientGame = null; this.GameController = null;
} }
Networker.prototype.join = function(channelName){ Networker.prototype.join = function(channelName){
@ -50,19 +50,19 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
} }
Networker.prototype.onJoinSuccess = function(options) { Networker.prototype.onJoinSuccess = function(options) {
this.clientGame = new ClientGame(this, options.id); this.GameController = new GameController(this, options.id);
this.clientGame.loadLevel("default.json") this.GameController.loadLevel("default.json")
console.log("Joined " + options.channelName); console.log("Joined " + options.channelName);
if (options.userIds && options.userIds.length > 0) { if (options.userIds && options.userIds.length > 0) {
for(var i = 0; i < options.userIds.length; i++) { for(var i = 0; i < options.userIds.length; i++) {
this.clientGame.userJoined(options.userIds[i]) this.GameController.userJoined(options.userIds[i])
} }
} }
} }
Networker.prototype.onUserJoined = function(userId) { Networker.prototype.onUserJoined = function(userId) {
this.clientGame.userJoined(userId); this.GameController.userJoined(userId);
console.log("User " + userId + " joined"); console.log("User " + userId + " joined");
} }
@ -71,7 +71,7 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
} }
Networker.prototype.onUserLeft = function(userId) { Networker.prototype.onUserLeft = function(userId) {
this.clientGame.userLeft(userId); this.GameController.userLeft(userId);
} }
Networker.prototype.processControlCommand = function(command, options) { Networker.prototype.processControlCommand = function(command, options) {
@ -82,7 +82,7 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
case 'gameCommand': case 'gameCommand':
for(var gameCommand in options) { for(var gameCommand in options) {
this.clientGame.processGameCommand(gameCommand, options[gameCommand]); this.GameController.processGameCommand(gameCommand, options[gameCommand]);
} }
break; break;

View file

@ -1,4 +1,4 @@
define(['Vendor/Three', 'Chuck/Settings'], function(Three, Settings) { define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) {
function CameraController(isOrthographic) { function CameraController(isOrthographic) {

View file

@ -1,11 +1,11 @@
define(['Chuck/Settings'], function(Settings) { define(['Game/Config/Settings'], function(Settings) {
var Dom = { var DomController = {
canvas: null, canvas: null,
debugCanvas: null debugCanvas: null
}; };
Dom.getCanvasContainer = function(){ DomController.getCanvasContainer = function(){
var container = document.getElementById(Settings.CANVAS_DOM_ID); var container = document.getElementById(Settings.CANVAS_DOM_ID);
if(container) { if(container) {
@ -15,39 +15,39 @@ define(['Chuck/Settings'], function(Settings) {
} }
} }
Dom.getCanvas = function(){ DomController.getCanvas = function(){
return Dom.canvas; return DomController.canvas;
} }
Dom.setCanvas = function(canvas){ DomController.setCanvas = function(canvas){
var container = Dom.getCanvasContainer(); var container = DomController.getCanvasContainer();
if(Dom.canvas){ if(DomController.canvas){
container.removeChild(Dom.canvas); container.removeChild(DomController.canvas);
} }
Dom.canvas = canvas; DomController.canvas = canvas;
container.appendChild(canvas); container.appendChild(canvas);
} }
Dom.getDebugCanvas = function(){ DomController.getDebugCanvas = function(){
return Dom.debugCanvas; return DomController.debugCanvas;
} }
Dom.createDebugCanvas = function(){ DomController.createDebugCanvas = function(){
var container = Dom.getCanvasContainer(); var container = DomController.getCanvasContainer();
if(Dom.debugCanvas){ if(DomController.debugCanvas){
container.removeChild(Dom.debugCanvas); container.removeChild(DomController.debugCanvas);
} }
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = Settings.STAGE_WIDTH; canvas.width = Settings.STAGE_WIDTH;
canvas.height = Settings.STAGE_HEIGHT; canvas.height = Settings.STAGE_HEIGHT;
Dom.debugCanvas = canvas; DomController.debugCanvas = canvas;
container.appendChild(canvas); container.appendChild(canvas);
} }
return Dom; return DomController;
}); });

View file

@ -1,4 +1,11 @@
define(["Client/Dom", "Vendor/Three", "Chuck/Settings", "Chuck/View/CameraController"], function(Dom, Three, Settings, CameraController){ var requires = [
"Game/Client/View/DomController",
"Lib/Vendor/Three",
"Game/Config/Settings",
"Game/Client/View/CameraController"
];
define(requires, function(DomController, Three, Settings, CameraController){
function ViewController(){ function ViewController(){
@ -36,10 +43,10 @@ define(["Client/Dom", "Vendor/Three", "Chuck/Settings", "Chuck/View/CameraContro
this.renderer.setClearColorHex(0x333333, 1); this.renderer.setClearColorHex(0x333333, 1);
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT); this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
Dom.setCanvas(this.renderer.domElement); DomController.setCanvas(this.renderer.domElement);
if(Settings.DEBUG_MODE){ if(Settings.DEBUG_MODE){
Dom.createDebugCanvas(); DomController.createDebugCanvas();
} }
this.scene = new Three.Scene(); this.scene = new Three.Scene();

4
app/Game/Server/Channel.js Normal file → Executable file
View file

@ -1,9 +1,9 @@
define(["Chuck/ServerGame"], function(ServerGame) { define(["Game/Server/GameController"], function(GameController) {
function Channel(name) { function Channel(name) {
this.name = name; this.name = name;
this.users = {}; this.users = {};
this.serverGame = this.factory.new(ServerGame, this); this.serverGame = new GameController();
console.log("server game " + this.serverGame); console.log("server game " + this.serverGame);
this.serverGame.loadLevel("default.json"); this.serverGame.loadLevel("default.json");