mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-04-18 18:26:42 +00:00
Changed to load local code only once on startup. If it fails it falls back to current behaviour
This commit is contained in:
parent
2a0c3992f4
commit
85ad98e7f5
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user