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
|
'use strict'
const Operator = require('../operator')
function OperatorO (orca, x, y, passive) {
Operator.call(this, orca, x, y, 'o', passive)
this.name = 'offset'
this.info = 'Reads a distant operator with offset.'
this.ports.haste.x = { x: -2, y: 0 }
this.ports.haste.y = { x: -1, y: 0 }
this.ports.input.val = { x: 1, y: 0 }
this.ports.output = { x: 0, y: 1 }
this.haste = function () {
const x = clamp(this.listen(this.ports.haste.x, true) + 1, 1, 24)
const y = clamp(this.listen(this.ports.haste.y, true), 0, 24)
this.ports.input.val = { x: x, y: y }
}
this.run = function () {
const res = this.listen(this.ports.input.val)
this.output(`${res}`)
}
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
}
module.exports = OperatorO
|