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
|
'use strict'
const FnBase = require('./_base')
function FnD (pico, x, y) {
FnBase.call(this, pico, x, y)
this.name = 'deflect'
this.glyph = 'd'
this.info = 'Converts neighboors into direction functions.'
this.ports = [{ x: 0, y: 1 }, { x: 0, y: -1 }, { x: 1, y: 0 }, { x: -1, y: 0 }]
this.operation = function () {
if (this.north() && this.north().glyph != 'n') {
pico.add(this.x, this.y - 1, 'n')
pico.lock(this.x, this.y - 1)
}
if (this.south() && this.south().glyph != 'd') {
pico.add(this.x, this.y + 1, 'd')
pico.lock(this.x, this.y + 1)
}
if (this.west() && this.west().glyph != 'w') {
pico.add(this.x - 1, this.y, 'w')
pico.lock(this.x - 1, this.y)
}
if (this.east() && this.east().glyph != 'e') {
pico.add(this.x + 1, this.y, 'e')
pico.lock(this.x + 1, this.y)
}
}
}
module.exports = FnD
|