diff options
author | Devine Lu Linvega <[email protected]> | 2018-12-14 11:59:34 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-12-14 11:59:34 +1200 |
commit | 4ddc2a50a3136775c65ebeed1d399d3a678d00c4 (patch) | |
tree | 9af7305c89a93627d3a998b9b374c739339aa34b | |
parent | 7edda42784cd4fcad9970baea251629cd670254b (diff) | |
download | Orca-4ddc2a50a3136775c65ebeed1d399d3a678d00c4.tar.gz Orca-4ddc2a50a3136775c65ebeed1d399d3a678d00c4.zip |
Progress
-rw-r--r-- | desktop/core/library.js | 3 | ||||
-rw-r--r-- | desktop/core/library/_room.js | 20 | ||||
-rw-r--r-- | desktop/core/orca.js | 4 | ||||
-rw-r--r-- | desktop/main.js | 2 | ||||
-rw-r--r-- | desktop/sources/index.html | 5 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 5 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 83 | ||||
-rw-r--r-- | examples/projects/room.orca | 33 |
8 files changed, 113 insertions, 42 deletions
diff --git a/desktop/core/library.js b/desktop/core/library.js index 7ff7670..1ad9be1 100644 --- a/desktop/core/library.js +++ b/desktop/core/library.js @@ -41,5 +41,6 @@ module.exports = { '#': require('./library/_comment'), ';': require('./library/_udp'), ':': require('./library/_midi'), - '!': require('./library/_keys') + '!': require('./library/_keys'), + '/': require('./library/_room') } diff --git a/desktop/core/library/_room.js b/desktop/core/library/_room.js new file mode 100644 index 0000000..9ca0f24 --- /dev/null +++ b/desktop/core/library/_room.js @@ -0,0 +1,20 @@ +'use strict' + +const Operator = require('../operator') + +function OperatorRoom (orca, x, y, passive) { + Operator.call(this, orca, x, y, '/', true) + + this.name = 'room' + this.info = 'Hosts a nested Orca grid.' + + this.ports.haste.id = { x: -1, y: 0 } + + this.run = function () { + const id = this.listen(this.ports.haste.id) + // console.log(id,orca.terminal.rooms[id]) + // orca.terminal.rooms[id].run() + } +} + +module.exports = OperatorRoom diff --git a/desktop/core/orca.js b/desktop/core/orca.js index f55cdd3..3360436 100644 --- a/desktop/core/orca.js +++ b/desktop/core/orca.js @@ -18,7 +18,9 @@ function Orca (library = {}) { this.f += 1 } - this.reset = function () { + this.reset = function (w = this.w, h = this.h) { + this.w = w + this.h = h this.s = new Array((this.h * this.w) + 1).join('.') } diff --git a/desktop/main.js b/desktop/main.js index f9d234b..28c6d8d 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -22,7 +22,7 @@ app.on('ready', () => { }) app.win.loadURL(`file://${__dirname}/sources/index.html`) - // app.inspect() + app.inspect() app.win.on('closed', () => { win = null diff --git a/desktop/sources/index.html b/desktop/sources/index.html index eddf0a6..250d33b 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -13,11 +13,8 @@ </head> <body> <script> - const Orca = require('../core/orca') - const library = require('../core/library') const Terminal = require('./scripts/terminal') - const orca = new Orca(library) const terminal = new Terminal(orca) const { app } = require('electron').remote @@ -59,8 +56,6 @@ terminal.controller.add("default","Program","Incr. Row",() => { terminal.modGrid(0,1); },"}") terminal.controller.add("default","Program","Decr. Row",() => { terminal.modGrid(0,-1); },"{") - terminal.controller.add("default","Keyboard","Toggle Play Mode",() => { terminal.cursor.toggleMode(2); },"/") - terminal.controller.add("default","Theme","Open Theme",() => { terminal.theme.open(); },"CmdOrCtrl+Shift+o") terminal.controller.add("default","Theme","Reset Theme",() => { terminal.theme.reset(); },"CmdOrCtrl+Shift+Backspace") terminal.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes'); }) diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index cb11a4c..c4fbf57 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -24,6 +24,7 @@ function Cursor (orca, terminal) { this.w = 1 this.h = 1 this.mode = 0 + terminal.enter() } this.selectAll = function () { @@ -68,6 +69,10 @@ function Cursor (orca, terminal) { } this.toggleMode = function (val) { + if (orca.glyphAt(this.x, this.y) === '/') { + terminal.enter(orca.s.charAt(orca.indexAt(this.x, this.y) - 1)) + return + } this.mode = this.mode === 0 ? val : 0 } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index 415285b..379680b 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -1,6 +1,8 @@ 'use strict' function Terminal (orca, tile = { w: 20, h: 30 }) { + const library = require('../../core/library') + const Orca = require('../core/orca') const Cursor = require('./cursor') const Source = require('./source') const History = require('./history') @@ -14,6 +16,9 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.keyboard = new Keyboard(orca, this) this.controller = new Controller() + this.rooms = { hall: new Orca(library) } + this.room = this.rooms.hall + // Themes const noir = { background: '#111111', f_high: '#ffffff', f_med: '#777777', f_low: '#444444', f_inv: '#000000', b_high: '#eeeeee', b_med: '#72dec2', b_low: '#444444', b_inv: '#ffb545' } const pale = { background: '#eeeeee', f_high: '#222222', f_med: '#444444', f_low: '#cccccc', f_inv: '#000000', b_high: '#000000', b_med: '#333333', b_low: '#dddddd', b_inv: '#72dec2' } @@ -22,7 +27,7 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.el = document.createElement('canvas') this.context = this.el.getContext('2d') - this.size = { width: tile.w * orca.w, height: tile.h * orca.h + (tile.h * 3), ratio: 0.5, grid: { w: 8, h: 8 } } + this.size = { width: tile.w * this.room.w, height: tile.h * this.room.h + (tile.h * 3), ratio: 0.5, grid: { w: 8, h: 8 } } this.isPaused = false this.timer = null this.bpm = 120 @@ -31,7 +36,7 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.resize() host.appendChild(this.el) this.theme.install(host) - orca.terminal = this + this.room.terminal = this } this.start = function () { @@ -46,7 +51,7 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.run = function () { if (this.isPaused) { return } this.io.clear() - orca.run() + this.rooms.hall.run() this.io.run() this.update() } @@ -64,7 +69,7 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { if (w < 10 || h < 10) { console.warn('Too small'); return } if (w > 121 || h > 49) { console.warn('Too large'); return } console.log(`Loading ${w}x${h}`) - orca.load(w, h, data, frame) + this.room.load(w, h, data, frame) this.resize() this.update() } @@ -87,6 +92,14 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.theme.reset() } + this.enter = function (id = 'hall') { + if (!this.rooms[id]) { this.rooms[id] = new Orca(library); this.rooms[id].reset(20, 13) } + console.log(`Enterting Room:${id}`) + this.room = this.rooms[id] + this.resize(false) + this.update() + } + // this.setSpeed = function (bpm) { @@ -105,18 +118,18 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.setSize = function (w, h) { let block = `${orca}` - if (h > orca.h) { - block = `${block}${`\n${'.'.repeat(orca.w)}`.repeat((h - orca.h))}` - } else if (h < orca.h) { - block = `${block}`.split('\n').slice(0, (h - orca.h)).join('\n').trim() + if (h > this.room.h) { + block = `${block}${`\n${'.'.repeat(this.room.w)}`.repeat((h - this.room.h))}` + } else if (h < this.room.h) { + block = `${block}`.split('\n').slice(0, (h - this.room.h)).join('\n').trim() } - if (w > orca.w) { - block = `${block}`.split('\n').map((val) => { return val + ('.').repeat((w - orca.w)) }).join('\n').trim() - } else if (w < orca.w) { - block = `${block}`.split('\n').map((val) => { return val.substr(0, val.length + (w - orca.w)) }).join('\n').trim() + if (w > this.room.w) { + block = `${block}`.split('\n').map((val) => { return val + ('.').repeat((w - this.room.w)) }).join('\n').trim() + } else if (w < this.room.w) { + block = `${block}`.split('\n').map((val) => { return val.substr(0, val.length + (w - this.room.w)) }).join('\n').trim() } - this.load(block, orca.f) + this.load(block, this.room.f) } this.modSpeed = function (mod = 0) { @@ -130,8 +143,8 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { } this.modSize = function (x = 0, y = 0) { - const w = ((parseInt(orca.w / this.size.grid.w) + x) * this.size.grid.w) + 1 - const h = ((parseInt(orca.h / this.size.grid.h) + y) * this.size.grid.h) + 1 + const w = ((parseInt(this.room.w / this.size.grid.w) + x) * this.size.grid.w) + 1 + const h = ((parseInt(this.room.h / this.size.grid.h) + y) * this.size.grid.h) + 1 this.setSize(w, h) } @@ -151,9 +164,9 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.findPorts = function () { const h = {} - for (const id in orca.runtime) { - const g = orca.runtime[id] - if (orca.lockAt(g.x, g.y)) { continue } + for (const id in this.room.runtime) { + const g = this.room.runtime[id] + if (this.room.lockAt(g.x, g.y)) { continue } // Default/Passive if (!h[`${g.x}:${g.y}`]) { h[`${g.x}:${g.y}`] = { type: g.passive && g.draw ? 'passive' : 'none', name: `${g.name}` } @@ -181,17 +194,17 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { } this.guide = function (x, y) { - const g = orca.glyphAt(x, y) + const g = this.room.glyphAt(x, y) if (g !== '.') { return g } if (x % this.size.grid.w === 0 && y % this.size.grid.h === 0) { return '+' } return g } this.drawProgram = function () { - for (let y = 0; y < orca.h; y++) { - for (let x = 0; x < orca.w; x++) { + for (let y = 0; y < this.room.h; y++) { + for (let x = 0; x < this.room.w; x++) { const port = this.ports[`${x}:${y}`] - const styles = { isSelection: this.isSelection(x, y), isCursor: this.isCursor(x, y), isPort: port ? port.type : false, isLocked: orca.lockAt(x, y) } + const styles = { isSelection: this.isSelection(x, y), isCursor: this.isCursor(x, y), isPort: port ? port.type : false, isLocked: this.room.lockAt(x, y) } this.drawSprite(x, y, this.guide(x, y), styles) } } @@ -205,10 +218,10 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.write(`${this.cursor.inspect()}`, col * 2, 1, this.size.grid.w) this.write(`${this.source}${this.cursor.mode === 2 ? '^' : this.cursor.mode === 1 ? '+' : ''}`, col * 3, 1, this.size.grid.w) // Grid - this.write(`${orca.w}x${orca.h}`, col * 0, 0, this.size.grid.w) + this.write(`${this.room.w}x${this.room.h}`, col * 0, 0, this.size.grid.w) this.write(`${this.size.grid.w}/${this.size.grid.h}`, col * 1, 0, this.size.grid.w) - this.write(`${orca.f}f${this.isPaused ? '*' : ''}`, col * 2, 0, this.size.grid.w) - this.write(`${this.bpm}${orca.f % 4 === 0 ? '*' : ''}`, col * 3, 0, this.size.grid.w) + this.write(`${this.room.f}f${this.isPaused ? '*' : ''}`, col * 2, 0, this.size.grid.w) + this.write(`${this.bpm}${this.room.f % 4 === 0 ? '*' : ''}`, col * 3, 0, this.size.grid.w) this.write(`${this.io}`, col * 4, 0, this.size.grid.w) } @@ -255,7 +268,7 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { let x = 0 while (x < text.length && x < limit - 1) { const c = text.substr(x, 1) - this.drawSprite(offsetX + x, orca.h + offsetY, c, { f: 'f_high', b: 'background' }) + this.drawSprite(offsetX + x, this.room.h + offsetY, c, { f: 'f_high', b: 'background' }) x += 1 } } @@ -264,21 +277,23 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.el.style.marginTop = (((window.innerHeight - (terminal.size.height * terminal.size.ratio)) / 2) - 20) + 'px' } - this.resize = function () { - this.size.width = tile.w * orca.w - this.size.height = tile.h * orca.h + (tile.h * 3) + this.resize = function (resizeWindow = true) { + this.size.width = tile.w * this.room.w + this.size.height = tile.h * this.room.h + (tile.h * 3) this.el.width = this.size.width this.el.height = this.size.height + tile.h this.el.style.width = (this.size.width * this.size.ratio) + 'px' this.el.style.height = (this.size.height * this.size.ratio) + 'px' this.align() - const { remote } = require('electron') - const win = remote.getCurrentWindow() - const width = parseInt((this.size.width * this.size.ratio) + 60) - const height = parseInt((this.size.height * this.size.ratio) + 30) - win.setSize(width, height, true) + if (resizeWindow === true) { + const { remote } = require('electron') + const win = remote.getCurrentWindow() + const width = parseInt((this.size.width * this.size.ratio) + 60) + const height = parseInt((this.size.height * this.size.ratio) + 30) + win.setSize(width, height, true) + } } function clamp (v, min, max) { return v < min ? min : v > max ? max : v } diff --git a/examples/projects/room.orca b/examples/projects/room.orca new file mode 100644 index 0000000..42a7f52 --- /dev/null +++ b/examples/projects/room.orca @@ -0,0 +1,33 @@ +......................................... +.#.MAIN.#................................ +......................................... +..1/..................................... +......................................... +..2/..................................... +......................................... +......................................... +......................................... +......................................... +......................................... +......................................... +......................................... +// +.................... +.#.HALLWAY.#........ +.................... +.................... +.................... +.................... +.................... +.................... +.................... +// +.................... +.#.CAVE.#........... +.................... +.................... +.................... +.................... +.................... +.................... +....................
\ No newline at end of file |