Merge 85ad98e7f5043a92de813f9c2f2830ba599a00e3 into 22c64110e98ba57eddde5287796977f1ed1684b2

This commit is contained in:
Kevin Ramharak 2018-01-04 10:53:48 +00:00 committed by GitHub
commit bac12bdbb4
2 changed files with 42 additions and 7 deletions

View File

@ -404,4 +404,34 @@ function editorClick() {
document.getElementById("gameBtns").setAttribute("style", "display: none");
}
/*
im using a closure because i don't like putting everything in global scope
feel free to disagree
*/
var lazySave = (function() {
if(typeof window.localStorage === 'undefined') {
return function() {}; // if browser does not support local storage make it a no op (no idea what browsers)
}
// store a reference to the timeout
var DELAY = 3000;
var timeout = null;
// Basicly on every change set a timeout that will wait DELAY milliseconds before storing the code.
// This will prevent unnececary saving on every change
return function(event) {
// if another timeout was waiting clear that one
if(timeout !== null) {
clearTimeout(timeout);
}
// and set a new one
timeout = setTimeout(function() {
window.localStorage.setItem('editorCodeContents', ace.edit("editor").getValue());
timeout = null; // clear the timeout cached variable after its function has run
}, DELAY);
};
})();
editor.on("change", parse);
// You can add multiple handlers on events
editor.on("change", lazySave);

View File

@ -791,11 +791,8 @@ function manhanttanDistance(x1, y1, x2, y2) {
}
function codeListener(message) {
if (message.t === "code") {
ace.edit("editor").setValue(message.code);
}
}
@ -1035,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) {
@ -1152,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 () {
@ -1179,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.