mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
nc refuckulating
This commit is contained in:
parent
28f71f49e1
commit
4f4bbf73e8
16 changed files with 142 additions and 58 deletions
|
|
@ -31,7 +31,7 @@
|
|||
Nc.on('broadcastControlCommand', this.broadcastControlCommand, this);
|
||||
Nc.on('broadcastControlCommandExcept', this.broadcastControlCommandExcept, this);
|
||||
|
||||
Nc.on('broadcastGameCommand', this.broadcastGameCommand, this);
|
||||
Nc.on(Nc.ns.channel.to.client.gameCommand.broadcast, this.broadcastGameCommand, this);
|
||||
Nc.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
|
||||
|
||||
console.checkpoint('channel ' + this.name + ' created');
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
Nc.on('user/joined', this.onUserJoined, this);
|
||||
Nc.on('user/left', this.onUserLeft, this);
|
||||
Nc.on('user/resetLevel', this.onResetLevel, this);
|
||||
Nc.on('user/clientReady', this.onClientReady, 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);
|
||||
|
|
@ -84,7 +84,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
y: spawnPoint.y
|
||||
};
|
||||
|
||||
Nc.trigger("broadcastGameCommand", "spawnPlayer", options);
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "spawnPlayer", options);
|
||||
}, respawnTime * 1000);
|
||||
};
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
var update = this.getWorldUpdateObject(false);
|
||||
|
||||
if(Object.getOwnPropertyNames(update).length > 0) {
|
||||
Nc.trigger("broadcastGameCommand", 'worldUpdate', update);
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, 'worldUpdate', update);
|
||||
}
|
||||
|
||||
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
||||
|
|
@ -184,12 +184,12 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
userId: userId
|
||||
}
|
||||
|
||||
Nc.trigger('user/' + userId + "/gameCommand", "clientReadyResponse", options);
|
||||
Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + userId, "clientReadyResponse", options);
|
||||
};
|
||||
|
||||
GameController.prototype.onResetLevel = function(userId) {
|
||||
Parent.prototype.onResetLevel.call(this);
|
||||
Nc.trigger("broadcastGameCommand", "resetLevel", true);
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "resetLevel", true);
|
||||
for (var key in this.players) {
|
||||
this.spawnPlayer(this.players[key]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ function (Parent, Item, Box2D, Nc) {
|
|||
self.player.addDamage(damage.Length() * 2, player);
|
||||
}
|
||||
|
||||
Nc.trigger("engine/addToWorldQueue", callback)
|
||||
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ function (Parent, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.destroy = function() {
|
||||
Nc.trigger("broadcastGameCommand", 'removeGameObject', {
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, 'removeGameObject', {
|
||||
type: 'animated',
|
||||
uid: this.uid
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ function (Nc, Channel) {
|
|||
this.channel = null;
|
||||
this.process = process;
|
||||
|
||||
Nc.on('process/message', this.send, this);
|
||||
Nc.on(Nc.ns.channel.to.server.controlCommand.send, this.send, this);
|
||||
|
||||
process.on('message', function (message, handle) {
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function (Parent, Nc) {
|
|||
options.action = "throw";
|
||||
options.x = x;
|
||||
options.y = y;
|
||||
Nc.trigger("broadcastGameCommand", "handActionResponse", options);
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "handActionResponse", options);
|
||||
}
|
||||
} else {
|
||||
// grab
|
||||
|
|
@ -51,7 +51,7 @@ function (Parent, Nc) {
|
|||
this.grab(item);
|
||||
|
||||
options.action = "grab";
|
||||
Nc.trigger("broadcastGameCommand", "handActionResponse", options);
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "handActionResponse", options);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -85,7 +85,7 @@ function (Parent, Nc) {
|
|||
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
|
||||
|
||||
this.broadcastStats();
|
||||
Nc.trigger("broadcastGameCommand", "playerKill", {
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "playerKill", {
|
||||
playerId: this.id,
|
||||
killedByPlayerId: killedByPlayer.id,
|
||||
ragDollId: ragDollId
|
||||
|
|
@ -102,7 +102,7 @@ function (Parent, Nc) {
|
|||
};
|
||||
|
||||
Player.prototype.broadcastStats = function() {
|
||||
Nc.trigger("broadcastGameCommand", "updateStats", {
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "updateStats", {
|
||||
playerId: this.id,
|
||||
stats: this.stats
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
|||
this.isReady = false;
|
||||
var self = this;
|
||||
|
||||
Nc.on('user/' + this.id + "/joinSuccess", function(options) {
|
||||
Nc.on(Nc.ns.channel.to.client.user.controlCommand.joinSuccess + this.id, function(options) {
|
||||
self.sendControlCommand("joinSuccess", options);
|
||||
});
|
||||
|
||||
|
|
@ -22,9 +22,12 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
|||
ProtocolHelper.applyCommand(message.data, self);
|
||||
});
|
||||
|
||||
/*
|
||||
couldnt find trigger for this while refactoring
|
||||
Nc.on('user/' + this.id + "/gameCommand", function(command, options) {
|
||||
self.sendGameCommand(command, options);
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -43,10 +46,10 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
|||
} // FIXME: move this to Protocol helper as a function
|
||||
|
||||
if(command.hasOwnProperty("resetLevel")) {
|
||||
Nc.trigger("user/resetLevel", this.id);
|
||||
Nc.trigger(Nc.ns.channel.events.user.level.reset, this.id);
|
||||
} else if(command.hasOwnProperty("clientReady")) {
|
||||
this.isReady = true;
|
||||
Nc.trigger("user/clientReady", this.id);
|
||||
Nc.trigger(Nc.ns.channel.events.user.client.ready, this.id);
|
||||
} else {
|
||||
this.player.playerController.applyCommand(command);
|
||||
}
|
||||
|
|
@ -60,7 +63,7 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
|||
var recipient = "user/" + this.id;
|
||||
var data = ProtocolHelper.encodeCommand(command, options);
|
||||
|
||||
Nc.trigger("process/message", recipient, data);
|
||||
Nc.trigger(Nc.ns.channel.to.server.controlCommand.send, recipient, data);
|
||||
};
|
||||
|
||||
User.prototype.sendGameCommand = function(command, options) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ function (Parent, Nc, Settings) {
|
|||
var callback = function(playerInfoView) {
|
||||
self.playerInfoView = playerInfoView;
|
||||
}
|
||||
Nc.trigger("view/createAndAddPlayerInfo", callback, options);
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.createAndAdd, callback, options);
|
||||
};
|
||||
|
||||
Player.prototype.onHealthChange = function() {
|
||||
|
|
@ -69,15 +69,15 @@ function (Parent, Nc, Settings) {
|
|||
healthFactor: this.stats.health / 100,
|
||||
visible: this.playerInfoViewVisible
|
||||
};
|
||||
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, options);
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, options);
|
||||
|
||||
this.playerInfoViewVisibleTimeout = setTimeout(function() {
|
||||
self.playerInfoViewVisible = false;
|
||||
Nc.trigger("view/updatePlayerInfo", self.playerInfoView, {visible: self.playerInfoViewVisible});
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, self.playerInfoView, {visible: self.playerInfoViewVisible});
|
||||
}, Settings.HEALTH_DISPLAY_TIME * 1000);
|
||||
|
||||
} else {
|
||||
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, {visible: this.playerInfoViewVisible});
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, {visible: this.playerInfoViewVisible});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ function (Parent, Nc, Settings) {
|
|||
x: position.x * Settings.RATIO,
|
||||
y: position.y * Settings.RATIO,
|
||||
}
|
||||
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, options);
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, options);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function (Settings, Nc, Stats, Screenfull) {
|
|||
this.stats = null;
|
||||
this.ping = null;
|
||||
|
||||
Nc.on("view/ready", this.initDevTools, this);
|
||||
Nc.on(Nc.ns.client.view.events.ready, this.initDevTools, this);
|
||||
}
|
||||
|
||||
DomController.prototype.initDevTools = function() {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function (Settings, Exception, AbstractView, PixiView, Nc) {
|
|||
throw new Exception("In the view", Settings.VIEW_CONTROLLER + 'View', "this.setCanvas(canvas) has not been called with a valid HTMLCanvasElement!");
|
||||
}
|
||||
|
||||
Nc.trigger("view/ready", view);
|
||||
Nc.trigger(Nc.ns.client.view.events.ready, view);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ function (DomController, Settings, Exception, Nc) {
|
|||
|
||||
Nc.on("view/toggleInfo", this.onToggleInfo, this);
|
||||
|
||||
Nc.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
|
||||
Nc.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, 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("view/updateLoader", this.onUpdateLoader, this);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function (Settings, Box2D, CollisionDetector, Nc) {
|
|||
this.lastStep = Date.now();
|
||||
this.worldQueue = [];
|
||||
|
||||
Nc.on("engine/addToWorldQueue", this.addToWorldQueue, this);
|
||||
Nc.on(Nc.ns.channel.engine.worldQueue.add, this.addToWorldQueue, this);
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function () {
|
||||
|
|
|
|||
|
|
@ -1,80 +1,159 @@
|
|||
define([
|
||||
"Lib/Utilities/Exception"
|
||||
],
|
||||
|
||||
function () {
|
||||
function (Exception) {
|
||||
|
||||
function populate(obj, path) {
|
||||
path = path || "Nc.ns";
|
||||
for(var key in obj) {
|
||||
if(!obj.hasOwnProperty(key)) continue;
|
||||
if(obj[key] === null) {
|
||||
obj[key] = path + "." + key;
|
||||
} else {
|
||||
obj[key] = populate(obj[key], path + "." + key);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function NotificationCenter () {
|
||||
this.topics = {};
|
||||
this.subUid = -1;
|
||||
/*
|
||||
|
||||
var i = 0;
|
||||
this.nc = {
|
||||
this.ns = {
|
||||
client: {
|
||||
view: {
|
||||
mesh: {
|
||||
create: i++,
|
||||
add: i++,
|
||||
remove: i++,
|
||||
update: i++
|
||||
create: null,
|
||||
add: null,
|
||||
remove: null,
|
||||
update: null
|
||||
},
|
||||
playerInfo: {
|
||||
createAndAdd: i++,
|
||||
remove: i++,
|
||||
update: i++
|
||||
createAndAdd: null,
|
||||
remove: null,
|
||||
update: null
|
||||
},
|
||||
preloadBar: {
|
||||
update: i++
|
||||
update: null
|
||||
},
|
||||
fullScreen: {
|
||||
change: i++
|
||||
change: null
|
||||
},
|
||||
debugMode: {
|
||||
toggle: i++
|
||||
toggle: null
|
||||
},
|
||||
gameInfo: {
|
||||
toggle: i++
|
||||
}
|
||||
toggle: null
|
||||
},
|
||||
events: {
|
||||
ready: i++
|
||||
ready: null
|
||||
}
|
||||
},
|
||||
input: {
|
||||
handAction: {
|
||||
request: i++
|
||||
request: null
|
||||
},
|
||||
xy: {
|
||||
change: i++
|
||||
change: null
|
||||
}
|
||||
},
|
||||
server: {
|
||||
gameCommand: {
|
||||
send: i++
|
||||
send: null
|
||||
}
|
||||
}
|
||||
},
|
||||
core: {
|
||||
game: {
|
||||
gameObject: {
|
||||
add: i++,
|
||||
remove: i++
|
||||
}
|
||||
add: null,
|
||||
remove: null
|
||||
},
|
||||
events: {
|
||||
level: {
|
||||
loaded: i++
|
||||
loaded: null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
channel: {
|
||||
pipeToServer: function(v) { return v + "-ns.channel.pipeToServer")}
|
||||
events: {
|
||||
controlCommand: null,
|
||||
user: {
|
||||
joined: null,
|
||||
left: null,
|
||||
client: {
|
||||
ready: null
|
||||
},
|
||||
level: {
|
||||
reset: null
|
||||
}
|
||||
}
|
||||
},
|
||||
engine: {
|
||||
worldQueue: {
|
||||
add: null
|
||||
}
|
||||
},
|
||||
to: {
|
||||
server: {
|
||||
send: null
|
||||
},
|
||||
client: {
|
||||
user: {
|
||||
gameCommand: {
|
||||
send: null
|
||||
},
|
||||
controlCommand: {
|
||||
joinSuccess: null
|
||||
}
|
||||
},
|
||||
gameCommand: {
|
||||
broadcast: null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
server: {
|
||||
events: {
|
||||
controlCommand: null,
|
||||
user: {
|
||||
joined: null,
|
||||
left: null
|
||||
}
|
||||
},
|
||||
to: {
|
||||
client: {
|
||||
message: {
|
||||
send: null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
populate(this.ns);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
NotificationCenter.prototype.validate = function(topic) {
|
||||
if (typeof topic === 'object') {
|
||||
throw new Exception("Topic bad format " + JSON.stringify(topic));
|
||||
}
|
||||
|
||||
if (topic.indexOf("Nc.ns") !== 0) {
|
||||
throw new Exception("Topic bad format, does not begin with Nc.ns. : " + topic);
|
||||
}
|
||||
};
|
||||
|
||||
NotificationCenter.prototype.trigger = function (topic /*, arguments*/) {
|
||||
|
||||
this.validate(topic);
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
console.warn("No such topic " + topic + ". Could not trigger. arguments: " + arguments.join);
|
||||
}
|
||||
|
|
@ -91,6 +170,8 @@ function () {
|
|||
|
||||
NotificationCenter.prototype.on = function (topic, func, context) {
|
||||
|
||||
this.validate(topic);
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
this.topics[topic] = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ function (User, Channel, PipeToChannel, Nc, Settings) {
|
|||
function Coordinator() {
|
||||
this.channelPipes = {};
|
||||
|
||||
Nc.on('coordinator/message', this.onMessage, this);
|
||||
Nc.on(Nc.ns.server.events.controlCommand + "coordinator", this.onMessage, this);
|
||||
|
||||
console.checkpoint('create Coordinator');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ function (Nc, childProcess) {
|
|||
}
|
||||
|
||||
PipeToChannel.prototype.onMessage = function (message) {
|
||||
Nc.trigger(message.recipient + '/message', message.data);
|
||||
Nc.trigger(Nc.ns.server.events.controlCommand + message.recipient, message.data);
|
||||
}
|
||||
|
||||
return PipeToChannel;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function (Parent, ProtocolHelper, Nc) {
|
|||
socketLink.on('message', this.onMessage.bind(this));
|
||||
socketLink.on('disconnect', this.onDisconnect.bind(this));
|
||||
|
||||
Nc.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink);
|
||||
Nc.on(Nc.ns.server.to.client.message.send + id, this.socketLink.send, this.socketLink);
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -73,7 +73,7 @@ function (Parent, ProtocolHelper, Nc) {
|
|||
|
||||
User.prototype.onPing = function(timestamp) {
|
||||
var message = ProtocolHelper.encodeCommand("pong", timestamp);
|
||||
Nc.trigger("user/" + this.socketLink.id + "/message", message);
|
||||
Nc.trigger(Nc.ns.server.to.client.message.send + id, message);
|
||||
};
|
||||
|
||||
return User;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue