aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/core/library/v.js
blob: 21225ee003a570963cb49a1a3baabfbf3890f7f3 (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
46
47
48
49
50
'use strict'

const Operator = require('../operator')
// TODO
function OperatorV (orca, x, y, passive) {
  Operator.call(this, orca, x, y, 'v', passive)

  this.name = 'variable'
  this.info = 'Reads and write globally available variables.'

  this.ports.haste.write = { x: -1, y: 0 }
  this.ports.input.value = { x: 1, y: 0 }
  this.ports.output = { x: 0, y: 1 }

  this.haste = function () {
    const key = this.listen(this.ports.haste.write, true)

    if (key > 9) {
      this.ports.output = null
    }
  }

  this.run = function () {
    if (this.listen(this.ports.haste.write, true) > 9) { return }

    const key = this.listen(this.ports.input.value)
    const res = this.read(key)

    if (res !== '.') {
      this.output(`${res}`)
    }
  }

  this.read = function (key) {
    for (const id in orca.runtime) {
      const operator = orca.runtime[id]
      if (orca.lockAt(operator.x, operator.y)) { continue }
      const glyph = operator.glyph.toLowerCase()
      if (glyph !== 'v') { continue }
      const write = operator.listen(operator.ports.haste.write)
      if (write !== key) { continue }
      const value = operator.listen(operator.ports.input.value)
      return value
    }

    return null
  }
}

module.exports = OperatorV