aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-12-14 17:22:42 +1200
committerDevine Lu Linvega <[email protected]>2018-12-14 17:22:42 +1200
commita276bec05fb0155d2a50ad7c1b3b565103edfbad (patch)
treef54b1fc3c99d4047595ad9e8bb0e9a3b7b5d28b9
parent19c5f09d6c4479886e8324066108eae80a8a46b4 (diff)
downloadOrca-a276bec05fb0155d2a50ad7c1b3b565103edfbad.tar.gz
Orca-a276bec05fb0155d2a50ad7c1b3b565103edfbad.zip
Started parsing new file formats
-rw-r--r--desktop/core/library.js2
-rw-r--r--desktop/core/library/_door.js (renamed from desktop/core/library/_room.js)6
-rw-r--r--desktop/core/orca.js6
-rw-r--r--desktop/sources/scripts/source.js32
-rw-r--r--desktop/sources/scripts/terminal.js25
-rw-r--r--examples/projects/room.orca10
-rw-r--r--server.js2
7 files changed, 60 insertions, 23 deletions
diff --git a/desktop/core/library.js b/desktop/core/library.js
index 1ad9be1..163ba6b 100644
--- a/desktop/core/library.js
+++ b/desktop/core/library.js
@@ -42,5 +42,5 @@ module.exports = {
';': require('./library/_udp'),
':': require('./library/_midi'),
'!': require('./library/_keys'),
- '/': require('./library/_room')
+ '/': require('./library/_door')
}
diff --git a/desktop/core/library/_room.js b/desktop/core/library/_door.js
index f0daf72..108acc2 100644
--- a/desktop/core/library/_room.js
+++ b/desktop/core/library/_door.js
@@ -2,10 +2,10 @@
const Operator = require('../operator')
-function OperatorRoom (orca, x, y, passive) {
+function OperatorDoor (orca, x, y, passive) {
Operator.call(this, orca, x, y, '/', true)
- this.name = 'room'
+ this.name = 'door'
this.info = 'Hosts a nested Orca grid.'
this.ports.input.val = { x: 1, y: 0 }
@@ -25,4 +25,4 @@ function OperatorRoom (orca, x, y, passive) {
}
}
-module.exports = OperatorRoom
+module.exports = OperatorDoor
diff --git a/desktop/core/orca.js b/desktop/core/orca.js
index 6ed5143..bc676b1 100644
--- a/desktop/core/orca.js
+++ b/desktop/core/orca.js
@@ -1,12 +1,14 @@
'use strict'
-function Orca (library = {}) {
+const library = require('./library')
+
+function Orca (terminal) {
this.w = 65 // Default Width
this.h = 25 // Default Height
this.s = '' // String
this.f = 0 // Frame
- this.terminal = null
+ this.terminal = terminal
this.keys = Object.keys(library)
this.locks = []
this.ports = {}
diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js
index 87bc2d7..40524dc 100644
--- a/desktop/sources/scripts/source.js
+++ b/desktop/sources/scripts/source.js
@@ -1,6 +1,7 @@
'use strict'
-function Source (terminal, orca = terminal.room) {
+function Source (terminal) {
+ const Orca = require('../../core/orca')
const fs = require('fs')
const { dialog, app } = require('electron').remote
@@ -8,10 +9,12 @@ function Source (terminal, orca = terminal.room) {
this.new = function () {
console.log('New')
- orca.w = 65
- orca.h = 25
- orca.reset()
+
this.path = null
+
+ terminal.rooms = { hall: new Orca(terminal) }
+ terminal.room = terminal.rooms.hall
+ terminal.enter()
terminal.resize()
terminal.history.reset()
}
@@ -26,6 +29,8 @@ function Source (terminal, orca = terminal.room) {
this.save = function (as = false) {
console.log('Save')
+ this.generate()
+ return
if (this.path && !as) {
this.write(this.path)
} else {
@@ -52,7 +57,7 @@ function Source (terminal, orca = terminal.room) {
// I/O
this.write = function (path) {
- fs.writeFile(path, `${orca}`, (err) => {
+ fs.writeFile(path, this.generate(), (err) => {
if (err) { alert('An error ocurred updating the file' + err.message); console.log(err) }
})
}
@@ -65,6 +70,23 @@ function Source (terminal, orca = terminal.room) {
})
}
+ // Converters
+
+ this.parse = function (text) {
+
+ }
+
+ this.generate = function (rooms = terminal.rooms) {
+ let html = `${rooms.hall}\n\n`
+ for (const id in rooms) {
+ if (id !== 'hall') {
+ const room = rooms[id]
+ html += `$${id}\n\n${room}\n\n`
+ }
+ }
+ return html.trim()
+ }
+
this.name = function () {
const parts = this.path.split('/')
return parts[parts.length - 1].replace('.orca', '').trim()
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 7cd71d1..1df407b 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -1,7 +1,6 @@
'use strict'
function Terminal (tile = { w: 20, h: 30 }) {
- const library = require('../../core/library')
const Orca = require('../../core/orca')
const Cursor = require('./cursor')
const Source = require('./source')
@@ -9,8 +8,7 @@ function Terminal (tile = { w: 20, h: 30 }) {
const Keyboard = require('./keyboard')
const IO = require('./io')
- this.rooms = { hall: new Orca(library) }
- this.room = this.rooms.hall
+ this.library = require('../../core/library')
this.io = new IO(this)
this.cursor = new Cursor(this)
@@ -27,23 +25,23 @@ function Terminal (tile = { w: 20, h: 30 }) {
this.el = document.createElement('canvas')
this.context = this.el.getContext('2d')
- 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.size = { width: 0, height: 0, ratio: 0.5, grid: { w: 8, h: 8 } }
this.isPaused = false
this.timer = null
this.bpm = 120
this.install = function (host) {
- this.resize()
host.appendChild(this.el)
this.theme.install(host)
- this.room.terminal = this
}
this.start = function () {
this.theme.start()
this.io.start()
+ this.source.new()
this.history.record()
this.setSpeed(120)
+ this.resize()
this.update()
this.el.className = 'ready'
}
@@ -92,10 +90,21 @@ function Terminal (tile = { w: 20, h: 30 }) {
this.theme.reset()
}
+ this.create = function (id) {
+ console.log(`Creating Room:${id}`)
+ this.rooms[id] = new Orca(this)
+ this.rooms[id].reset(33, 17)
+ }
+
this.enter = function (id = 'hall') {
- if (!this.rooms[id]) { this.rooms[id] = new Orca(library); this.rooms[id].reset(33, 17) }
+ if (!this.rooms[id]) {
+ this.create(id)
+ }
+
console.log(`Enterting Room:${id}`)
+
this.room = this.rooms[id]
+ this.room.id = id
this.resize(false)
this.update()
}
@@ -216,7 +225,7 @@ function Terminal (tile = { w: 20, h: 30 }) {
this.write(`${this.cursor.x},${this.cursor.y}`, col * 0, 1, this.size.grid.w)
this.write(`${this.cursor.w}:${this.cursor.h}`, col * 1, 1, this.size.grid.w)
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)
+ this.write(`${this.source}${this.cursor.mode === 2 ? '^' : this.cursor.mode === 1 ? '+' : ''}${this.room.id && this.room.id !== 'hall' ? '/' + this.room.id : ''}`, col * 3, 1, this.size.grid.w)
// Grid
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)
diff --git a/examples/projects/room.orca b/examples/projects/room.orca
index 42a7f52..cfb7156 100644
--- a/examples/projects/room.orca
+++ b/examples/projects/room.orca
@@ -11,7 +11,9 @@
.........................................
.........................................
.........................................
-//
+
+1
+
....................
.#.HALLWAY.#........
....................
@@ -21,7 +23,9 @@
....................
....................
....................
-//
+
+2
+
....................
.#.CAVE.#...........
....................
@@ -30,4 +34,4 @@
....................
....................
....................
-.................... \ No newline at end of file
+....................
diff --git a/server.js b/server.js
index ff94290..5b42261 100644
--- a/server.js
+++ b/server.js
@@ -9,7 +9,7 @@ function run (data,frames) {
const Orca = require('./desktop/core/orca')
const library = require('./desktop/core/library')
- const orca = new Orca(library)
+ const orca = new Orca(terminal)
const w = data.split('\n')[0].length
const h = data.split('\n').length