diff --git a/app/Game/Client/Loader/Level.js b/app/Game/Client/Loader/Level.js index 72543b5..9f73b06 100755 --- a/app/Game/Client/Loader/Level.js +++ b/app/Game/Client/Loader/Level.js @@ -13,17 +13,23 @@ function (Parent, Settings, Nc, PIXI) { Level.prototype = Object.create(Parent.prototype); + Level.prototype.setup = function(levelData) { + this.levelData = levelData; + this.addBackground(); + Parent.prototype.setup.call(this, levelData); + }; + Level.prototype.loadLevelDataFromPath = function (path, callback) { var self = this; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { - if(xhr.readyState == 4) { - if(xhr.status == 200) { - self.loadAssets(JSON.parse(xhr.responseText), callback); - } else { - console.error("Ajax error: " + xhr.status + " " + xhr.statusText) - } + if(xhr.readyState == 4) { + if(xhr.status == 200) { + self.loadAssets(JSON.parse(xhr.responseText), callback); + } else { + console.error("Ajax error: " + xhr.status + " " + xhr.statusText) } + } } xhr.open("GET", path, true); xhr.send(null); diff --git a/app/Game/Client/View/Views/AbstractView.js b/app/Game/Client/View/Views/AbstractView.js index a59176f..31bb692 100755 --- a/app/Game/Client/View/Views/AbstractView.js +++ b/app/Game/Client/View/Views/AbstractView.js @@ -1,11 +1,12 @@ define([ + "Lib/Utilities/Abstract", "Game/Client/View/DomController", "Game/Config/Settings", "Lib/Utilities/Exception", "Lib/Utilities/NotificationCenter" ], -function (DomController, Settings, Exception, Nc) { +function (Abstract, DomController, Settings, Exception, Nc) { function AbstractView () { this.me = null; @@ -37,10 +38,29 @@ function (DomController, Settings, Exception, Nc) { Nc.on(Nc.ns.client.view.preloadBar.update, this.onUpdateLoader, this), ]; - - } + Abstract.prototype.addMethod.call(AbstractView, 'render'); + Abstract.prototype.addMethod.call(AbstractView, 'createMesh', ['texturePath', 'callback', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'createAnimatedMesh', ['texturePaths', 'callback', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'addMesh', ['mesh']); + Abstract.prototype.addMethod.call(AbstractView, 'removeMesh', ['mesh']); + Abstract.prototype.addMethod.call(AbstractView, 'updateMesh', ['mesh', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'addFilter', ['mesh', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'removeFilter', ['mesh', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'setCameraPosition', ['x', 'y']); + Abstract.prototype.addMethod.call(AbstractView, 'setCameraZoom', ['z']); + Abstract.prototype.addMethod.call(AbstractView, 'onZoomIn'); + Abstract.prototype.addMethod.call(AbstractView, 'onZoomIn'); + Abstract.prototype.addMethod.call(AbstractView, 'onZoomReset'); + Abstract.prototype.addMethod.call(AbstractView, 'toggleInfo', ['show', 'string']); + Abstract.prototype.addMethod.call(AbstractView, 'onCreateAndAddPlayerInfo', ['options']); + Abstract.prototype.addMethod.call(AbstractView, 'onCreateAndAddPlayerArrow', ['options']); + Abstract.prototype.addMethod.call(AbstractView, 'onUpdatePlayerArrow', ['options']); + Abstract.prototype.addMethod.call(AbstractView, 'onUpdatePlayerInfo', ['mesh', 'options']); + Abstract.prototype.addMethod.call(AbstractView, 'onRemovePlayerInfo', ['mesh']); + Abstract.prototype.addMethod.call(AbstractView, 'onUpdateLoader', ['progress']); + AbstractView.prototype.isWebGlEnabled = function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); @@ -50,67 +70,14 @@ function (DomController, Settings, Exception, Nc) { } AbstractView.prototype.initCanvas = function (canvas) { - this.canvas = canvas; DomController.initCanvas(canvas); } - AbstractView.prototype.loadPlayerMesh = function(player) { - throw new Exception('Abstract Function loadPlayerMesh not overwritten'); - }; - - AbstractView.prototype.loadMeshes = function(objects) { - throw new Exception('Abstract Function loadMeshes not overwritten'); - }; - - AbstractView.prototype.render = function () { - throw new Exception('Abstract Function render not overwritten'); - } - - AbstractView.prototype.createMesh = function (texturePath, callback, options) { - throw new Exception('Abstract Function createMesh not overwritten'); - } - - AbstractView.prototype.createAnimatedMesh = function (texturePaths, callback, options) { - throw new Exception('Abstract Function createAnimatedMesh not overwritten'); - } - - AbstractView.prototype.addMesh = function(mesh) { - throw new Exception('Abstract Function addMesh not overwritten'); - }; - - AbstractView.prototype.removeMesh = function(mesh) { - throw new Exception('Abstract Function removeMesh not overwritten'); - }; - - AbstractView.prototype.updateMesh = function(mesh, options) { - throw new Exception('Abstract Function updateMesh not overwritten'); - }; - - AbstractView.prototype.addFilter = function(mesh, options) { - throw new Exception('Abstract Function addFilter not overwritten'); - }; - - AbstractView.prototype.removeFilter = function(mesh, options) { - throw new Exception('Abstract Function removeFilter not overwritten'); - }; - AbstractView.prototype.setMe = function(player) { this.me = player; }; - AbstractView.prototype.addPlayer = function(player) { - throw new Exception('Abstract Function addPlayer not overwritten'); - }; - - AbstractView.prototype.removPlayer = function(player) { - throw new Exception('Abstract Function removPlayer not overwritten'); - }; - - AbstractView.prototype.setCameraPosition = function (x, y) { - throw new Exception('Abstract Function setCameraPosition not overwritten'); - } - AbstractView.prototype.calculateCameraPosition = function() { var reference = this.me.getPosition(); var pos = {}; @@ -127,22 +94,6 @@ function (DomController, Settings, Exception, Nc) { return pos; }; - AbstractView.prototype.setCameraZoom = function (z) { - throw new Exception('Abstract Function setCameraZoom not overwritten'); - }; - - AbstractView.prototype.onZoomIn = function () { - throw new Exception('Abstract Function onZoomIn not overwritten'); - }; - - AbstractView.prototype.onZoomOut = function () { - throw new Exception('Abstract Function onZoomOut not overwritten'); - }; - - AbstractView.prototype.onZoomReset = function () { - throw new Exception('Abstract Function onZoomReset not overwritten'); - }; - AbstractView.prototype.onFullscreenChange = function(isFullScreen) { if (!isFullScreen) { @@ -164,34 +115,6 @@ function (DomController, Settings, Exception, Nc) { this.debugMode = debugMode; }; - AbstractView.prototype.toggleInfo = function(show, string) { - throw new Exception('Abstract Function showInfo not overwritten'); - }; - - AbstractView.prototype.onCreateAndAddPlayerInfo = function(options) { - throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten'); - }; - - AbstractView.prototype.onCreateAndAddPlayerArrow = function(options) { - throw new Exception('Abstract Function onCreateAndAddPlayerArrow not overwritten'); - }; - - AbstractView.prototype.onUpdatePlayerArrow = function(options) { - throw new Exception('Abstract Function onUpdatePlayerArrow not overwritten'); - }; - - AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) { - throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten'); - }; - - AbstractView.prototype.onRemovePlayerInfo = function(playerInfo) { - throw new Exception('Abstract Function onRemovePlayerInfo not overwritten'); - }; - - AbstractView.prototype.onUpdateLoader = function(progress) { - throw new Exception('Abstract Function onUpdateLoader not overwritten'); - }; - AbstractView.prototype.destroy = function() { for (var i = 0; i < this.ncTokens.length; i++) { Nc.off(this.ncTokens[i]); diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 8ed08f1..8e2e0b3 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -65,7 +65,7 @@ define(function() { USE_WEBGL: true, // NETWORKING - NETWORK_UPDATE_INTERVAL: 70, + NETWORK_UPDATE_INTERVAL: 70, // in milliseconds NETWORK_LOG_INCOMING: false, NETWORK_LOG_OUTGOING: false, NETWORK_LOG_FILTER: ['ping', 'pong', 'worldUpdate', 'lookAt'], diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index 4600191..fe042c2 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -2,6 +2,7 @@ define([ "Game/Config/Settings", "Lib/Vendor/Box2D", "Lib/Utilities/NotificationCenter", + "Lib/Utilities/Abstract", "Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + GLOBALS.context + "/GameObjects/Item", @@ -9,7 +10,7 @@ define([ "Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll", "Game/" + GLOBALS.context + "/GameObjects/Items/Rube" -], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) { +], function (Settings, Box2D, Nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) { function Level (uid, engine) { this.uid = uid; @@ -19,19 +20,26 @@ define([ this.load(this.uid); } + Abstract.prototype.addMethod.call(Level, "createTiles"); + Abstract.prototype.addMethod.call(Level, "createItems"); + Abstract.prototype.addMethod.call(Level, "addBackground"); + Level.prototype.load = function (uid) { var self = this; var path = Settings.MAPS_PATH + uid + ".json" - this.loadLevelDataFromPath(path, function(levelData) { - self.levelData = levelData; - self.addBackground(); - self.createTiles(); - self.createItems(); - self.isLoaded = true; - Nc.trigger(Nc.ns.core.game.events.level.loaded); + this.loadLevelDataFromPath(path, function (levelData) { + self.setup(levelData); }); } + Level.prototype.setup = function(levelData) { + this.levelData = levelData; + this.createTiles(); + this.createItems(); + this.isLoaded = true; + Nc.trigger(Nc.ns.core.game.events.level.loaded); + }; + Level.prototype.createItem = function(uid, options) { switch(options.type) { //case 'skateboard': @@ -54,55 +62,8 @@ define([ }; Level.prototype.destroy = function () { - /* - for (var key in this.gameObjects) { - for (var i = 0; i < this.gameObjects[key].length; i++) { - this.gameObjects[key][i].destroy(); - } - } - */ this.isLoaded = false; } -/* Extended by TiledLevel - Level.prototype.createTiles = function () { - - if (!this.levelData || !this.levelData.tiles || this.levelData.tiles.length < 1) { - throw "Level: Can't create physic tiles, no tiles found"; - } - - var tiles = this.levelData.tiles; - - for (var i = 0; i < tiles.length; i++) { - var options = tiles[i]; - //options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil"; - options.m = "Soil"; - //this.gameObjects.fixed.push( - new Tile(this.engine, "tile-" + i, options); - //); - } - } -*/ - -/* Extended by TiledLevel - Level.prototype.createItems = function() { - if (!this.levelData || !this.levelData.items) { - return; - } - var items = this.levelData.items; - - for (var i = 0; i < items.length; i++) { - var options = items[i]; - var uid = "item-" + i; - var item = this.createItem(uid, options); - //this.gameObjects.animated.push(item); - }; - }; - - // Extended by TiledLevel - Level.prototype.addBackground = function() { - } -*/ - return Level; }) \ No newline at end of file diff --git a/app/Lib/Utilities/Abstract.js b/app/Lib/Utilities/Abstract.js new file mode 100644 index 0000000..36c5780 --- /dev/null +++ b/app/Lib/Utilities/Abstract.js @@ -0,0 +1,18 @@ +define([ + "Lib/Utilities/Exception" +], + +function (Exception) { + + function Abstract() { + } + + Abstract.prototype.addMethod = function(methodName, params) { + this.prototype[methodName] = function() { + throw new Exception("Abstract method", this, methodName + "(" + params.join(', ') + ") not overwritten."); + } + } + + return Abstract; + +}); \ No newline at end of file diff --git a/static/html/index.html b/static/html/index.html index f0c37e3..43fc6e0 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -1,7 +1,8 @@
-