client/src/session.js

45 lines
767 B
JavaScript

function Session() {
var game = JSON.parse(localStorage.getItem('game'));
var options = JSON.parse(localStorage.getItem('options')) || defaultOptions();
return {
getOptions: getOptions,
getGame: getGame,
save : save
};
function getGame() {
return game;
}
function update(state) {
game = state;
}
function save() {
localStorage.setItem('game', JSON.stringify(game));
}
function defaultOptions() {
var o = {
layout: {
'a': 'A',
'b': 'B',
'ArrowLeft': 'Left',
'ArrowRight': 'Right',
'ArrowUp': 'Up',
'ArrowDown': 'Down',
'Enter': 'Start',
' ': 'Select'
},
textSpeed: 'medium'
};
localStorage.setItem('options', JSON.stringify(o));
return o;
}
function getOptions() {
return options;
}
}