Added (folder ($path)) to library

This commit is contained in:
Devine Lu Linvega 2019-07-14 15:16:17 +09:00
parent e060b81e0b
commit 160ef4a158
6 changed files with 25 additions and 17 deletions

View File

@ -34,7 +34,8 @@ function Commander (ronin) {
} }
this.setStatus = function (msg) { this.setStatus = function (msg) {
this._status.textContent = `${msg.substr(0, 40)}` if (!msg) { return }
this._status.textContent = `${(msg + '').substr(0, 40)}`
} }
this.update = function () { this.update = function () {

View File

@ -1,14 +1,20 @@
function Library (ronin) { function Library (ronin) {
this.clear = (rect = this.select_all()) => {
}
// IO
this.open = (path, w = 1, h = 1) => { this.open = (path, w = 1, h = 1) => {
ronin.surface.open(path, { w, h }) ronin.surface.open(path, { w, h })
return path 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') => { this.save = (path, type = 'jpg') => {
console.log('save', path) console.log('save', path)
// TODO: Save file // TODO: Save file
@ -74,6 +80,10 @@ function Library (ronin) {
return arr.reduce(fn, acc) return arr.reduce(fn, acc)
} }
this.len = (item) => {
return item.length
}
this.first = (arr) => { this.first = (arr) => {
return arr[0] return arr[0]
} }
@ -236,11 +246,11 @@ function Library (ronin) {
a = a.toString() a = a.toString()
b = b.toString() b = b.toString()
} }
if (a != b) { if (a !== b) {
console.warn('failed ' + name, a, b) console.warn('failed ' + name, a)
} else { } else {
console.log('passed ' + name, a, b) console.log('passed ' + name, a, b)
} }
return a == b return a === b
} }
} }

View File

@ -138,8 +138,8 @@ function Source (ronin) {
return this.path ? path.basename(this.path, '.lisp') : null return this.path ? path.basename(this.path, '.lisp') : null
} }
this.folder = function () { this.folder = function (p = this.path) {
return this.path ? path.dirname(this.path) : null return p ? path.dirname(p) : null
} }
this.toString = function () { this.toString = function () {

View File

@ -102,9 +102,7 @@ function Surface (ronin) {
const img = new Image() const img = new Image()
img.src = path img.src = path
img.onload = () => { img.onload = () => {
const ratio = img.width / img.height this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * (rect.w / img.width))
const scale = rect.w / img.width
this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * scale)
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback() callback()
} }

View File

@ -29,4 +29,3 @@
a a
(add 20 (mul (cos a) 50))) 1 "red")) (add 20 (mul (cos a) 50))) 1 "red"))
(range 0 200 5))) (range 0 200 5)))
)

View File

@ -1,5 +1,5 @@
; load file ; load file
((clear) ((clear)
(stroke (draw ($path) ($rect)) 1 "red") (print (folder))
) )