diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index ccf9f1f..a4e8aec 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -10,8 +10,8 @@ function Commander (ronin) { this.el.appendChild(this._input) this.el.appendChild(this._status) host.appendChild(this.el) - this._input.addEventListener('input', this.onInput) + this.docs.install() } this.start = function () { @@ -162,4 +162,27 @@ function Commander (ronin) { this.hide() } } + + // Docs micro-module + + this.docs = { + path: 'sources/scripts/library.js', + load: function () { + const fs = require('fs') + if (!fs.existsSync(this.path)) { console.warn('Docs', 'File does not exist: ' + this.path); return } + const lines = fs.readFileSync(this.path, 'utf8').split('\n').filter((line) => { return line.substr(0, 7) === ' this.' }) + return lines.map((line) => { return line.trim().substr(5, line.length - 5).trim() }) + }, + install: function (payload = this.load()) { + const dict = {} + for (const id in payload) { + const parts = payload[id].split(' = ') + const name = parts[0] + const params = parts[1].match(/\(([^)]+)\)/) + if (!params) { console.warn('Docs', 'Misformatted ' + name); continue } + dict[name] = params[1].split(',').map((word) => { return word.trim() }) + } + console.log(dict) + } + } } diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 1ea70c6..0cdc753 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -1,5 +1,4 @@ function Library (ronin) { - console.log(ronin) this.open = async (path) => { return ronin.surface.open(path) } @@ -215,7 +214,7 @@ function Library (ronin) { // Gradients - this.gradient = ([x1,y1,x2,y2], colors=['white','black']) => { + this.gradient = ([x1, y1, x2, y2], colors = ['white', 'black']) => { return ronin.surface.linearGradient(x1, y1, x2, y2, colors) } @@ -337,5 +336,4 @@ function Library (ronin) { // javascript interop this.js = window - } diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index e7de660..a1bd5eb 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -61,11 +61,11 @@ function Surface (ronin) { context.closePath() } - this.linearGradient = function(x1, y1, x2, y2, colors, context = this.context) { + this.linearGradient = function (x1, y1, x2, y2, colors, context = this.context) { const gradient = context.createLinearGradient(x1, y1, x2, y2) - const step = 1/(colors.length - 1) - colors.forEach((color,i) => { - gradient.addColorStop(i*step, color) + const step = 1 / (colors.length - 1) + colors.forEach((color, i) => { + gradient.addColorStop(i * step, color) }) return gradient }