aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources/scripts/history.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/sources/scripts/history.js')
-rw-r--r--desktop/sources/scripts/history.js19
1 files changed, 14 insertions, 5 deletions
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 }