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) {
Parent.call(this);
this.me = me;
this.listener = new Box2D.Dynamics.b2ContactListener();
@ -10,13 +16,15 @@ define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) {
this.listener.EndContact = this.EndContact;
}
Detector.prototype = Object.create(Parent);
Detector.prototype.getListener = function() {
return this.listener;
}
Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR
|| point.GetFixtureB().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR) {
if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR
|| point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) {
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.keyboardInput = new KeyboardInput(this);
@ -22,7 +22,7 @@ define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], functio
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.left, 'moveLeft', 'stop', 'moveLeft');
@ -40,55 +40,55 @@ define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], functio
this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
}
InputControlUnit.prototype.moveLeft = function() {
KeyboardController.prototype.moveLeft = function() {
this.inputController.moveLeft();
this.clientProcessor.sendGameCommand('moveLeft');
this.gameController.sendGameCommand('moveLeft');
}
InputControlUnit.prototype.moveRight = function() {
KeyboardController.prototype.moveRight = function() {
this.inputController.moveRight();
this.clientProcessor.sendGameCommand('moveRight');
this.gameController.sendGameCommand('moveRight');
}
InputControlUnit.prototype.stop = function() {
KeyboardController.prototype.stop = function() {
this.inputController.stop();
this.clientProcessor.sendGameCommand('stop');
this.gameController.sendGameCommand('stop');
}
InputControlUnit.prototype.jump = function() {
KeyboardController.prototype.jump = function() {
this.inputController.jump();
this.clientProcessor.sendGameCommand('jump');
this.gameController.sendGameCommand('jump');
}
InputControlUnit.prototype.jumped = function() {
KeyboardController.prototype.jumped = function() {
this.inputController.jumped();
}
InputControlUnit.prototype.jumping = function() {
KeyboardController.prototype.jumping = function() {
this.inputController.jumping();
}
InputControlUnit.prototype.duck = function() {
KeyboardController.prototype.duck = function() {
this.inputController.duck();
this.clientProcessor.sendGameCommand('duck');
this.gameController.sendGameCommand('duck');
}
InputControlUnit.prototype.standUp = function() {
KeyboardController.prototype.standUp = function() {
this.inputController.standUp();
}
InputControlUnit.prototype.activateShift = function() {
KeyboardController.prototype.activateShift = function() {
this.inputController.activateShift();
this.clientProcessor.sendGameCommand('activateShift');
this.gameController.sendGameCommand('activateShift');
}
InputControlUnit.prototype.deactivateShift = function() {
KeyboardController.prototype.deactivateShift = function() {
this.inputController.deactivateShift();
}
InputControlUnit.prototype.update = function() {
KeyboardController.prototype.update = function() {
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._inputControlUnit = inputControlUnit;
this._keyboardController = keyboardController;
this.init();
}
@ -61,12 +61,12 @@ define(["Chuck/Control/Key"], function(Key){
}
if (callback) {
self._inputControlUnit[callback]();
self._keyboardController[callback]();
} else {
if (key.getActive()) {
callback = key.getKeyFrameFunction();
if (callback) {
self._inputControlUnit[callback]();
self._keyboardController[callback]();
}
}
}

View file

@ -1,30 +1,29 @@
var requires = [
"Chuck/View/ViewController",
"Chuck/Physics/Engine",
"Chuck/Player",
"Chuck/Control/InputControlUnit",
"Chuck/Settings",
"Vendor/Box2D",
"Chuck/Loader/Level",
"RequestAnimationFrame"
"Game/Client/View/ViewController",
"Game/Core/Physics/Engine",
"Game/Core/Player",
"Game/Client/Control/KeyboardController",
"Game/Config/Settings",
"Game/Core/Loader/Level",
"Lib/Vendor/Box2D",
"Lib/Utilities/RequestAnimFrame"
];
define(requires,
function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame) {
define(requires, function(ViewController, PhysicsEngine, Player, KeyboardController, Settings, Level, Box2D, requestAnimFrame) {
function ClientProcessor (clientGame) {
function GameController (clientGame) {
this.clientGame = clientGame;
this.init();
};
ClientProcessor.prototype.init = function() {
GameController.prototype.init = function() {
this.viewController = new ViewController();
this.physicsEngine = new PhysicsEngine();
this.update();
}
ClientProcessor.prototype.loadLevel = function(path) {
GameController.prototype.loadLevel = function(path) {
if (this.level) {
this.level.unload();
}
@ -33,15 +32,15 @@ define(requires,
this.level.loadLevelInToEngine();
}
ClientProcessor.prototype.getPhysicsEngine = function() {
GameController.prototype.getPhysicsEngine = function() {
return this.physicsEngine;
}
ClientProcessor.prototype.getMe = function() {
GameController.prototype.getMe = function() {
return this.me;
}
ClientProcessor.prototype.update = function() {
GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
@ -49,32 +48,32 @@ define(requires,
this.viewController.update();
if(this.me) {
this.inputControlUnit.update();
this.KeyboardController.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);
player.spawn(100, 0);
this.physicsEngine.setCollisionDetector(player);
return player;
}
ClientProcessor.prototype.spawnMeWithId = function(id) {
GameController.prototype.spawnMeWithId = function(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);
}
ClientProcessor.prototype.processGameCommand = function(command, options) {
GameController.prototype.processGameCommand = function(command, options) {
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) {
this.socketLink = socketLink;
this.clientGame = null;
this.GameController = null;
this.init();
}
@ -36,8 +36,8 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
}
Networker.prototype.onDisconnect = function() {
this.clientGame.destruct();
this.clientGame = null;
this.GameController.destruct();
this.GameController = null;
}
Networker.prototype.join = function(channelName){
@ -50,19 +50,19 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
}
Networker.prototype.onJoinSuccess = function(options) {
this.clientGame = new ClientGame(this, options.id);
this.clientGame.loadLevel("default.json")
this.GameController = new GameController(this, options.id);
this.GameController.loadLevel("default.json")
console.log("Joined " + options.channelName);
if (options.userIds && options.userIds.length > 0) {
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) {
this.clientGame.userJoined(userId);
this.GameController.userJoined(userId);
console.log("User " + userId + " joined");
}
@ -71,7 +71,7 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
}
Networker.prototype.onUserLeft = function(userId) {
this.clientGame.userLeft(userId);
this.GameController.userLeft(userId);
}
Networker.prototype.processControlCommand = function(command, options) {
@ -82,7 +82,7 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
case 'gameCommand':
for(var gameCommand in options) {
this.clientGame.processGameCommand(gameCommand, options[gameCommand]);
this.GameController.processGameCommand(gameCommand, options[gameCommand]);
}
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) {

View file

@ -1,11 +1,11 @@
define(['Chuck/Settings'], function(Settings) {
define(['Game/Config/Settings'], function(Settings) {
var Dom = {
var DomController = {
canvas: null,
debugCanvas: null
};
Dom.getCanvasContainer = function(){
DomController.getCanvasContainer = function(){
var container = document.getElementById(Settings.CANVAS_DOM_ID);
if(container) {
@ -15,39 +15,39 @@ define(['Chuck/Settings'], function(Settings) {
}
}
Dom.getCanvas = function(){
return Dom.canvas;
DomController.getCanvas = function(){
return DomController.canvas;
}
Dom.setCanvas = function(canvas){
DomController.setCanvas = function(canvas){
var container = Dom.getCanvasContainer();
if(Dom.canvas){
container.removeChild(Dom.canvas);
var container = DomController.getCanvasContainer();
if(DomController.canvas){
container.removeChild(DomController.canvas);
}
Dom.canvas = canvas;
DomController.canvas = canvas;
container.appendChild(canvas);
}
Dom.getDebugCanvas = function(){
return Dom.debugCanvas;
DomController.getDebugCanvas = function(){
return DomController.debugCanvas;
}
Dom.createDebugCanvas = function(){
DomController.createDebugCanvas = function(){
var container = Dom.getCanvasContainer();
if(Dom.debugCanvas){
container.removeChild(Dom.debugCanvas);
var container = DomController.getCanvasContainer();
if(DomController.debugCanvas){
container.removeChild(DomController.debugCanvas);
}
var canvas = document.createElement('canvas');
canvas.width = Settings.STAGE_WIDTH;
canvas.height = Settings.STAGE_HEIGHT;
Dom.debugCanvas = canvas;
DomController.debugCanvas = 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(){
@ -36,10 +43,10 @@ define(["Client/Dom", "Vendor/Three", "Chuck/Settings", "Chuck/View/CameraContro
this.renderer.setClearColorHex(0x333333, 1);
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
Dom.setCanvas(this.renderer.domElement);
DomController.setCanvas(this.renderer.domElement);
if(Settings.DEBUG_MODE){
Dom.createDebugCanvas();
DomController.createDebugCanvas();
}
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) {
this.name = name;
this.users = {};
this.serverGame = this.factory.new(ServerGame, this);
this.serverGame = new GameController();
console.log("server game " + this.serverGame);
this.serverGame.loadLevel("default.json");