diff options
author | neauoire <[email protected]> | 2019-12-04 11:38:10 -0500 |
---|---|---|
committer | neauoire <[email protected]> | 2019-12-04 11:38:10 -0500 |
commit | d289b64defa666e49685917a184fe282d98cda07 (patch) | |
tree | fd6988eecad55126299934186c9074b9989ccef7 | |
parent | 64ab9c284cda13ad68a4c8f544e756992fad4cae (diff) | |
download | Orca-d289b64defa666e49685917a184fe282d98cda07.tar.gz Orca-d289b64defa666e49685917a184fe282d98cda07.zip |
Always use plaintext within orca, no more arrays
-rw-r--r-- | desktop/sources/scripts/client.js | 17 | ||||
-rw-r--r-- | desktop/sources/scripts/commander.js | 16 | ||||
-rw-r--r-- | desktop/sources/scripts/core/orca.js | 28 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 52 | ||||
-rw-r--r-- | sw.js | 2 |
5 files changed, 56 insertions, 59 deletions
diff --git a/desktop/sources/scripts/client.js b/desktop/sources/scripts/client.js index 00d845c..2bf9ab5 100644 --- a/desktop/sources/scripts/client.js +++ b/desktop/sources/scripts/client.js @@ -12,7 +12,7 @@ /* global Theme */ function Client () { - this.version = 161 + this.version = 162 this.library = library this.theme = new Theme(this) @@ -47,9 +47,10 @@ function Client () { this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.reset() }) this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('orca', this.whenOpen, true) }) - this.acels.set('File', 'Load Modules', 'CmdOrCtrl+L', () => { this.source.load('orca') }) - this.acels.set('File', 'Load Images', 'CmdOrCtrl+Shift+L', () => { this.source.load('jpg') }) - this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.write('orca', 'orca', `${this.orca}`, 'text/plain') }) + this.acels.set('File', 'Import Modules', 'CmdOrCtrl+L', () => { this.source.load('orca') }) + this.acels.set('File', 'Import Images', 'CmdOrCtrl+Shift+L', () => { this.source.load('jpg') }) + this.acels.set('File', 'Export', 'CmdOrCtrl+S', () => { this.source.write('orca', 'orca', `${this.orca}`, 'text/plain') }) + this.acels.set('File', 'Export Selection', 'CmdOrCtrl+Shift+S', () => { this.source.write('orca', 'orca', `${this.cursor.selection()}`, 'text/plain') }) this.acels.add('Edit', 'cut') this.acels.add('Edit', 'copy') @@ -171,7 +172,7 @@ function Client () { } this.whenOpen = (file, text) => { - const lines = text.trim().split('\n') + const lines = text.trim().split(/\r?\n/) const w = lines[0].length const h = lines.length const s = lines.join('\n').trim() @@ -408,13 +409,13 @@ function Client () { if (h > this.orca.h) { block = `${block}${`\n${'.'.repeat(this.orca.w)}`.repeat((h - this.orca.h))}` } else if (h < this.orca.h) { - block = `${block}`.split('\n').slice(0, (h - this.orca.h)).join('\n').trim() + block = `${block}`.split(/\r?\n/).slice(0, (h - this.orca.h)).join('\n').trim() } if (w > this.orca.w) { - block = `${block}`.split('\n').map((val) => { return val + ('.').repeat((w - this.orca.w)) }).join('\n').trim() + block = `${block}`.split(/\r?\n/).map((val) => { return val + ('.').repeat((w - this.orca.w)) }).join('\n').trim() } else if (w < this.orca.w) { - block = `${block}`.split('\n').map((val) => { return val.substr(0, val.length + (w - this.orca.w)) }).join('\n').trim() + block = `${block}`.split(/\r?\n/).map((val) => { return val.substr(0, val.length + (w - this.orca.w)) }).join('\n').trim() } this.history.reset() diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 43739e2..e9ea0d2 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -14,8 +14,9 @@ function Commander (client) { inject: (p) => { client.cursor.select(p._x, p._y) if (client.source.cache[p._str + '.orca']) { - const lines = client.source.cache[p._str + '.orca'].trim().split('\n') - client.cursor.scaleTo(lines[0].length - 1, lines.length - 1) + const block = client.source.cache[p._str + '.orca'] + const rect = client.orca.toRect(block) + client.cursor.scaleTo(rect.x, rect.y) } }, write: (p) => { client.cursor.select(p._x, p._y, p._str.length) } @@ -44,7 +45,7 @@ function Commander (client) { skip: (p) => { client.clock.setFrame(client.orca.f + p.int) }, time: (p, origin) => { const formatted = new Date(250 * (client.orca.f * (60 / client.clock.speed.value))).toISOString().substr(14, 5).replace(/:/g, '') - client.orca.writeBlock(origin ? origin.x : client.cursor.x, origin ? origin.y : client.cursor.y, [`${formatted}`]) + client.orca.writeBlock(origin ? origin.x : client.cursor.x, origin ? origin.y : client.cursor.y, `${formatted}`) }, // Themeing color: (p) => { @@ -56,11 +57,12 @@ function Commander (client) { find: (p) => { client.cursor.find(p.str) }, select: (p) => { client.cursor.select(p.x, p.y, p.w, p.h) }, inject: (p, origin) => { - const mod = client.source.cache[p._str + '.orca'] - if (!mod) { console.warn('Commander', 'Unknown mod: ' + p._str); return } - client.orca.writeBlock(origin ? origin.x : client.cursor.x, origin ? origin.y : client.cursor.y, mod.trim().split('\n')) + const block = client.source.cache[p._str + '.orca'] + if (!block) { console.warn('Commander', 'Unknown block: ' + p._str); return } + client.orca.writeBlock(origin ? origin.x : client.cursor.x, origin ? origin.y : client.cursor.y, block) + client.cursor.scaleTo(0,0) }, - write: (p) => { client.cursor.select(p._x, p._y, p._str.length); client.cursor.writeBlock([p._str.split('')]) } + write: (p) => { client.cursor.select(p._x, p._y, p._str.length); client.orca.writeBlock(p._str) } } // Make shorthands diff --git a/desktop/sources/scripts/core/orca.js b/desktop/sources/scripts/core/orca.js index 218088a..83a6f36 100644 --- a/desktop/sources/scripts/core/orca.js +++ b/desktop/sources/scripts/core/orca.js @@ -97,21 +97,22 @@ function Orca (library) { // Blocks this.getBlock = (x, y, w, h) => { - const block = [] + let lines = '' for (let _y = y; _y < y + h; _y++) { - const line = [] + let line = '' for (let _x = x; _x < x + w; _x++) { - line.push(this.glyphAt(_x, _y)) + line += this.glyphAt(_x, _y) } - block.push(line) + lines += line + '\n' } - return block + return lines } this.writeBlock = (x, y, block, overlap = false) => { - if (!block || block.length === 0) { return } + if (!block) { return } + const lines = block.split(/\r?\n/) let _y = y - for (const line of block) { + for (const line of lines) { let _x = x for (const y in line) { const glyph = line[y] @@ -190,7 +191,7 @@ function Orca (library) { // Tools - this.format = function () { + this.format = () => { const a = [] for (let y = 0; y < this.h; y++) { a.push(this.s.substr(y * this.w, this.w)) @@ -200,17 +201,22 @@ function Orca (library) { }, '') } - this.length = function () { + this.length = () => { return this.strip().length } - this.strip = function () { + this.strip = () => { return this.s.replace(/[^a-zA-Z0-9+]+/gi, '').trim() } - this.toString = function () { + this.toString = () => { return this.format().trim() } + this.toRect = (str = this.s) => { + const lines = str.trim().split(/\r?\n/) + return { x: lines[0].length, y: lines.length } + } + this.reset() } diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 3c85540..9e5234c 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -59,10 +59,11 @@ function Cursor (client) { this.drag = (x, y) => { if (isNaN(x) || isNaN(y)) { return } this.ins = false - const block = this.getBlock() + const block = this.selection() this.erase() this.move(x, y) - this.writeBlock(block) + client.orca.writeBlock(this.minX, this.minY, block) + client.history.record(client.orca.s) } this.reset = (pos = false) => { @@ -70,7 +71,7 @@ function Cursor (client) { this.ins = 0 } - this.read = function () { + this.read = () => { return client.orca.glyphAt(this.x, this.y) } @@ -115,27 +116,15 @@ function Cursor (client) { } this.comment = () => { - const block = this.getBlock() - for (const val of block) { - val[0] = val[0] === '#' ? '.' : '#' - val[val.length - 1] = val[val.length - 1] === '#' ? '.' : '#' - } - this.writeBlock(block) - } - - // Block - - this.getBlock = () => { - const rect = this.toRect() - return client.orca.getBlock(rect.x, rect.y, rect.w, rect.h) - } - - this.writeBlock = (block, overlap = false) => { - client.orca.writeBlock(this.minX, this.minY, block, overlap) + const block = this.selection() + const lines = block.trim().split(/\r?\n/) + const char = block.substr(0, 1) === '#' ? '.' : '#' + const res = lines.map((line) => { return `${char}${line.substr(1, line.length - 2)}${char}` }).join('\n') + client.orca.writeBlock(this.minX, this.minY, res) client.history.record(client.orca.s) } - this.toRect = function () { + this.toRect = () => { return { x: this.minX, y: this.minY, @@ -144,14 +133,14 @@ function Cursor (client) { } } - this.calculateBounds = function () { + this.calculateBounds = () => { this.minX = this.x < this.x + this.w ? this.x : this.x + this.w this.minY = this.y < this.y + this.h ? this.y : this.y + this.h this.maxX = this.x > this.x + this.w ? this.x : this.x + this.w this.maxY = this.y > this.y + this.h ? this.y : this.y + this.h } - this.selected = function (x, y) { + this.selected = (x, y) => { return ( x >= this.minX && x <= this.maxX && @@ -160,6 +149,10 @@ function Cursor (client) { ) } + this.selection = (rect = this.toRect()) => { + return client.orca.getBlock(rect.x, rect.y, rect.w, rect.h) + } + this.mouseFrom = null this.onMouseDown = (e) => { @@ -204,13 +197,7 @@ function Cursor (client) { } this.onCopy = (e) => { - const block = this.getBlock() - var rows = [] - for (var i = 0; i < block.length; i++) { - rows.push(block[i].join('')) - } - const content = rows.join('\n').trim() - e.clipboardData.setData('text/plain', content) + e.clipboardData.setData('text/plain', this.selection()) e.preventDefault() } @@ -221,8 +208,9 @@ function Cursor (client) { this.onPaste = (e) => { const data = e.clipboardData.getData('text/plain').trim() - this.writeBlock(data.split(/\r?\n/), this.ins) - this.scaleTo(data.split('\n')[0].length - 1, data.split('\n').length - 1) + client.orca.writeBlock(this.minX, this.minY, data, this.ins) + client.history.record(client.orca.s) + this.scaleTo(data.split(/\r?\n/)[0].length - 1, data.split(/\r?\n/).length - 1) e.preventDefault() } @@ -1,4 +1,4 @@ -// 161 +// 162 const assets = [ './', |