mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-04-19 18:46:41 +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) {
|
function codeListener(message) {
|
||||||
if (message.t === "code") {
|
if (message.t === "code") {
|
||||||
var code = message.code;
|
ace.edit("editor").setValue(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,6 +800,7 @@ function codeListener(message) {
|
|||||||
* Listens for authentications responses from the server
|
* Listens for authentications responses from the server
|
||||||
*/
|
*/
|
||||||
function authListener(message) {
|
function authListener(message) {
|
||||||
|
|
||||||
if (message.t === "auth") {
|
if (message.t === "auth") {
|
||||||
|
|
||||||
if (message.m === "ok") {
|
if (message.m === "ok") {
|
||||||
@ -1039,7 +1032,15 @@ var GameClient = function (callback) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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();
|
self.reloadCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (callback !== undefined) {
|
if (callback !== undefined) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user