From 160ef4a1589c056d855787828a62299559191094 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 14 Jul 2019 15:16:17 +0900 Subject: [PATCH] Added (folder ($path)) to library --- desktop/sources/scripts/commander.js | 3 ++- desktop/sources/scripts/library.js | 26 ++++++++++++++++++-------- desktop/sources/scripts/source.js | 4 ++-- desktop/sources/scripts/surface.js | 4 +--- examples/arrays.lisp | 3 +-- examples/load.lisp | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 000124a..0ace1ff 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -34,7 +34,8 @@ function Commander (ronin) { } this.setStatus = function (msg) { - this._status.textContent = `${msg.substr(0, 40)}` + if (!msg) { return } + this._status.textContent = `${(msg + '').substr(0, 40)}` } this.update = function () { diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index d75b601..2c0ad76 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -1,14 +1,20 @@ function Library (ronin) { - this.clear = (rect = this.select_all()) => { - } - - // IO - this.open = (path, w = 1, h = 1) => { ronin.surface.open(path, { w, h }) return path } + this.folder = (path = ronin.source.path) => { + const a = [] + if (path) { + const folder = ronin.source.folder(path) + if (fs.existsSync(folder)) { + return fs.readdirSync(folder) + } + } + return a + } + this.save = (path, type = 'jpg') => { console.log('save', path) // TODO: Save file @@ -74,6 +80,10 @@ function Library (ronin) { return arr.reduce(fn, acc) } + this.len = (item) => { + return item.length + } + this.first = (arr) => { return arr[0] } @@ -236,11 +246,11 @@ function Library (ronin) { a = a.toString() b = b.toString() } - if (a != b) { - console.warn('failed ' + name, a, b) + if (a !== b) { + console.warn('failed ' + name, a) } else { console.log('passed ' + name, a, b) } - return a == b + return a === b } } diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js index 206b6f5..39e7943 100644 --- a/desktop/sources/scripts/source.js +++ b/desktop/sources/scripts/source.js @@ -138,8 +138,8 @@ function Source (ronin) { return this.path ? path.basename(this.path, '.lisp') : null } - this.folder = function () { - return this.path ? path.dirname(this.path) : null + this.folder = function (p = this.path) { + return p ? path.dirname(p) : null } this.toString = function () { diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index e7e3e76..722c717 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -102,9 +102,7 @@ function Surface (ronin) { const img = new Image() img.src = path img.onload = () => { - const ratio = img.width / img.height - const scale = rect.w / img.width - this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * scale) + this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * (rect.w / img.width)) if (typeof callback === 'function') { callback() } diff --git a/examples/arrays.lisp b/examples/arrays.lisp index 2a71a15..e6c7db1 100644 --- a/examples/arrays.lisp +++ b/examples/arrays.lisp @@ -28,5 +28,4 @@ (add 50 (mul (sin a) 40)) a (add 20 (mul (cos a) 50))) 1 "red")) - (range 0 200 5))) -) \ No newline at end of file + (range 0 200 5))) \ No newline at end of file diff --git a/examples/load.lisp b/examples/load.lisp index 3c30d92..fa9c31e 100644 --- a/examples/load.lisp +++ b/examples/load.lisp @@ -1,5 +1,5 @@ ; load file ((clear) - (stroke (draw ($path) ($rect)) 1 "red") + (print (folder)) ) \ No newline at end of file