PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/js/core/RealtimeMutliplayerGame.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 83 lines | 49 code | 7 blank | 27 comment | 14 complexity | 08eb621728bfc1259e14966dd9929877 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. Basic Usage:
  11. This class is not instantiated
  12. */
  13. RealtimeMultiplayerGame = (typeof RealtimeMultiplayerGame === 'undefined') ? {} : RealtimeMultiplayerGame;
  14. /**
  15. * Allows a package to create a namespace within RealtimeMultiplayerGame
  16. * From Javascript Patterns book
  17. * @param ns_string
  18. */
  19. RealtimeMultiplayerGame.namespace = function (ns_string) {
  20. var parts = ns_string.split('.'),
  21. parent = RealtimeMultiplayerGame,
  22. i = 0;
  23. // strip redundant leading global
  24. if (parts[0] === "RealtimeMultiplayerGame") {
  25. parts = parts.slice(1);
  26. }
  27. var len = parts.length,
  28. aPackage = null;
  29. for (i = 0; i < len; i += 1) {
  30. var singlePart = parts[i];
  31. // create a property if it doesn't exist
  32. if (typeof parent[singlePart] === "undefined") {
  33. parent[singlePart] = {};
  34. }
  35. parent = parent[singlePart];
  36. }
  37. return parent;
  38. };
  39. /**
  40. * Allows a simple inheritance model
  41. * based on http://www.kevs3d.co.uk/dev/canvask3d/scripts/mathlib.js
  42. */
  43. RealtimeMultiplayerGame.extend = function (subc, superc, overrides) {
  44. /**
  45. * @constructor
  46. */
  47. var F = function () {
  48. };
  49. var i;
  50. if (overrides) {
  51. F.prototype = superc.prototype;
  52. subc.prototype = new F();
  53. subc.prototype.constructor = subc;
  54. subc.superclass = superc.prototype;
  55. if (superc.prototype.constructor == Object.prototype.constructor) {
  56. superc.prototype.constructor = superc;
  57. }
  58. for (i in overrides) {
  59. if (overrides.hasOwnProperty(i)) {
  60. subc.prototype[i] = overrides[i];
  61. }
  62. }
  63. } else {
  64. subc.prototype.constructor = subc;
  65. subc.superclass = superc.prototype;
  66. if (superc.prototype.constructor == Object.prototype.constructor) {
  67. superc.prototype.constructor = superc;
  68. }
  69. for (i in superc.prototype) {
  70. if (false == subc.prototype.hasOwnProperty(i)) {
  71. subc.prototype[i] = superc.prototype[i];
  72. }
  73. }
  74. }
  75. }