aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources/scripts/history.js
blob: 9d3912be0794f3f94bd96ffa2944c9a95a2f025c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'

function History (terminal, orca = terminal.room) {
  this.index = 0
  this.frames = []

  this.record = function () {
    if (this.index === this.frames.length) {
      this.append()
    } else {
      this.fork()
    }
    this.index = this.frames.length
  }

  this.undo = function () {
    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.redo = function () {
    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.reset = function () {
    this.index = 0
    this.frames = []
  }

  this.append = function () {
    // this.frames.push(`${orca}`)
  }

  this.fork = function () {
    // this.frames = this.frames.slice(0, this.index + 1)
    // this.frames.push(`${orca}`)
  }

  function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
}

module.exports = History