aboutsummaryrefslogtreecommitdiffhomepage
path: root/core/lib/y.js
blob: b55b2d837157c801edf7b7dc1734566a48b2edf3 (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
'use strict'

const FnBase = require('./_base')

function FnY (pico, x, y) {
  FnBase.call(this, pico, x, y)

  this.name = 'type'
  this.glyph = 'y'
  this.info = 'Compares the type(num/alpha/special) of westward and eastward fns, and return 1 or 0 southward.'
  this.ports = [{ x: -1, y: 0, input: true }, { x: 1, y: 0, input: true }, { x: 0, y: 1, output: true }]

  this.haste = function () {
    pico.lock(this.x, this.y + 1)
    pico.lock(this.x + 1, this.y)
    pico.lock(this.x - 1, this.y)
  }

  this.operation = function () {
    const w = this.west()
    const e = this.east()
    if (!w && !this.east()) {
      pico.add(this.x, this.y + 1, '1')
    } else if ((w && !e) || (e && !w)) {
      pico.add(this.x, this.y + 1, '0')
    } else if ((w && !e) || (e && !w)) {
      pico.add(this.x, this.y + 1, '0')
    } else if (isNum(w.glyph) === isNum(e.glyph)) {
      pico.add(this.x, this.y + 1, '1')
    } else {
      pico.add(this.x, this.y + 1, '0')
    }
  }

  function isNum (c) {
    return pico.lib.num[c]
  }
}

module.exports = FnY