PageRenderTime 81ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

/js/DemoBox2D/DemoBox2DApp.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 44 lines | 19 code | 3 blank | 22 comment | 3 complexity | ef327361794feeef6a33094c0f87d412 MD5 | raw file
 1/**
 2 File:
 3 DemoBox2DApp.js
 4 Created By:
 5 Mario Gonzalez
 6 Project:
 7 RealtimeMultiplayerNodeJS
 8 Abstract:
 9 This is the core module for the DemoBox2DApp contains the namespace
10 This demo shows how to create a game that uses a Box2D javascript implementation (https://github.com/HBehrens/box2d.js)
11 Basic Usage:
12 This class is not instantiated
13 Version:
14 1.0
15 */
16DemoBox2D = (typeof DemoBox2D === 'undefined') ? {} : DemoBox2D;
17/**
18 * Allows a package to create a namespace within RealtimeMultiplayerGame
19 * From Javascript Patterns book
20 * @param ns_string
21 */
22DemoBox2D.namespace = function (ns_string) {
23    var parts = ns_string.split('.'),
24        parent = DemoBox2D,
25        i = 0;
26
27    // strip redundant leading global
28    if (parts[0] === "DemoBox2D") {
29        parts = parts.slice(1);
30    }
31
32    var len = parts.length,
33        aPackage = null;
34    for (i = 0; i < len; i += 1) {
35        var singlePart = parts[i];
36        // create a property if it doesn't exist
37        if (typeof parent[singlePart] === "undefined") {
38            parent[singlePart] = {};
39        }
40        parent = parent[singlePart];
41
42    }
43    return parent;
44};