diff options
author | Devine Lu Linvega <[email protected]> | 2019-04-17 17:41:50 +0900 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2019-04-17 17:41:50 +0900 |
commit | b1ede29786e3950d6ead2453eb9f66a43d8d5d37 (patch) | |
tree | fa8d2900e821a7b32b1c033a504db5452f6b486d | |
parent | 46b1dfdc06e496eb381523726c4f3d9decb0b2fb (diff) | |
download | Orca-b1ede29786e3950d6ead2453eb9f66a43d8d5d37.tar.gz Orca-b1ede29786e3950d6ead2453eb9f66a43d8d5d37.zip |
Inject patterns byname
-rw-r--r-- | desktop/sources/scripts/commander.js | 11 | ||||
-rw-r--r-- | desktop/sources/scripts/patterns.js | 80 | ||||
-rw-r--r-- | desktop/sources/scripts/source.js | 7 |
3 files changed, 48 insertions, 50 deletions
diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 7d91a1f..37d38c2 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -1,7 +1,8 @@ 'use strict' function Commander (terminal) { - this.patterns = require('./patterns') + const Patterns = require('./patterns') + this.patterns = new Patterns(terminal) this.isActive = false this.query = '' @@ -65,8 +66,8 @@ function Commander (terminal) { if (this.operations[cmd]) { this.operations[cmd](val) - } else if (this.patterns[msg]) { - this.inject(this.patterns[msg]) + } else if (this.patterns.find(msg)) { + this.inject(this.patterns.find(msg)) } else { console.warn(`Unknown message: ${msg}`) } @@ -83,8 +84,8 @@ function Commander (terminal) { } this.preview = function () { - if (!this.patterns[this.query]) { terminal.cursor.reset(); return } - const result = this.patterns[this.query].trim().split('\n') + if (!this.patterns.find(this.query)) { terminal.cursor.reset(); return } + const result = this.patterns.find(this.query).trim().split('\n') terminal.cursor.resize(result[0].length, result.length) } diff --git a/desktop/sources/scripts/patterns.js b/desktop/sources/scripts/patterns.js index c18493f..fe2a1a5 100644 --- a/desktop/sources/scripts/patterns.js +++ b/desktop/sources/scripts/patterns.js @@ -1,45 +1,39 @@ 'use strict' -const patterns = {} - -// Setters - -patterns['vion'] = ` -iV......oV......nV` - -patterns['vionvl'] = ` -iV......oV......nV......vV......lV.` - -// Readers - -patterns['kion'] = ` -3Kion -.:...` - -patterns['kionvl'] = ` -5Kionvl -.:.....` - -// Notes - -patterns['oct'] = ` -.7TCDEFGAB -..C.......` - -patterns['oct#'] = ` -.7Tcdefgab -..C.......` - -patterns['scale'] = ` -cTCcDdEFfGgAaB -.C............` - -patterns['ca44'] = ` -.C4 -A04` - -patterns['dy'] = ` -D8 -.Y` - -module.exports = patterns +const Patterns = function (terminal) { + const fs = require('fs') + + this.collection = {} + + // Writers + this.collection['vion'] = `iV......oV......nV` + this.collection['vionvl'] = `iV......oV......nV......vV......lV` + + // Readers + this.collection['kion'] = `3Kion\n.:...` + this.collection['kionvl'] = `5Kionvl\n.:.....` + + // Notes + this.collection['oct'] = `.7TCDEFGAB\n..C.......` + this.collection['oct#'] = `.7Tcdefgab\n..C.......` + this.collection['scale'] = `cTCcDdEFfGgAaB\n.C............` + this.collection['ca44'] = `.C4\nA04` + this.collection['dy'] = `D8\n.Y` + + this.find = function (name) { + // Basics + if (this.collection[name]) { + return this.collection[name] + } + // Dynamics + if (terminal.source.path) { + const path = terminal.source.folder() + '/' + name + '.orca' + if (fs.existsSync(path)) { + return fs.readFileSync(path, 'utf8') + } + } + return null + } +} + +module.exports = Patterns diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js index ae43c31..9eb571f 100644 --- a/desktop/sources/scripts/source.js +++ b/desktop/sources/scripts/source.js @@ -118,8 +118,11 @@ function Source (terminal) { // Etc this.name = function (path = this.path) { - const parts = this.path.replace(/\\/g, '/').split('/') - return parts[parts.length - 1].replace('.orca', '').trim() + return path ? path.substr(path.lastIndexOf('/') + 1).replace('.orca', '').trim() : null + } + + this.folder = function (path = this.path) { + return path ? path.substring(0, path.lastIndexOf('/')).trim() : null } this.toString = function () { |