From 2fa63256eb9edf564ed735859ce578ca94b7d853 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 11 Dec 2015 11:50:37 +0200 Subject: [PATCH] Add prevScene, nextScene navigation --- public_html/js/Parser.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/public_html/js/Parser.js b/public_html/js/Parser.js index 20dcbbb..98de96b 100644 --- a/public_html/js/Parser.js +++ b/public_html/js/Parser.js @@ -51,6 +51,26 @@ Parser.prototype.next = function () { } 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) { var pos = from; while (true) {