moved Protocol and NotificationCenter to Lib/Utilities

This commit is contained in:
jeena 2013-12-27 01:36:01 +01:00
parent 93e8133c89
commit 3aa89fc8d6
24 changed files with 30 additions and 30 deletions

View file

@ -1,5 +1,5 @@
define([
"Game/Core/NotificationCenter"
"Lib/Utilities/NotificationCenter"
],
function (NotificationCenter) {

View file

@ -2,7 +2,7 @@ define([
"Game/Core/Control/PlayerController",
"Game/Client/Control/KeyboardInput",
"Game/Client/Control/Input/MouseInput",
"Game/Core/NotificationCenter"
"Lib/Utilities/NotificationCenter"
],
function (Parent, KeyboardInput, MouseInput, NotificationCenter) {

View file

@ -4,12 +4,12 @@ define([
"Game/Client/Physics/Engine",
"Game/Client/View/ViewManager",
"Game/Client/Control/PlayerController",
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/RequestAnimFrame",
"Game/Config/Settings",
"Lib/Vendor/Stats",
"Game/Client/GameObjects/GameObject",
"Game/Client/Physics/Doll"
"Game/Client/GameObjects/Doll"
],
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, NotificationCenter, requestAnimFrame, Settings, Stats, GameObject, Doll) {

View file

@ -1,7 +1,7 @@
define([
"Game/Core/Physics/Doll",
"Game/Core/GameObjects/Doll",
"Game/Config/Settings",
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception"
],

View file

@ -1,7 +1,7 @@
define([
"Game/Core/GameObjects/Item",
"Game/Config/Settings",
"Game/Core/NotificationCenter"
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, NotificationCenter) {

View file

@ -1,7 +1,7 @@
define([
"Game/Core/GameObjects/Tile",
"Game/Config/Settings",
"Game/Core/NotificationCenter"
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, NotificationCenter) {

View file

@ -1,8 +1,8 @@
define([
"Game/Core/Protocol/Helper",
"Lib/Utilities/Protocol/Helper",
"Game/Client/GameController",
"Game/Client/User",
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Game/Config/Settings"
],

View file

@ -2,7 +2,7 @@ define([
"Game/Client/View/DomController",
"Game/Config/Settings",
"Lib/Utilities/Exception",
"Game/Core/NotificationCenter"
"Lib/Utilities/NotificationCenter"
],
function (DomController, Settings, Exception, NotificationCenter) {

View file

@ -1,58 +0,0 @@
define([
],
function () {
function NotificationCenter () {
this.topics = {};
this.subUid = -1;
}
NotificationCenter.prototype.trigger = function (topic /*, arguments*/) {
if (!this.topics[topic]) {
throw "No such topic " + topic + ". Could not trigger. arguments: " + arguments.join;
}
var args = Array.prototype.slice.call(arguments, 1);
var subscribers = this.topics[topic];
var len = subscribers ? subscribers.length : 0;
while (len--) {
var subscriber = subscribers[len];
subscriber.func.apply(subscriber.context, args);
}
}
NotificationCenter.prototype.on = function (topic, func, context) {
if (!this.topics[topic]) {
this.topics[topic] = [];
}
var token = ( ++this.subUid ).toString();
this.topics[topic].push({
token: token,
func: func,
context: context
});
return token;
}
NotificationCenter.prototype.off = function (token) {
for(var m in this.topics) {
if (this.topics[m]) {
for(var i = 0, j = this.topics[m].length; i < j; i++) {
if (this.topics[m][i].token === token) {
this.topics[m].splice(i, 1);
return token;
}
}
}
}
}
return new NotificationCenter(); // making it singletone
});

View file

@ -1,5 +1,5 @@
define([
"Game/" + GLOBALS.context + "/Physics/Doll",
"Game/" + GLOBALS.context + "/GameObjects/Doll",
"Game/Config/Settings"
],

View file

@ -1,40 +0,0 @@
define([
"Game/Core/Protocol/Parser",
"Lib/Utilities/Exception"
],
function (Parser, Exception) {
var Helper = {}
Helper.encodeCommand = function (command, options) {
var message = {};
message[command] = options || null;
return Parser.encode(message);
}
Helper.applyCommand = function(options, target) {
var message;
if (typeof options == "string") {
message = Parser.decode(options);
} else {
message = options;
}
// The for loop is only here to get the key, it is not designed to get multiple commands
for(var command in message) {
var methodName = "on" + command.toUpperCaseFirstChar();
var options = message[command];
if (!target[methodName]) {
throw new Exception("Helper.applyCommand:", target, "has no method", methodName);
}
target[methodName].call(target, options);
}
};
return Helper;
});

View file

@ -1,17 +0,0 @@
define([
],
function () {
var Parser = {};
Parser.encode = function (message) {
return JSON.stringify(message);
}
Parser.decode = function (message) {
return JSON.parse(message);
}
return Parser;
});

View file

@ -1,8 +1,8 @@
define([
"Game/Server/GameController",
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Game/Server/User",
"Game/Core/Protocol/Helper"
"Lib/Utilities/Protocol/Helper"
],
function (GameController, NotificationCenter, User, ProtocolHelper) {

View file

@ -1,7 +1,7 @@
define([
"Game/Core/Control/PlayerController",
"Game/Core/NotificationCenter",
"Game/Core/Protocol/Parser"
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Protocol/Parser"
],
function(Parent, NotificationCenter, Parser) {

View file

@ -4,10 +4,10 @@ define([
"Game/Config/Settings",
"Game/Server/Control/PlayerController",
"Lib/Utilities/RequestAnimFrame",
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Game/Server/Player",
"Game/Server/GameObjects/GameObject",
"Game/Server/Physics/Doll"
"Game/Server/GameObjects/Doll"
],
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Player, GameObject, Doll) {

View file

@ -1,5 +1,5 @@
define([
"Game/Core/Physics/Doll"
"Game/Core/GameObjects/Doll"
],
function(Parent) {

View file

@ -1,5 +1,5 @@
define([
"Game/Core/NotificationCenter",
"Lib/Utilities/NotificationCenter",
"Game/Server/Channel"
],

View file

@ -1,7 +1,7 @@
define([
"Game/Core/User",
"Game/Core/NotificationCenter",
"Game/Core/Protocol/Helper"
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Protocol/Helper"
],
function(Parent, NotificationCenter, ProtocolHelper) {