Added (folder ($path)) to library
This commit is contained in:
parent
e060b81e0b
commit
160ef4a158
@ -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 () {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -28,5 +28,4 @@
|
||||
(add 50 (mul (sin a) 40))
|
||||
a
|
||||
(add 20 (mul (cos a) 50))) 1 "red"))
|
||||
(range 0 200 5)))
|
||||
)
|
||||
(range 0 200 5)))
|
@ -1,5 +1,5 @@
|
||||
; load file
|
||||
|
||||
((clear)
|
||||
(stroke (draw ($path) ($rect)) 1 "red")
|
||||
(print (folder))
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user