Refactores the GLOBALS.context to use more expressive naming

Combines GLOBALS and Chuck namespace into App. Also increases
number of stack trace steps to be printed when an error occurs.

I experimented with the "replace" plugin from require.js, which
works but it would mean that our context switchable
"import-statements" would look like the example below, which I
decided against at least for now, just because of the looks.

The downside of not using the plugin is that we cannot use the
"use strict" statement in the channel.js entry script and also
cannot put a "var" in front of App variable there.

For example: "replace!Game/:AppContext/Physics/Engine",
Instead of:  "Game/" + App.context + "/Physics/Engine",

Fixes #86
This commit is contained in:
logsol 2016-10-11 23:05:33 +02:00
parent 45ea2dfba3
commit 806a9d8194
17 changed files with 59 additions and 49 deletions

View file

@ -1,11 +1,11 @@
define([ define([
"Game/" + GLOBALS.context + "/Physics/Engine", "Game/" + App.context + "/Physics/Engine",
"Game/" + GLOBALS.context + "/Loader/TiledLevel", "Game/" + App.context + "/Loader/TiledLevel",
"Game/" + GLOBALS.context + "/Player", "Game/" + App.context + "/Player",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Game/" + GLOBALS.context + "/GameObjects/Doll", "Game/" + App.context + "/GameObjects/Doll",
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + App.context + "/GameObjects/GameObject",
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Utilities/Assert", "Lib/Utilities/Assert",
], ],

View file

@ -1,10 +1,10 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + App.context + "/GameObjects/GameObject",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",
"Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + App.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"
], ],

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + App.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Lib/Utilities/OptionsHelper", "Lib/Utilities/OptionsHelper",
"Game/Config/Settings", "Game/Config/Settings",

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings" "Game/Config/Settings"
], ],

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Vendor/RubeLoader", "Lib/Vendor/RubeLoader",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"
@ -89,7 +89,7 @@ function (Parent, Box2D, Settings, Assert) {
/* /*
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Assert" "Lib/Utilities/Assert"

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + App.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D" "Lib/Vendor/Box2D"
], ],

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject", "Game/" + App.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",

View file

@ -3,12 +3,12 @@ define([
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Abstract", "Lib/Utilities/Abstract",
"Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + App.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + App.context + "/GameObjects/Tile",
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", "Game/" + App.context + "/GameObjects/Items/Skateboard",
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll", "Game/" + App.context + "/GameObjects/Items/RagDoll",
"Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll" "Game/" + App.context + "/GameObjects/Items/RubeDoll"
], function (Settings, Box2D, nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, RubeDoll) { ], function (Settings, Box2D, nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, RubeDoll) {

View file

@ -1,5 +1,5 @@
define([ define([
"Game/" + GLOBALS.context + "/Loader/Level", "Game/" + App.context + "/Loader/Level",
"Game/Config/Settings", "Game/Config/Settings",
"Game/Config/ItemSettings", "Game/Config/ItemSettings",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
@ -8,10 +8,10 @@ define([
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert", "Lib/Utilities/Assert",
"Game/Client/View/Abstract/Layer", "Game/Client/View/Abstract/Layer",
"Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + App.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + App.context + "/GameObjects/Tile",
"Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + App.context + "/GameObjects/Item",
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", "Game/" + App.context + "/GameObjects/Items/Skateboard",
], function (Parent, Settings, ItemSettings, Box2D, optionsHelper, Exception, nc, Assert, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) { ], function (Parent, Settings, ItemSettings, Box2D, optionsHelper, Exception, nc, Assert, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) {

View file

@ -1,7 +1,7 @@
define([ define([
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Vendor/Box2D", "Lib/Vendor/Box2D",
"Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + App.context + "/Collision/Detector",
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],

View file

@ -1,12 +1,12 @@
define([ define([
"Game/" + GLOBALS.context + "/GameObjects/Doll", "Game/" + App.context + "/GameObjects/Doll",
"Game/" + GLOBALS.context + "/Control/PlayerController", "Game/" + App.context + "/Control/PlayerController",
"Game/Config/Settings", "Game/Config/Settings",
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",
"Lib/Utilities/ColorConverter", "Lib/Utilities/ColorConverter",
"Game/" + GLOBALS.context + "/GameObjects/SpectatorDoll", "Game/" + App.context + "/GameObjects/SpectatorDoll",
"Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll" "Game/" + App.context + "/GameObjects/Items/RubeDoll"
], ],
function (Doll, PlayerController, Settings, nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) { function (Doll, PlayerController, Settings, nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) {

View file

@ -1,4 +1,7 @@
GLOBALS = { context: "Channel" }; // "use strict"; intentionally omitted as App scope workaround
Error.stackTraceLimit = Infinity;
var requirejs = require('requirejs'); var requirejs = require('requirejs');
requirejs.config({ requirejs.config({
@ -11,7 +14,10 @@ requirejs.config({
}, },
}); });
var inspector = {};
App = {};
App.inspector = {};
App.context = "Channel";
requirejs([ requirejs([
"Game/Channel/PipeToServer" "Game/Channel/PipeToServer"
@ -20,5 +26,5 @@ requirejs([
function (PipeToServer) { function (PipeToServer) {
var PipeToServer = new PipeToServer(process); var PipeToServer = new PipeToServer(process);
inspector.PipeToServer = PipeToServer; App.inspector.PipeToServer = PipeToServer;
}); });

View file

@ -1,6 +1,6 @@
"use strict"; "use strict";
var GLOBALS = { context: "Client" }; Error.stackTraceLimit = Infinity;
requirejs.config({ requirejs.config({
baseUrl: 'app', baseUrl: 'app',
@ -15,8 +15,9 @@ requirejs.config({
}, },
}); });
if(!Chuck) var Chuck = {}; var App = App || {};
Chuck.inspector = {}; App.inspector = {};
App.context = "Client";
requirejs([ requirejs([
"Game/Client/Networker", "Game/Client/Networker",
@ -42,10 +43,10 @@ function (Networker, SocketIO, Settings, Exception, nc, Menu) {
}; };
var socket = SocketIO.connect("/", options); var socket = SocketIO.connect("/", options);
var networker = new Networker(socket, channelName, nickname); var networker = new Networker(socket, channelName, nickname);
Chuck.inspector.networker = networker; App.inspector.networker = networker;
Chuck.inspector.settings = Settings; App.inspector.settings = Settings;
Chuck.inspector.nc = nc; App.inspector.nc = nc;
Chuck.inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); } App.inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); }
} }
menu.init(); menu.init();
}); });

View file

@ -10,7 +10,7 @@
name: "../client", name: "../client",
out: "../build/client.min.js", out: "../build/client.min.js",
onBuildRead: function (moduleName, path, contents) { onBuildRead: function (moduleName, path, contents) {
var contents = contents.replace(/\" \+ GLOBALS.context \+ \"/g, "Client"); var contents = contents.replace(/\" \+ App.context \+ \"/g, "Client");
return contents; return contents;
} }
}) })

View file

@ -1,10 +1,13 @@
"use strict" "use strict"
var GLOBALS = { context: "Channel" }; Error.stackTraceLimit = Infinity;
var requirejs = require('requirejs'); var requirejs = require('requirejs');
var fs = require('fs'); var fs = require('fs');
var inspector; var App = App || {};
App.inspector = {};
App.context = "Channel";
requirejs.config({ requirejs.config({
nodeRequire: require, nodeRequire: require,
@ -41,11 +44,11 @@ function (HttpServer, Socket, Coordinator, Settings) {
var httpServer = new HttpServer(options, coordinator); var httpServer = new HttpServer(options, coordinator);
var socket = new Socket(httpServer.getServer(), options, coordinator); var socket = new Socket(httpServer.getServer(), options, coordinator);
inspector = { App.inspector = {
coordinator: coordinator, coordinator: coordinator,
httpServer: httpServer, httpServer: httpServer,
socket: socket socket: socket
} }
}); });
exports = module.exports = inspector; exports = module.exports = App;