This commit is contained in:
logsol 2014-03-17 21:58:54 +01:00
commit f7ca9d2393
23 changed files with 69 additions and 67 deletions

View file

@ -50,7 +50,7 @@
var self = this;
if(!this.gameController.level || !this.gameController.level.isLoaded) {
var token = Nc.on("game/level/loaded", function() {
var token = Nc.on(Nc.ns.core.game.events.level.loaded, function() {
self.sendJoinSuccess(options);
Nc.off(token);
});
@ -82,14 +82,14 @@
//Nc.trigger('user/' + user.id + "/joinSuccess", options);
user.sendControlCommand("joinSuccess", options);
Nc.trigger('user/joined', user);
Nc.trigger(Nc.ns.channel.events.user.joined, user);
this.broadcastControlCommandExcept("userJoined", user.options, user);
};
Channel.prototype.onReleaseUser = function (userId) {
var user = this.users[userId];
Nc.trigger('user/left', userId);
Nc.trigger(Nc.ns.channel.events.user.left, userId);
delete this.users[userId];
this.broadcastControlCommand("userLeft", userId);

View file

@ -20,10 +20,11 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Parent.call(this);
Nc.on('user/joined', this.onUserJoined, this);
Nc.on('user/left', this.onUserLeft, this);
Nc.on(Nc.ns.channel.events.user.joined, this.onUserJoined, this);
Nc.on(Nc.ns.channel.events.user.left, this.onUserLeft, this);
Nc.on(Nc.ns.channel.events.user.level.reset, this.onResetLevel, this);
Nc.on(Nc.ns.channel.events.user.client.ready, this.onClientReady, this);
Nc.on('player/killed', this.onPlayerKilled, this);
console.checkpoint('starting game controller for channel ' + channel.name);

View file

@ -37,7 +37,7 @@ function (Nc, Channel) {
};
PipeToServer.prototype.onMessage = function (message) {
Nc.trigger(message.recipient + '/controlCommand', message);
Nc.trigger(Nc.ns.channel.events.controlCommand + recipient, message);
}
PipeToServer.prototype.destroy = function() {

View file

@ -37,7 +37,7 @@ function (Parent, DomController, Settings, Nc) {
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1;
var y = (((Settings.STAGE_HEIGHT - (e.clientY - this.offsetTop)) / Settings.STAGE_HEIGHT) * 2) -1;
Nc.trigger("input/onHandActionRequest", x, y);
Nc.trigger(Nc.ns.client.input.handAction.request, x, y);
}
};

View file

@ -12,7 +12,7 @@ function (Nc) {
XyInput.prototype.onXyChange = function(x, y) {
this.x = x;
this.y = y;
Nc.trigger('input/onXyChange', x, y);
Nc.trigger(Nc.ns.client.input.xy.change, x, y);
}
return XyInput;

View file

@ -14,8 +14,8 @@ function (Parent, KeyboardInput, MouseInput, Nc) {
this.keyboardInput = new KeyboardInput(this);
this.xyInput = new MouseInput(this);
Nc.on("input/onXyChange", this.setXY, this);
Nc.on("input/onHandActionRequest", this.handActionRequest, this);
Nc.on(Nc.ns.client.input.xy.change, this.setXY, this);
Nc.on(Nc.ns.client.input.handAction.request, this.handActionRequest, this);
var keys = {
w:87,
@ -64,33 +64,33 @@ function (Parent, KeyboardInput, MouseInput, Nc) {
PlayerController.prototype.moveLeft = function () {
Parent.prototype.moveLeft.call(this);
Nc.trigger('sendGameCommand', 'moveLeft');
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'moveLeft');
}
PlayerController.prototype.moveRight = function () {
Parent.prototype.moveRight.call(this);
Nc.trigger('sendGameCommand', 'moveRight');
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'moveRight');
}
PlayerController.prototype.stop = function () {
Parent.prototype.stop.call(this);
Nc.trigger('sendGameCommand', 'stop');
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'stop');
}
PlayerController.prototype.jump = function () {
Parent.prototype.jump.call(this);
Nc.trigger('sendGameCommand', 'jump');
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'jump');
}
PlayerController.prototype.jumpStop = function () {
Parent.prototype.jumpStop.call(this);
Nc.trigger('sendGameCommand', 'jumpStop');
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'jumpStop');
}
PlayerController.prototype.setXY = function(x, y) {
var options = {x:x, y:y};
Parent.prototype.lookAt.call(this, options);
Nc.trigger('sendGameCommand', 'lookAt', options);
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'lookAt', options);
};
PlayerController.prototype.handActionLeft = function() {
@ -102,20 +102,20 @@ function (Parent, KeyboardInput, MouseInput, Nc) {
};
PlayerController.prototype.suicide = function() {
Nc.trigger("sendGameCommand", "suicide");
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide");
};
PlayerController.prototype.handActionRequest = function(x, y) {
var options = {x:x, y:y};
Nc.trigger("sendGameCommand", "handActionRequest", options);
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "handActionRequest", options);
};
PlayerController.prototype.showInfo = function() {
Nc.trigger("game/toggleInfo", true);
Nc.trigger(Nc.ns.client.view.gameInfo.toggle, true);
};
PlayerController.prototype.hideInfo = function() {
Nc.trigger("game/toggleInfo", false);
Nc.trigger(Nc.ns.client.view.gameInfo.toggle, false);
};

View file

@ -18,7 +18,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
this.view = ViewManager.createView();
this.me = null;
Nc.on("game/toggleInfo", this.toggleInfo, this);
Nc.on(Nc.ns.client.view.gameInfo.toggle, this.toggleInfo, this);
Parent.call(this);
}

