Files
MI2Mario/src/Storage.js
T
2020-06-04 17:42:23 +02:00

40 lines
1.3 KiB
JavaScript

/*
* 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";