Add prevScene, nextScene navigation

This commit is contained in:
Victor 2015-12-11 11:50:37 +02:00
parent 3237a17535
commit 2fa63256eb

View File

@ -51,6 +51,26 @@ Parser.prototype.next = function () {
} while (!terminal); } while (!terminal);
}; };
Parser.prototype.prevScene = function() {
// Для перехода к предыдущей сцене, следует два раза найти токен SCENE,
// т.к. при первом поиске мы найдём лишь текущую.
var currentScene = this.find(TokenType.SCENE, -1);
var pos = this.findFrom(currentScene, TokenType.SCENE, -1);
// Если не нашли - перематываем на начало.
if (pos == this.position) this.position = 0;
else this.position = pos;
this.next();
};
Parser.prototype.nextScene = function() {
this.position = this.find(TokenType.SCENE, 1);
this.next();
};
Parser.prototype.find = function(which, step) {
return this.findFrom(this.position, which, step);
};
Parser.prototype.findFrom = function(from, which, step) { Parser.prototype.findFrom = function(from, which, step) {
var pos = from; var pos = from;
while (true) { while (true) {