added Storage and ControlsSettings

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-06-04 17:42:23 +02:00
parent 7c4d08cf8f
commit 07e08ba4f6
7 changed files with 262 additions and 45 deletions
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
* All rights reserved.
*/
export default class Storage {
static get() {
if (!window.localStorage.getItem(Storage.KEY))
this.reset();
return JSON.parse(atob(window.localStorage.getItem(Storage.KEY)));
}
static set(value) {
window.localStorage.setItem(Storage.KEY, btoa(JSON.stringify(value)));
}
static clear() {
window.localStorage.removeItem(Storage.KEY);
}
static reset() {
this.set({
controls: {
jump: {name: "Jump", bind: Phaser.Input.Keyboard.KeyCodes.W},
w_left: {name: "Walk left", bind: Phaser.Input.Keyboard.KeyCodes.A},
w_right: {name: "Walk right", bind: Phaser.Input.Keyboard.KeyCodes.D},
use_left: {name: "Use left item", bind: Phaser.Input.Keyboard.KeyCodes.Q},
use_right: {name: "Use right item", bind: Phaser.Input.Keyboard.KeyCodes.E},
attack: {name: "Attack", bind: Phaser.Input.Keyboard.KeyCodes.SPACE},
block: {name: "Block", bind: Phaser.Input.Keyboard.KeyCodes.F},
pickup: {name: "Pickup", bind: Phaser.Input.Keyboard.KeyCodes.S}
}
})
}
}
Storage.KEY = "save";