/js/core/RealtimeMutliplayerGame.js
JavaScript | 83 lines | 49 code | 7 blank | 27 comment | 14 complexity | 08eb621728bfc1259e14966dd9929877 MD5 | raw file
1/** 2 File: 3 RealtimeMultiplayerGame.js 4 Created By: 5 Mario Gonzalez 6 Project: 7 RealtimeMultiplayerNodeJS 8 Abstract: 9 This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method 10 11 Basic Usage: 12 This class is not instantiated 13 */ 14RealtimeMultiplayerGame = (typeof RealtimeMultiplayerGame === 'undefined') ? {} : RealtimeMultiplayerGame; 15/** 16 * Allows a package to create a namespace within RealtimeMultiplayerGame 17 * From Javascript Patterns book 18 * @param ns_string 19 */ 20RealtimeMultiplayerGame.namespace = function (ns_string) { 21 var parts = ns_string.split('.'), 22 parent = RealtimeMultiplayerGame, 23 i = 0; 24 25 // strip redundant leading global 26 if (parts[0] === "RealtimeMultiplayerGame") { 27 parts = parts.slice(1); 28 } 29 30 var len = parts.length, 31 aPackage = null; 32 for (i = 0; i < len; i += 1) { 33 var singlePart = parts[i]; 34 // create a property if it doesn't exist 35 if (typeof parent[singlePart] === "undefined") { 36 parent[singlePart] = {}; 37 } 38 parent = parent[singlePart]; 39 40 } 41 return parent; 42}; 43 44/** 45 * Allows a simple inheritance model 46 * based on http://www.kevs3d.co.uk/dev/canvask3d/scripts/mathlib.js 47 */ 48RealtimeMultiplayerGame.extend = function (subc, superc, overrides) { 49 /** 50 * @constructor 51 */ 52 var F = function () { 53 }; 54 var i; 55 56 if (overrides) { 57 F.prototype = superc.prototype; 58 subc.prototype = new F(); 59 subc.prototype.constructor = subc; 60 subc.superclass = superc.prototype; 61 if (superc.prototype.constructor == Object.prototype.constructor) { 62 superc.prototype.constructor = superc; 63 } 64 for (i in overrides) { 65 if (overrides.hasOwnProperty(i)) { 66 subc.prototype[i] = overrides[i]; 67 } 68 } 69 } else { 70 71 subc.prototype.constructor = subc; 72 subc.superclass = superc.prototype; 73 if (superc.prototype.constructor == Object.prototype.constructor) { 74 superc.prototype.constructor = superc; 75 } 76 for (i in superc.prototype) { 77 if (false == subc.prototype.hasOwnProperty(i)) { 78 subc.prototype[i] = superc.prototype[i]; 79 } 80 } 81 82 } 83}