diff options
author | Devine Lu Linvega <[email protected]> | 2018-10-16 10:24:09 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-10-16 10:24:09 +1200 |
commit | 66088f9d69ad20a20463937e22124b87e7a93da3 (patch) | |
tree | f2de74d10f6181dbceca211117c7f79b7b7f6297 | |
parent | 90ec8e3f23d3bbcfcf8f7ba4fe5f59222ed8bbec (diff) | |
download | Orca-66088f9d69ad20a20463937e22124b87e7a93da3.tar.gz Orca-66088f9d69ad20a20463937e22124b87e7a93da3.zip |
Implemented BPM
-rw-r--r-- | desktop/core/lib.js | 2 | ||||
-rw-r--r-- | desktop/core/lib/__bpm.js | 7 | ||||
-rw-r--r-- | desktop/core/lib/_base.js | 3 | ||||
-rw-r--r-- | desktop/core/lib/_query.js | 22 | ||||
-rw-r--r-- | desktop/core/lib/c.js | 6 | ||||
-rw-r--r-- | desktop/core/lib/s.js | 2 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 14 |
7 files changed, 33 insertions, 23 deletions
diff --git a/desktop/core/lib.js b/desktop/core/lib.js index 81838fa..fe82c0e 100644 --- a/desktop/core/lib.js +++ b/desktop/core/lib.js @@ -50,6 +50,6 @@ module.exports = { '+': require('./lib/_wiref') }, queries: { - 'bpm': require('./lib/__bpm'), + 'bpm': require('./lib/__bpm') } } diff --git a/desktop/core/lib/__bpm.js b/desktop/core/lib/__bpm.js index f141d73..25e269c 100644 --- a/desktop/core/lib/__bpm.js +++ b/desktop/core/lib/__bpm.js @@ -9,7 +9,7 @@ function FnBpm (pico, x, y) { this.glyph = '?' this.info = 'Changes the speed of Pico.' - this.ports = [{ x: 1, y: 0, output: true },{ x: 2, y: 0, output: true },{ x: 3, y: 0, output: true }] + this.ports = [{ x: 1, y: 0, output: true }, { x: 2, y: 0, output: true }, { x: 3, y: 0, output: true }] this.haste = function () { pico.lock(this.x + 1, this.y) @@ -19,8 +19,11 @@ function FnBpm (pico, x, y) { this.run = function () { const val = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}` - pico.terminal.log(`Set bpm to ${val}.`) + if (val.indexOf('.') > -1) { return } + pico.terminal.setSpeed(val) } + + function clamp (v, min, max) { return v < min ? min : v > max ? max : v } } module.exports = FnBpm diff --git a/desktop/core/lib/_base.js b/desktop/core/lib/_base.js index cfd400a..9e1c095 100644 --- a/desktop/core/lib/_base.js +++ b/desktop/core/lib/_base.js @@ -30,7 +30,6 @@ function FnBase (pico, x, y) { } this.replace = function (g) { - this.lock() pico.add(this.x, this.y, g) } @@ -75,7 +74,7 @@ function FnBase (pico, x, y) { const ns = this.neighbors('b') for (const id in ns) { const n = ns[id] - if (pico.glyphAt(n.x, n.y - 1) !== 'h') { + if (!pico.isLocked(n.x, n.y)) { return { x: n.x, y: n.y } } } diff --git a/desktop/core/lib/_query.js b/desktop/core/lib/_query.js index 803c200..d8025d4 100644 --- a/desktop/core/lib/_query.js +++ b/desktop/core/lib/_query.js @@ -10,14 +10,14 @@ function FnQuery (pico, x, y) { this.info = 'Call a function by name, freezes 3 characters eastward.' const cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}` - this.queryFn = pico.lib.queries[cmd] ? new pico.lib.queries[cmd](pico,x+3,y) : null + this.query = pico.lib.queries[cmd] ? new pico.lib.queries[cmd](pico, x + 3, y) : null - this.ports = [{ x: 1, y: 0, bang: true },{ x: 2, y: 0, bang: true },{ x: 3, y: 0, bang: true }] + this.ports = [{ x: 1, y: 0, bang: true }, { x: 2, y: 0, bang: true }, { x: 3, y: 0, bang: true }] - if(this.queryFn){ - for(const id in this.queryFn.ports){ - const port = this.queryFn.ports[id] - this.ports.push({x:port.x+3,y:port.y,bang:port.bang,output:port.output}) + if (this.query) { + for (const id in this.query.ports) { + const port = this.query.ports[id] + this.ports.push({ x: port.x + 3, y: port.y, bang: port.bang, output: port.output }) } } @@ -25,17 +25,17 @@ function FnQuery (pico, x, y) { pico.lock(this.x + 1, this.y) pico.lock(this.x + 2, this.y) pico.lock(this.x + 3, this.y) - if(this.queryFn){ - this.queryFn.haste() + if (this.query) { + this.query.haste() } } this.run = function () { - const cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}` + if (!this.bang()) { return } + const cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}` if (cmd.indexOf('.') > -1) { return } - - this.queryFn.run() + this.query.run() } } diff --git a/desktop/core/lib/c.js b/desktop/core/lib/c.js index 33a50f1..f0d102b 100644 --- a/desktop/core/lib/c.js +++ b/desktop/core/lib/c.js @@ -10,9 +10,9 @@ function FnC (pico, x, y) { this.ports = [{ x: 0, y: 0, bang: true }, { x: 1, y: 0, output: true }, { x: -1, y: 0 }] this.operation = function () { - if (this.bang() && this.west()) { - pico.add(this.x + 1, this.y, this.west().glyph) - } + if (!this.bang() || !this.west()) { return } + + pico.add(this.x + 1, this.y, this.west().glyph) } } diff --git a/desktop/core/lib/s.js b/desktop/core/lib/s.js index 32190d5..d4fda97 100644 --- a/desktop/core/lib/s.js +++ b/desktop/core/lib/s.js @@ -11,7 +11,7 @@ function FnS (pico, x, y) { this.haste = function () { if (this.signal()) { return } - if (this.is_free(0, 1) !== true) { this.replace('b'); this.lock(); return } + if (this.is_free(0, 1) !== true) { this.replace('b'); return } this.move(0, 1) } } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index bc84dfc..e68f399 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -8,6 +8,7 @@ function Terminal (pico) { this.is_paused = false this.tile = { w: 12, h: 20 } this.debug = "hello." + this.timer = null this.cursor = { x: 0, @@ -25,7 +26,7 @@ function Terminal (pico) { }, inspect: function () { const g = pico.glyphAt(this.x, this.y) - return pico.docs[g] ? pico.docs[g] : 'idle.' + return pico.docs[g] ? pico.docs[g] : `${this.x},${this.y}` } } @@ -57,7 +58,15 @@ function Terminal (pico) { this.log("Started.") this.update() - setInterval(() => { this.run() }, 200) + this.setSpeed(120) + } + + this.setSpeed = function(bpm) + { + this.log(`Changed speed to ${bpm}.`) + const ms = (60000/bpm)/4 + clearInterval(this.timer); + this.timer = setInterval(() => { this.run() }, ms) } this.run = function () { @@ -174,7 +183,6 @@ function Terminal (pico) { this.clear = function () { const ctx = this.context() - ctx.clearRect(0, 0, this.size.width, this.size.height) } |