diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 8e0340c..9474f27 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -46,7 +46,7 @@ ronin.controller.add("default","View","Toggle Commander",() => { ronin.commander.toggle(); },"CmdOrCtrl+K"); ronin.controller.add("default","Project","Run",() => { ronin.commander.run(); },"CmdOrCtrl+R"); ronin.controller.add("default","Project","Reload Run",() => { ronin.source.revert(); ronin.commander.run(); },"CmdOrCtrl+Shift+R"); - ronin.controller.add("default","Project", "Toggle Animation (experimental)",() => { ronin.commander.toggleAnimation(); },"CmdOrCtrl+Shift+T"); + ronin.controller.add("default","Project", "Toggle Animation (experimental)",() => { ronin.animate(!ronin.always); },"CmdOrCtrl+Shift+T"); ronin.controller.add("default","Theme","Open Theme",() => { ronin.theme.open() },"CmdOrCtrl+Shift+O") ronin.controller.add("default","Theme","Reset Theme",() => { ronin.theme.reset() },"CmdOrCtrl+Shift+Backspace") ronin.controller.addSpacer('default', 'Theme', 'Download') diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 74a520d..8169562 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -4,7 +4,6 @@ function Commander (ronin) { this._input = document.createElement('textarea') this._status = document.createElement('div') this._status.id = 'status' - this.isAnimated = false this.install = function (host) { this.el.appendChild(this._input) @@ -23,16 +22,10 @@ function Commander (ronin) { this.run = (txt = this._input.value) => { if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return } - !this.isAnimated && console.log('========') ronin.surface.maximize() const inter = new Lisp(txt, ronin.library) inter.toPixels() - this.isAnimated && requestAnimationFrame(() => this.run(txt)) - } - - this.toggleAnimation = () => { - this.isAnimated = !this.isAnimated - this.run(this._input.value) + ronin.always && requestAnimationFrame(() => this.run(txt)) } this.load = function (txt) { diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 5c78dad..c04f194 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -82,14 +82,14 @@ function Library (ronin) { this._filter = (fn, arr) => { return arr.filter(fn) } - this.filter= (fn, arr) => { - const list = Array.from(arr); - return Promise.all(list.map((element, index) => fn(element, index, list))) - .then(result => { - return list.filter((_, index) => { - return result[index]; - }); - }); + this.filter = (fn, arr) => { + const list = Array.from(arr) + return Promise.all(list.map((element, index) => fn(element, index, list))) + .then(result => { + return list.filter((_, index) => { + return result[index] + }) + }) } this.reduce = (fn, arr, acc = 0) => { @@ -193,7 +193,16 @@ function Library (ronin) { return rect } - // + this.get = (item, key) => { + return item[key] + } + + this.set = (item, key, val) => { + item[key] = val + return item[key] + } + + // TODO: Should remove (of) for (get)? this.of = (h, ...keys) => { return keys.reduce((acc, key) => { @@ -315,9 +324,11 @@ function Library (ronin) { } // Livecoding - this.time = Date.now // javascript interop this.js = window + + // Client + this.ronin = ronin } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index b0b58cd..4db3261 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -21,6 +21,10 @@ function Ronin () { this.surface = new Surface(this) this.library = new Library(this) + // Parameters + + this.always = false + this.install = function (host = document.body) { this._wrapper = document.createElement('div') this._wrapper.id = 'wrapper' @@ -56,6 +60,11 @@ function Ronin () { } + this.animate = (b = true) => { + this.always = b + this.commander.run() + } + // Zoom this.modZoom = function (mod = 0, set = false) { diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 8c1086d..efaa8a1 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -123,11 +123,11 @@ function Surface (ronin) { this.draw = function (img, rect = this.getFrame()) { return new Promise(resolve => { img.onload = () => { - ronin.log(`Draw ${img.width}x${img.height}`) - this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) // no strect: img.height * (rect.w / img.width) - resolve() - } - }); + ronin.log(`Draw ${img.width}x${img.height}`) + this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) // no strect: img.height * (rect.w / img.width) + resolve() + } + }) } this.crop = function (rect) { diff --git a/examples/animation.lisp b/examples/animate.lisp similarity index 73% rename from examples/animation.lisp rename to examples/animate.lisp index e8ccf30..b3b4690 100644 --- a/examples/animation.lisp +++ b/examples/animate.lisp @@ -1,7 +1,7 @@ -; animation -; click Project > Toggle Animation +; animate ( +(ronin animate) (def t (sin (div (time) 100))) (def pos (add 200 (mul 30 t)))