From e3012761ee05d911992aa5f6f40d78596450f30a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 15 Dec 2018 13:40:25 +1200 Subject: Fixed issue with history --- desktop/sources/scripts/history.js | 19 ++++++++++++++----- desktop/sources/scripts/terminal.js | 1 + examples/_keys.orca | 13 ------------- 3 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 examples/_keys.orca diff --git a/desktop/sources/scripts/history.js b/desktop/sources/scripts/history.js index 9d3912b..0c16a8a 100644 --- a/desktop/sources/scripts/history.js +++ b/desktop/sources/scripts/history.js @@ -14,15 +14,24 @@ function History (terminal, orca = terminal.room) { } this.undo = function () { + if (terminal.room.id !== 'lobby') { console.warn('History', 'Outside Lobby'); return } if (this.index === 0) { console.warn('History', 'Reached beginning'); return } + this.index = clamp(this.index - 1, 0, this.frames.lengt - 1) - // terminal.load(this.frames[this.index], terminal.rooms.lobby.f) + this.apply(this.frames[this.index]) } this.redo = function () { + if (terminal.room.id !== 'lobby') { console.warn('History', 'Outside Lobby'); return } if (this.index > this.frames.length - 1) { console.warn('History', 'Reached end'); return } + this.index = clamp(this.index + 1, 0, this.frames.lengt - 1) - // terminal.load(this.frames[this.index], terminal.rooms.lobby.f) + this.apply(this.frames[this.index]) + } + + this.apply = function (f) { + if (!f || f.length !== terminal.room.s.length) { return } + terminal.room.s = this.frames[this.index] } this.reset = function () { @@ -31,12 +40,12 @@ function History (terminal, orca = terminal.room) { } this.append = function () { - // this.frames.push(`${orca}`) + this.frames.push(terminal.room.s) } this.fork = function () { - // this.frames = this.frames.slice(0, this.index + 1) - // this.frames.push(`${orca}`) + this.frames = this.frames.slice(0, this.index + 1) + this.frames.push(terminal.room.s) } function clamp (v, min, max) { return v < min ? min : v > max ? max : v } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index c6814b2..68f813f 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -61,6 +61,7 @@ function Terminal (tile = { w: 20, h: 30 }) { } this.load = function (rooms, frame = 0) { + this.history.reset() this.rooms = rooms this.enter() } diff --git a/examples/_keys.orca b/examples/_keys.orca deleted file mode 100644 index f184b23..0000000 --- a/examples/_keys.orca +++ /dev/null @@ -1,13 +0,0 @@ -......................................... -.#.KEYS.#................................ -......................................... -.#.TOGGLE.KEYS.MODE.WITH.SLASH.#......... -.#.PRESS.a.b.OR.c.#...................... -......................................... -......................................... -........!a......!b......!c............... -......................................... -......................................... -......................................... -......................................... -......................................... \ No newline at end of file -- cgit v1.2.3