Added files fn

This commit is contained in:
neauoire
2020-05-19 07:02:15 +09:00
parent 660180d6b8
commit da839efa8f
4 changed files with 36 additions and 20 deletions

View File

@@ -593,15 +593,7 @@ function Client () {
this.onMouseOut = (e) => {
this.mouseOrigin = null
}
this.onDrag = (e) => {
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
}
this.onDrop = (e) => {
e.preventDefault()
e.stopPropagation()
const file = e.dataTransfer.files[0]
this.parseFile = (file) => {
if (file.name.indexOf('.lisp') > -1) {
this.source.read(file, this.whenOpen)
this.log('Loaded ' + file.name)
@@ -617,6 +609,18 @@ function Client () {
console.warn('Unknown format', file)
}
}
this.onDrag = (e) => {
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
}
this.onDrop = (e) => {
e.preventDefault()
e.stopPropagation()
for (const file of e.dataTransfer.files) {
this.parseFile(file)
}
}
this.cache = {
data: {},
set: (key, content) => {
@@ -900,6 +904,9 @@ function Library (client) {
const type = `image/${format === 'jpeg' || format === 'jpg' ? 'jpeg' : 'png'}`
client.source.write('ronin', format, client.surface.el.toDataURL(type, quality), type)
}
this.files = () => {
return Object.keys(client.cache.data)
}
this.pos = (x = 0, y = 0) => { // Returns a position shape.
return { x, y }
}