diff options
author | Devine Lu Linvega <[email protected]> | 2018-12-14 17:51:29 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-12-14 17:51:29 +1200 |
commit | 358fea3ce6ee4f31c1ef105faacbe4ffeec584a0 (patch) | |
tree | dbbd7bf5bfa4980d4e2780343245729e49d5a3a6 | |
parent | a276bec05fb0155d2a50ad7c1b3b565103edfbad (diff) | |
download | Orca-358fea3ce6ee4f31c1ef105faacbe4ffeec584a0.tar.gz Orca-358fea3ce6ee4f31c1ef105faacbe4ffeec584a0.zip |
Working copy
-rw-r--r-- | desktop/core/orca.js | 1 | ||||
-rw-r--r-- | desktop/sources/index.html | 1 | ||||
-rw-r--r-- | desktop/sources/scripts/source.js | 46 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 14 |
4 files changed, 36 insertions, 26 deletions
diff --git a/desktop/core/orca.js b/desktop/core/orca.js index bc676b1..e2076e6 100644 --- a/desktop/core/orca.js +++ b/desktop/core/orca.js @@ -31,6 +31,7 @@ function Orca (terminal) { this.h = h this.f = f this.s = this.clean(s) + return this } this.write = function (x, y, g) { diff --git a/desktop/sources/index.html b/desktop/sources/index.html index ad6e0cd..01b6149 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -31,7 +31,6 @@ terminal.controller.add("default","File","Save As",() => { terminal.source.save(true); },"CmdOrCtrl+Shift+S") terminal.controller.add("default","File","Open",() => { terminal.source.open(); },"CmdOrCtrl+O") terminal.controller.add("default","File","Revert",() => { terminal.source.revert(); },"CmdOrCtrl+Shift+R") - terminal.controller.add("default","File","Close",() => { terminal.source.close(); },"CmdOrCtrl+W") terminal.controller.add("default","Edit","Select All",() => { terminal.cursor.selectAll(); },"CmdOrCtrl+A") terminal.controller.add("default","Edit","Erase Selection",() => { terminal.cursor.erase(); },"Backspace") diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js index 40524dc..77a5ab1 100644 --- a/desktop/sources/scripts/source.js +++ b/desktop/sources/scripts/source.js @@ -29,8 +29,6 @@ function Source (terminal) { this.save = function (as = false) { console.log('Save') - this.generate() - return if (this.path && !as) { this.write(this.path) } else { @@ -48,12 +46,6 @@ function Source (terminal) { this.read(this.path) } - this.close = function () { - console.log('Close') - orca.reset() - this.path = null - } - // I/O this.write = function (path) { @@ -63,30 +55,54 @@ function Source (terminal) { } this.read = function (path) { - fs.readFile(path, 'utf8', function (err, data) { + fs.readFile(path, 'utf8', (err, data) => { if (err) throw err - terminal.load(data.trim()) + const rooms = this.parse(data) + terminal.load(rooms) terminal.history.record() }) } // 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` + html += `${id}\n\n${room}\n\n` } } return html.trim() } + this.parse = function (text) { + const lines = text.split('\n') + const blocks = { hall: [] } + const rooms = { hall: [] } + const room = [] + let key = 'hall' + // Blocks + for (const id in lines) { + const line = lines[id].trim() + if (line.length === 0) { continue } + if (line.length === 1) { key = line; continue } + if (!blocks[key]) { blocks[key] = [] } + blocks[key].push(line) + } + // Rooms + for (const id in blocks) { + const block = blocks[id] + const w = block[0].length + const h = block.length + const s = block.join('\n').trim() + rooms[id] = new Orca(terminal).load(w, h, s) + } + return rooms + } + + // Etc + 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 1df407b..e223f1f 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -60,16 +60,10 @@ function Terminal (tile = { w: 20, h: 30 }) { this.update() } - this.load = function (data, frame = 0) { - if (!data) { return } - const w = data.split('\n')[0].length - const h = data.split('\n').length - 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}`) - this.room.load(w, h, data, frame) - this.resize() - this.update() + this.load = function (rooms, frame = 0) { + console.log(rooms) + this.rooms = rooms + this.enter() } this.crop = function () { |