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);
|
screen = Screen(dom);
|
||||||
session = Session();
|
session = Session();
|
||||||
buttons = Buttons(session);
|
buttons = Buttons(session);
|
||||||
ui = UI(buttons, screen);
|
ui = UI(async, buttons, screen);
|
||||||
automaton = Automaton(async, dom, messaging, screen, session, ui);
|
automaton = Automaton(async, dom, messaging, screen, session, ui);
|
||||||
|
|
||||||
messaging.start();
|
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 {
|
return {
|
||||||
animation: animation,
|
animation: animation,
|
||||||
|
@ -30,13 +31,16 @@ function UI(buttons, screen) {
|
||||||
function cinematic(frames, controls) {
|
function cinematic(frames, controls) {
|
||||||
var remote = animation(frames);
|
var remote = animation(frames);
|
||||||
var mapping = {};
|
var mapping = {};
|
||||||
for(var key in controls) {
|
var escaper = function(f) {
|
||||||
mapping[key] = function() {
|
return function() {
|
||||||
buttons.pop();
|
buttons.pop();
|
||||||
remote.pause();
|
remote.pause();
|
||||||
controls[key]();
|
f();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
for(var key in controls) {
|
||||||
|
mapping[key] = escaper(controls[key]);
|
||||||
|
}
|
||||||
return function(f) {
|
return function(f) {
|
||||||
buttons.push(mapping);
|
buttons.push(mapping);
|
||||||
remote.run();
|
remote.run();
|
||||||
|
@ -92,6 +96,37 @@ function UI(buttons, screen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function text(message) {
|
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