Handle text speeds and store it along with keyboard layout
This commit is contained in:
parent
54ff5b0875
commit
78aa3f6281
4 changed files with 22 additions and 17 deletions
|
@ -1,10 +1,9 @@
|
|||
function Buttons(session) {
|
||||
var mapping;
|
||||
var mappingsStack = [];
|
||||
var layout = session.getLayout();
|
||||
|
||||
document.addEventListener('keydown', function(event) {
|
||||
var button = layout[event.key];
|
||||
var button = session.getOptions().layout[event.key];
|
||||
if(button != undefined && mapping[button] != undefined) {
|
||||
mapping[button]();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ window.addEventListener('load', function() {
|
|||
screen = Screen(dom);
|
||||
session = Session();
|
||||
buttons = Buttons(session);
|
||||
ui = UI(async, buttons, screen);
|
||||
ui = UI(async, buttons, screen, session);
|
||||
automaton = Automaton(async, dom, messaging, screen, session, ui);
|
||||
|
||||
messaging.start();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
function Session() {
|
||||
var game = JSON.parse(localStorage.getItem('game'));
|
||||
var layout = loadLayout();
|
||||
var options = JSON.parse(localStorage.getItem('options')) || defaultOptions();
|
||||
|
||||
return {
|
||||
getLayout: getLayout,
|
||||
getOptions: getOptions,
|
||||
getGame: getGame,
|
||||
save : save
|
||||
};
|
||||
|
@ -20,10 +20,9 @@ function Session() {
|
|||
localStorage.setItem('game', JSON.stringify(game));
|
||||
}
|
||||
|
||||
function loadLayout() {
|
||||
var saved = JSON.parse(localStorage.getItem('layout'));
|
||||
if(saved == undefined) {
|
||||
saved = {
|
||||
function defaultOptions() {
|
||||
var o = {
|
||||
layout: {
|
||||
'a': 'A',
|
||||
'b': 'B',
|
||||
'ArrowLeft': 'Left',
|
||||
|
@ -32,13 +31,14 @@ function Session() {
|
|||
'ArrowDown': 'Down',
|
||||
'Enter': 'Start',
|
||||
' ': 'Select'
|
||||
};
|
||||
localStorage.setItem('layout', JSON.stringify(saved));
|
||||
}
|
||||
return saved;
|
||||
},
|
||||
textSpeed: 'medium'
|
||||
};
|
||||
localStorage.setItem('options', JSON.stringify(o));
|
||||
return o;
|
||||
}
|
||||
|
||||
function getLayout() {
|
||||
return layout;
|
||||
function getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
|
10
src/ui.js
10
src/ui.js
|
@ -1,5 +1,11 @@
|
|||
function UI(async, buttons, screen) {
|
||||
function UI(async, buttons, screen, session) {
|
||||
var lineWidth = 36;
|
||||
var textSpeeds = {
|
||||
slow: 100,
|
||||
medium: 50,
|
||||
fast: 20
|
||||
};
|
||||
var textDelay = textSpeeds[session.getOptions().textSpeed];
|
||||
|
||||
return {
|
||||
animation: animation,
|
||||
|
@ -74,7 +80,7 @@ function UI(async, buttons, screen) {
|
|||
var ready = false;
|
||||
var append = function(c) { return function() { screen.appendText(c); }; };
|
||||
for(var i = 0; i < characters.length; i++) {
|
||||
frames.push({action: append(characters[i]), delay: 50});
|
||||
frames.push({action: append(characters[i]), delay: textDelay});
|
||||
}
|
||||
frames.push({action: function() { ready = true; screen.markAsRead(); }, delay: null});
|
||||
var remote = animation(frames);
|
||||
|
|
Loading…
Reference in a new issue