aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/sources')
-rw-r--r--desktop/sources/scripts/history.js19
-rw-r--r--desktop/sources/scripts/terminal.js1
2 files changed, 15 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 }
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()
}