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
|
'use strict'
const Operator = require('../operator')
function OperatorP (orca, x, y, passive) {
Operator.call(this, orca, x, y, 'p', true)
this.name = 'push'
this.info = 'Writes an eastward operator with offset.'
this.ports.haste.len = { x: -1, y: 0 }
this.ports.haste.key = { x: -2, y: 0 }
this.ports.input.val = { x: 1, y: 0 }
this.ports.output = { x: 0, y: 1 }
this.haste = function () {
this.len = clamp(this.listen(this.ports.haste.len, true), 1, 16)
this.key = this.listen(this.ports.haste.key, true)
for (let x = 0; x < this.len; x++) {
orca.lock(this.x + x, this.y + 1)
}
this.ports.output = { x: (this.key % this.len), y: 1, unlock: true }
}
this.run = function () {
if (!passive && !this.bang()) { return }
this.draw = false
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 = OperatorP
|