Implement text to be split in enough screens it takes to display it all
This commit is contained in:
parent
524735329f
commit
6a154e094d
2 changed files with 41 additions and 6 deletions
|
@ -5,7 +5,7 @@ window.addEventListener('load', function() {
|
|||
screen = Screen(dom);
|
||||
session = Session();
|
||||
buttons = Buttons(session);
|
||||
ui = UI(buttons, screen);
|
||||
ui = UI(async, buttons, screen);
|
||||
automaton = Automaton(async, dom, messaging, screen, session, ui);
|
||||
|
||||
messaging.start();
|
||||
|
|
45
src/ui.js
45
src/ui.js
|
@ -1,4 +1,5 @@
|
|||
function UI(buttons, screen) {
|
||||
function UI(async, buttons, screen) {
|
||||
var lineWidth = 36;
|
||||
|
||||
return {
|
||||
animation: animation,
|
||||
|
@ -30,13 +31,16 @@ function UI(buttons, screen) {
|
|||
function cinematic(frames, controls) {
|
||||
var remote = animation(frames);
|
||||
var mapping = {};
|
||||
for(var key in controls) {
|
||||
mapping[key] = function() {
|
||||
var escaper = function(f) {
|
||||
return function() {
|
||||
buttons.pop();
|
||||
remote.pause();
|
||||
controls[key]();
|
||||
f();
|
||||
};
|
||||
}
|
||||
for(var key in controls) {
|
||||
mapping[key] = escaper(controls[key]);
|
||||
}
|
||||
return function(f) {
|
||||
buttons.push(mapping);
|
||||
remote.run();
|
||||
|
@ -92,6 +96,37 @@ function UI(buttons, screen) {
|
|||
}
|
||||
|
||||
function text(message) {
|
||||
return textScreen(message);
|
||||
var words = message.split(' ');
|
||||
var i = 0;
|
||||
var line = '';
|
||||
var screen = null;
|
||||
var screens = [];
|
||||
var width = 0;
|
||||
while (i < words.length) {
|
||||
if(width == 0) {
|
||||
line = words[i];
|
||||
width += line.length;
|
||||
i++;
|
||||
} else {
|
||||
if(width + words[i].length + 1 <= lineWidth) {
|
||||
line += ' ' + words[i];
|
||||
width += 1 + words[i].length;
|
||||
i++;
|
||||
} else {
|
||||
if(screen === null) {
|
||||
screen = line;
|
||||
} else {
|
||||
screens.push(screen + ' ' + line);
|
||||
screen = null;
|
||||
}
|
||||
line = '';
|
||||
width = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
screens.push(screen === null ? line : screen + ' ' + line);
|
||||
return async.sequence.apply(null,
|
||||
screens.map(function(s) { return textScreen(s); })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue