From 806a9d8194fbd7d318afbc88fe7493863244a29f Mon Sep 17 00:00:00 2001 From: logsol Date: Tue, 11 Oct 2016 23:05:33 +0200 Subject: [PATCH] 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 --- app/Game/Core/GameController.js | 12 ++++++------ app/Game/Core/GameObjects/Doll.js | 6 +++--- app/Game/Core/GameObjects/Item.js | 2 +- app/Game/Core/GameObjects/Items/RagDoll.js | 2 +- app/Game/Core/GameObjects/Items/RagDoll2.js | 2 +- app/Game/Core/GameObjects/Items/RubeDoll.js | 2 +- app/Game/Core/GameObjects/Items/Skateboard.js | 4 ++-- app/Game/Core/GameObjects/SpectatorDoll.js | 2 +- app/Game/Core/GameObjects/Tile.js | 2 +- app/Game/Core/Loader/Level.js | 12 ++++++------ app/Game/Core/Loader/TiledLevel.js | 10 +++++----- app/Game/Core/Physics/Engine.js | 2 +- app/Game/Core/Player.js | 8 ++++---- channel.js | 14 ++++++++++---- client.js | 15 ++++++++------- config/build-profile.js | 2 +- server.js | 11 +++++++---- 17 files changed, 59 insertions(+), 49 deletions(-) diff --git a/app/Game/Core/GameController.js b/app/Game/Core/GameController.js index caea9c3..3e01d5e 100755 --- a/app/Game/Core/GameController.js +++ b/app/Game/Core/GameController.js @@ -1,11 +1,11 @@ define([ - "Game/" + GLOBALS.context + "/Physics/Engine", - "Game/" + GLOBALS.context + "/Loader/TiledLevel", - "Game/" + GLOBALS.context + "/Player", + "Game/" + App.context + "/Physics/Engine", + "Game/" + App.context + "/Loader/TiledLevel", + "Game/" + App.context + "/Player", "Lib/Utilities/NotificationCenter", - "Game/" + GLOBALS.context + "/GameObjects/Doll", - "Game/" + GLOBALS.context + "/GameObjects/GameObject", - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Doll", + "Game/" + App.context + "/GameObjects/GameObject", + "Game/" + App.context + "/GameObjects/Item", "Lib/Utilities/Assert", ], diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 32c3e05..e6dcfe8 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -1,10 +1,10 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/GameObject", + "Game/" + App.context + "/GameObjects/GameObject", "Lib/Utilities/Exception", "Lib/Vendor/Box2D", "Game/Config/Settings", - "Game/" + GLOBALS.context + "/Collision/Detector", - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/Collision/Detector", + "Game/" + App.context + "/GameObjects/Item", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Assert" ], diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index 4e25fb0..515e96a 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/GameObject", + "Game/" + App.context + "/GameObjects/GameObject", "Lib/Vendor/Box2D", "Lib/Utilities/OptionsHelper", "Game/Config/Settings", diff --git a/app/Game/Core/GameObjects/Items/RagDoll.js b/app/Game/Core/GameObjects/Items/RagDoll.js index 48faba6..840582e 100644 --- a/app/Game/Core/GameObjects/Items/RagDoll.js +++ b/app/Game/Core/GameObjects/Items/RagDoll.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Item", "Lib/Vendor/Box2D", "Game/Config/Settings", "Lib/Utilities/NotificationCenter", diff --git a/app/Game/Core/GameObjects/Items/RagDoll2.js b/app/Game/Core/GameObjects/Items/RagDoll2.js index 75fd89e..9a6f170 100644 --- a/app/Game/Core/GameObjects/Items/RagDoll2.js +++ b/app/Game/Core/GameObjects/Items/RagDoll2.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Item", "Lib/Vendor/Box2D", "Game/Config/Settings" ], diff --git a/app/Game/Core/GameObjects/Items/RubeDoll.js b/app/Game/Core/GameObjects/Items/RubeDoll.js index 77b511d..f0856bd 100644 --- a/app/Game/Core/GameObjects/Items/RubeDoll.js +++ b/app/Game/Core/GameObjects/Items/RubeDoll.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Item", "Lib/Vendor/RubeLoader", "Lib/Vendor/Box2D", "Game/Config/Settings", diff --git a/app/Game/Core/GameObjects/Items/Skateboard.js b/app/Game/Core/GameObjects/Items/Skateboard.js index 1e12df6..e04e946 100755 --- a/app/Game/Core/GameObjects/Items/Skateboard.js +++ b/app/Game/Core/GameObjects/Items/Skateboard.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Item", "Lib/Vendor/Box2D", "Game/Config/Settings", "Lib/Utilities/Assert" @@ -89,7 +89,7 @@ function (Parent, Box2D, Settings, Assert) { /* define([ - "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Item", "Lib/Vendor/Box2D", "Game/Config/Settings", "Lib/Utilities/Assert" diff --git a/app/Game/Core/GameObjects/SpectatorDoll.js b/app/Game/Core/GameObjects/SpectatorDoll.js index 912314a..709dcf8 100644 --- a/app/Game/Core/GameObjects/SpectatorDoll.js +++ b/app/Game/Core/GameObjects/SpectatorDoll.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/GameObject", + "Game/" + App.context + "/GameObjects/GameObject", "Lib/Vendor/Box2D" ], diff --git a/app/Game/Core/GameObjects/Tile.js b/app/Game/Core/GameObjects/Tile.js index dee3a1a..809c599 100755 --- a/app/Game/Core/GameObjects/Tile.js +++ b/app/Game/Core/GameObjects/Tile.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/GameObject", + "Game/" + App.context + "/GameObjects/GameObject", "Lib/Vendor/Box2D", "Game/Config/Settings", "Lib/Utilities/Exception", diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index 83cabde..9583e70 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -3,12 +3,12 @@ define([ "Lib/Vendor/Box2D", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Abstract", - "Game/" + GLOBALS.context + "/Collision/Detector", - "Game/" + GLOBALS.context + "/GameObjects/Tile", - "Game/" + GLOBALS.context + "/GameObjects/Item", - "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", - "Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll", - "Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll" + "Game/" + App.context + "/Collision/Detector", + "Game/" + App.context + "/GameObjects/Tile", + "Game/" + App.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Items/Skateboard", + "Game/" + App.context + "/GameObjects/Items/RagDoll", + "Game/" + App.context + "/GameObjects/Items/RubeDoll" ], function (Settings, Box2D, nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, RubeDoll) { diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index 16834b0..0e070ed 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -1,5 +1,5 @@ define([ - "Game/" + GLOBALS.context + "/Loader/Level", + "Game/" + App.context + "/Loader/Level", "Game/Config/Settings", "Game/Config/ItemSettings", "Lib/Vendor/Box2D", @@ -8,10 +8,10 @@ define([ "Lib/Utilities/NotificationCenter", "Lib/Utilities/Assert", "Game/Client/View/Abstract/Layer", - "Game/" + GLOBALS.context + "/Collision/Detector", - "Game/" + GLOBALS.context + "/GameObjects/Tile", - "Game/" + GLOBALS.context + "/GameObjects/Item", - "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", + "Game/" + App.context + "/Collision/Detector", + "Game/" + App.context + "/GameObjects/Tile", + "Game/" + App.context + "/GameObjects/Item", + "Game/" + App.context + "/GameObjects/Items/Skateboard", ], function (Parent, Settings, ItemSettings, Box2D, optionsHelper, Exception, nc, Assert, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) { diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index 4ec27b2..6a35e31 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -1,7 +1,7 @@ define([ "Game/Config/Settings", "Lib/Vendor/Box2D", - "Game/" + GLOBALS.context + "/Collision/Detector", + "Game/" + App.context + "/Collision/Detector", "Lib/Utilities/NotificationCenter" ], diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index 996facb..6143f8f 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -1,12 +1,12 @@ define([ - "Game/" + GLOBALS.context + "/GameObjects/Doll", - "Game/" + GLOBALS.context + "/Control/PlayerController", + "Game/" + App.context + "/GameObjects/Doll", + "Game/" + App.context + "/Control/PlayerController", "Game/Config/Settings", "Lib/Utilities/NotificationCenter", "Lib/Utilities/Exception", "Lib/Utilities/ColorConverter", - "Game/" + GLOBALS.context + "/GameObjects/SpectatorDoll", - "Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll" + "Game/" + App.context + "/GameObjects/SpectatorDoll", + "Game/" + App.context + "/GameObjects/Items/RubeDoll" ], function (Doll, PlayerController, Settings, nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) { diff --git a/channel.js b/channel.js index a94689f..e7a50ac 100755 --- a/channel.js +++ b/channel.js @@ -1,4 +1,7 @@ -GLOBALS = { context: "Channel" }; +// "use strict"; intentionally omitted as App scope workaround + +Error.stackTraceLimit = Infinity; + var requirejs = require('requirejs'); requirejs.config({ @@ -11,14 +14,17 @@ requirejs.config({ }, }); -var inspector = {}; + +App = {}; +App.inspector = {}; +App.context = "Channel"; requirejs([ "Game/Channel/PipeToServer" -], +], function (PipeToServer) { var PipeToServer = new PipeToServer(process); - inspector.PipeToServer = PipeToServer; + App.inspector.PipeToServer = PipeToServer; }); \ No newline at end of file diff --git a/client.js b/client.js index 6ccbb94..d15ce94 100755 --- a/client.js +++ b/client.js @@ -1,6 +1,6 @@ "use strict"; -var GLOBALS = { context: "Client" }; +Error.stackTraceLimit = Infinity; requirejs.config({ baseUrl: 'app', @@ -15,8 +15,9 @@ requirejs.config({ }, }); -if(!Chuck) var Chuck = {}; -Chuck.inspector = {}; +var App = App || {}; +App.inspector = {}; +App.context = "Client"; requirejs([ "Game/Client/Networker", @@ -42,10 +43,10 @@ function (Networker, SocketIO, Settings, Exception, nc, Menu) { }; var socket = SocketIO.connect("/", options); var networker = new Networker(socket, channelName, nickname); - Chuck.inspector.networker = networker; - Chuck.inspector.settings = Settings; - Chuck.inspector.nc = nc; - Chuck.inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); } + App.inspector.networker = networker; + App.inspector.settings = Settings; + App.inspector.nc = nc; + App.inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); } } menu.init(); }); \ No newline at end of file diff --git a/config/build-profile.js b/config/build-profile.js index e650ccc..336dbea 100644 --- a/config/build-profile.js +++ b/config/build-profile.js @@ -10,7 +10,7 @@ name: "../client", out: "../build/client.min.js", onBuildRead: function (moduleName, path, contents) { - var contents = contents.replace(/\" \+ GLOBALS.context \+ \"/g, "Client"); + var contents = contents.replace(/\" \+ App.context \+ \"/g, "Client"); return contents; } }) diff --git a/server.js b/server.js index bb9586f..2220bb9 100755 --- a/server.js +++ b/server.js @@ -1,10 +1,13 @@ "use strict" -var GLOBALS = { context: "Channel" }; +Error.stackTraceLimit = Infinity; + var requirejs = require('requirejs'); var fs = require('fs'); -var inspector; +var App = App || {}; +App.inspector = {}; +App.context = "Channel"; requirejs.config({ nodeRequire: require, @@ -41,11 +44,11 @@ function (HttpServer, Socket, Coordinator, Settings) { var httpServer = new HttpServer(options, coordinator); var socket = new Socket(httpServer.getServer(), options, coordinator); - inspector = { + App.inspector = { coordinator: coordinator, httpServer: httpServer, socket: socket } }); -exports = module.exports = inspector; \ No newline at end of file +exports = module.exports = App; \ No newline at end of file