View file

@ -35,12 +35,12 @@ function (Parent, Settings, Nc, Exception) {
if(!state) throw new Exception("action state is undefined");
if(this.animatedMeshes[this.actionState]) {
Nc.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
Nc.trigger(Nc.ns.client.view.mesh.update, this.animatedMeshes[this.actionState], { visible: false });
}
Parent.prototype.setActionState.call(this, state);
Nc.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: true });
Nc.trigger(Nc.ns.client.view.mesh.update, this.animatedMeshes[this.actionState], { visible: true });
}
Doll.prototype.createMesh = function() {
@ -74,7 +74,7 @@ function (Parent, Settings, Nc, Exception) {
var callback = function(mesh) {
self.animatedMeshes[key] = mesh;
Nc.trigger("view/addMesh", mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
};
Nc.trigger("view/createAnimatedMesh", texturePaths, callback, {
@ -93,7 +93,7 @@ function (Parent, Settings, Nc, Exception) {
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
var callback = function (mesh) {
self.headMesh = mesh;
Nc.trigger("view/addMesh", mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
}
Nc.trigger("view/createMesh", texturePath, callback, {
pivot: {
@ -113,7 +113,7 @@ function (Parent, Settings, Nc, Exception) {
if(oldLookDirection != this.lookDirection) {
for(var key in this.animatedMeshes) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.animatedMeshes[key],
{
xScale: this.lookDirection
@ -124,7 +124,7 @@ function (Parent, Settings, Nc, Exception) {
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.headMesh,
{
xScale: this.lookDirection,
@ -136,17 +136,17 @@ function (Parent, Settings, Nc, Exception) {
Doll.prototype.destroy = function () {
for (var key in this.animatedMeshes) {
Nc.trigger("view/removeMesh", this.animatedMeshes[key]);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.animatedMeshes[key]);
}
Nc.trigger("view/removeMesh", this.headMesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.headMesh);
Parent.prototype.destroy.call(this);
}
Doll.prototype.render = function() {
if(this.actionState) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.animatedMeshes[this.actionState],
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -155,7 +155,7 @@ function (Parent, Settings, Nc, Exception) {
}
);
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.headMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -22,7 +22,7 @@ function (Parent, Settings, Nc) {
var callback = function(mesh) {
self.mesh = mesh;
Nc.trigger("view/addMesh", mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
}
Nc.trigger("view/createMesh",
@ -40,13 +40,13 @@ function (Parent, Settings, Nc) {
};
Item.prototype.destroy = function() {
Nc.trigger("view/removeMesh", this.mesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh);
Parent.prototype.destroy.call(this);
};
Item.prototype.render = function() {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -62,7 +62,7 @@ function (Parent, Settings, Nc) {
Parent.prototype.flip.call(this, direction);
if(oldFlipDirection != direction) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.mesh,
{
xScale: direction

View file

@ -37,7 +37,7 @@ function (Parent, CoreItem, Settings, Nc) {
self.limbMeshes[name] = mesh;
}
Nc.trigger("view/addMesh", mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
}
Nc.trigger("view/createMesh",
@ -60,7 +60,7 @@ function (Parent, CoreItem, Settings, Nc) {
if(this.limbs) {
for(var name in this.limbMeshes) {
if(this.limbs[name]) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.limbMeshes[name],
{
x: this.limbs[name].GetPosition().x * Settings.RATIO,
@ -80,7 +80,7 @@ function (Parent, CoreItem, Settings, Nc) {
CoreItem.prototype.flip.call(this, direction);
if(oldFlipDirection != direction) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.mesh,
{
xScale: direction
@ -88,7 +88,7 @@ function (Parent, CoreItem, Settings, Nc) {
);
for (var name in this.limbMeshes) {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.limbMeshes[name],
{
xScale: direction
@ -100,7 +100,7 @@ function (Parent, CoreItem, Settings, Nc) {
RagDoll.prototype.destroy = function() {
for (var name in this.limbMeshes) {
Nc.trigger("view/removeMesh", this.limbMeshes[name]);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.limbMeshes[name]);
};
Parent.prototype.destroy.call(this);

View file

@ -27,7 +27,7 @@ function (Parent, Settings, Nc) {
var callback = function(mesh) {
self.mesh = mesh;
Nc.trigger("view/addMesh", mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
}
Nc.trigger("view/createMesh",
@ -45,13 +45,13 @@ function (Parent, Settings, Nc) {
};
Tile.prototype.destroy = function() {
Nc.trigger("view/removeMesh", this.mesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh);
Parent.prototype.destroy.call(this);
};
Tile.prototype.render = function() {
Nc.trigger("view/updateMesh",
Nc.trigger(Nc.ns.client.view.mesh.update,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -39,7 +39,7 @@ function (Parent, Settings, Nc, PIXI) {
loader.onComplete = function() { callback(levelData); };
loader.onProgress = function() {
var progress = parseInt(100 / numPaths * ++count, 10) + 1;
Nc.trigger("view/updateLoader", progress);
Nc.trigger(Nc.ns.client.view.preloadBar.update, progress);
}
loader.load();
};

View file

@ -26,8 +26,8 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
ProtocolHelper.applyCommand(message, self);
});
Nc.on("sendGameCommand", this.sendGameCommand, this);
Nc.on("game/level/loaded", this.onLevelLoaded, this);
Nc.on(Nc.ns.client.to.server.gameCommand.send, this.sendGameCommand, this);
Nc.on(Nc.ns.core.game.events.level.loaded, this.onLevelLoaded, this);
}
// Socket callbacks

View file

@ -13,7 +13,7 @@ function (Parent, Settings, DomController, Box2D, Nc) {
this.debugMode = false;
Nc.on("view/toggleDebugMode", this.onToggleDebugMode, this);
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this);
}
Engine.prototype = Object.create(Parent.prototype);

View file

@ -102,7 +102,7 @@ function (Parent, Nc, Settings) {
Player.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
Nc.trigger("view/removePlayerInfo", this.playerInfoView);
Nc.trigger(Nc.ns.client.view.playerInfo.remove, this.playerInfoView);
};
return Player;

View file

@ -39,7 +39,7 @@ function (Settings, Nc, Stats, Screenfull) {
window.onresize = function() {
if(Screenfull.enabled) {
Nc.trigger("view/fullscreenChange", Screenfull.isFullscreen);
Nc.trigger(Nc.ns.client.view.fullscreen.change, Screenfull.isFullscreen);
}
}
@ -71,7 +71,7 @@ function (Settings, Nc, Stats, Screenfull) {
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.onclick = function(e) {
Nc.trigger("view/toggleDebugMode", e.target.checked);
Nc.trigger(Nc.ns.client.view.debugMode.toggle, e.target.checked);
self.getDebugCanvas().style.display = e.target.checked ? "" : "none";
}
label.appendChild(checkbox);

View file

@ -14,20 +14,21 @@ function (DomController, Settings, Exception, Nc) {
Nc.on("view/createMesh", this.createMesh, this);
Nc.on("view/createAnimatedMesh", this.createAnimatedMesh, this);
Nc.on("view/addMesh", this.addMesh, this);
Nc.on("view/removeMesh", this.removeMesh, this);
Nc.on("view/updateMesh", this.updateMesh, this);
Nc.on(Nc.ns.client.view.mesh.add, this.addMesh, this);
Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this);
Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this);
Nc.on("view/fullscreenChange", this.onFullscreenChange, this);
Nc.on("view/toggleDebugMode", this.onToggleDebugMode, this);
Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this);
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this);
Nc.on("view/toggleInfo", this.onToggleInfo, this);
Nc.on(Nc.ns.client.view.playerInfo.createAndAdd, this.onCreateAndAddPlayerInfo, this);
Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, this);
Nc.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
Nc.on(Nc.ns.client.view.playerInfo.remove, this.onRemovePlayerInfo, this);
Nc.on("view/updateLoader", this.onUpdateLoader, this);
Nc.on(Nc.ns.client.view.preloadBar.update, this.onUpdateLoader, this);
}
AbstractView.prototype.isWebGlEnabled = function () {

View file

@ -18,7 +18,7 @@ define(function() {
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
GRAPHICS_SUBPATH_TILES: 'Tiles/',
MAPS_PATH: 'static/maps/tiled/',
DEFAULT_LEVELS: ['stones2', 'debug'],
DEFAULT_LEVELS: ['debug', 'stones2', 'debug'],
RATIO: 21, //35
// original tile size is 25 but we want it to resize to 20

View file

@ -16,10 +16,10 @@ function (PhysicsEngine, TiledLevel, Player, Nc) {
this.physicsEngine = new PhysicsEngine();
this.physicsEngine.setCollisionDetector();
Nc.on("game/level/loaded", this.onLevelLoaded, this);
Nc.on(Nc.ns.core.game.events.level.loaded, this.onLevelLoaded, this);
Nc.on("game/object/add", this.onGameObjectAdd, this);
Nc.on("game/object/remove", this.onGameObjectRemove, this);
Nc.on(Nc.ns.core.game.gameObject.add, this.onGameObjectAdd, this);
Nc.on(Nc.ns.core.game.gameObject.remove, this.onGameObjectRemove, this);
this.update();
}

View file

@ -163,7 +163,7 @@ function (Parent, Box2D, Settings, Nc) {
);
Nc.trigger("game/object/add", 'animated', this);
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -362,7 +362,7 @@ function (Parent, Box2D, Settings, Nc) {
};
RagDoll.prototype.destroy = function() {
Nc.trigger("game/object/remove", 'animated', this);
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
var world = this.body.GetWorld();
Parent.prototype.destroy.call(this);

View file

@ -28,7 +28,7 @@ define([
self.createTiles();
self.createItems();
self.isLoaded = true;
Nc.trigger("game/level/loaded");
Nc.trigger(Nc.ns.core.game.events.level.loaded);
});
}

View file

@ -40,7 +40,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y);
this.isSpawned = true;
Nc.trigger("game/object/add", 'animated', this.doll);
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this.doll);
}
Player.prototype.getPosition = function () {
@ -120,7 +120,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.isSpawned = false;
Nc.trigger("game/object/remove", 'animated', this.doll);
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this.doll);
this.doll.destroy();
this.doll = null;

View file

@ -40,7 +40,7 @@ function (Parent, ProtocolHelper, GameController, User, Nc) {
}
}, this);
Nc.on("sendGameCommand", this.sendGameCommand, this);
Nc.on(Nc.ns.client.to.server.gameCommand.send, this.sendGameCommand, this);
}
Worker.prototype.sendCommand = function (command, options) {