From 85ad98e7f5043a92de813f9c2f2830ba599a00e3 Mon Sep 17 00:00:00 2001 From: KevinRamharak Date: Wed, 3 Jan 2018 13:45:13 +0100 Subject: [PATCH] Changed to load local code only once on startup. If it fails it falls back to current behaviour --- mar/phaser/mar.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mar/phaser/mar.js b/mar/phaser/mar.js index 2eeb37c..974e23a 100644 --- a/mar/phaser/mar.js +++ b/mar/phaser/mar.js @@ -792,15 +792,7 @@ function manhanttanDistance(x1, y1, x2, y2) { function codeListener(message) { if (message.t === "code") { - var code = message.code; - if(typeof window.localStorage !== 'undefined') { // localStorage is supported - var value = window.localStorage.getItem("editorCodeContents"); - // if item does not exist null is returned - if(value !== null) { - code = value; - } - } - ace.edit("editor").setValue(code); + ace.edit("editor").setValue(message.code); } } @@ -808,6 +800,7 @@ function codeListener(message) { * Listens for authentications responses from the server */ function authListener(message) { + if (message.t === "auth") { if (message.m === "ok") { @@ -1039,7 +1032,15 @@ var GameClient = function (callback) { }; - self.reloadCode(); + // check if we can load code locally first + try { + var value = window.localStorage.getItem("editorCodeContents"); + if(value === null) throw new TypeError("no code stored locally under key: 'editorCodeContents'") + ace.edit("editor").setValue(value); + + } catch(e) { + self.reloadCode(); + } if (callback !== undefined) { @@ -1156,11 +1157,11 @@ BasicGame.Boot.prototype = { game.camera.x = 280; game.camera.y = 90; game.stage.disableVisibilityChange = true; - + this.scale.scaleMode = Phaser.ScaleManager.RESIZE; this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; - + }, create: function () { @@ -1183,7 +1184,7 @@ BasicGame.Boot.prototype = { }, update: function () { game.scale.setShowAll(); - game.scale.refresh(); + game.scale.refresh(); // Update the cursor position. // It's important to understand that screen-to-isometric projection means you have to specify a z position manually, as this cannot be easily // determined from the 2D pointer position without extra trickery. By default, the z position is 0 if not set.