Added file load
This commit is contained in:
parent
ac94515355
commit
9757fcfb48
@ -40,7 +40,6 @@
|
||||
ronin.controller.addRole('default', 'Edit', 'delete')
|
||||
ronin.controller.addRole('default', 'Edit', 'selectall')
|
||||
|
||||
|
||||
ronin.controller.add("default","Project","Run",() => { ronin.commander.run(); },"CmdOrCtrl+R");
|
||||
|
||||
ronin.controller.commit();
|
||||
|
@ -11,17 +11,13 @@ function Commander (ronin) {
|
||||
host.appendChild(this.el)
|
||||
|
||||
this._input.addEventListener('input', this.onInput)
|
||||
|
||||
window.addEventListener('dragover', this.drag)
|
||||
window.addEventListener('drop', this.drop)
|
||||
}
|
||||
|
||||
this.start = function () {
|
||||
this._input.value = `
|
||||
(stroke (rect 15 15 120 80) 2 "red")
|
||||
(fill (rect 30 30 120 80) 2 "blue")
|
||||
(clear (rect 45 45 45 45))
|
||||
`.trim()
|
||||
|
||||
this._status.textContent = 'Idle, RUN(cmd+enter).'
|
||||
|
||||
this._input.focus()
|
||||
this.run()
|
||||
}
|
||||
@ -33,6 +29,11 @@ function Commander (ronin) {
|
||||
inter.toPixels()
|
||||
}
|
||||
|
||||
this.load = function (txt) {
|
||||
this._input.value = txt
|
||||
this.run()
|
||||
}
|
||||
|
||||
this.update = function () {
|
||||
|
||||
}
|
||||
@ -44,4 +45,24 @@ function Commander (ronin) {
|
||||
this.getQuery = function () {
|
||||
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
this.drag = function (e) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
e.dataTransfer.dropEffect = 'copy'
|
||||
}
|
||||
|
||||
this.drop = function (e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
const file = e.dataTransfer.files[0]
|
||||
if (!file || !file.name || file.name.indexOf('.lisp') < 0) { console.warn('File', 'Not a .lisp file.'); return }
|
||||
const reader = new FileReader()
|
||||
reader.onload = function (e) {
|
||||
ronin.commander.load(e.target.result)
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,22 @@ function Library (ronin) {
|
||||
this.clear = (rect = this.select_all()) => {
|
||||
}
|
||||
|
||||
// Rects
|
||||
|
||||
this.rect = (x, y, w, h) => {
|
||||
return { x, y, w, h }
|
||||
}
|
||||
|
||||
this.frame = () => {
|
||||
return { x: 0, y: 0, w: Math.floor(window.innerWidth / 2) - 15, h: Math.floor(window.innerHeight) - 30 }
|
||||
}
|
||||
|
||||
this.stroke = (rect, thickness, color) => {
|
||||
ronin.surface.stroke(rect, thickness, color)
|
||||
return rect
|
||||
}
|
||||
|
||||
this.fill = (rect, thickness, color) => {
|
||||
this.fill = (rect = this.frame(), thickness, color) => {
|
||||
ronin.surface.fill(rect, thickness, color)
|
||||
return rect
|
||||
}
|
||||
@ -20,8 +26,4 @@ function Library (ronin) {
|
||||
ronin.surface.clear(rect)
|
||||
return rect
|
||||
}
|
||||
|
||||
this.select_all = () => {
|
||||
ronin.surface.getRect()
|
||||
}
|
||||
}
|
||||
|
5
examples/test1.lisp
Normal file
5
examples/test1.lisp
Normal file
@ -0,0 +1,5 @@
|
||||
; test file
|
||||
|
||||
((stroke (rect 15 15 120 80) 2 "red")
|
||||
(fill (rect 30 30 120 80) 2 "blue")
|
||||
(clear (rect 45 45 45 45)))
|
Loading…
x
Reference in New Issue
Block a user