From e3234195e70001c8a36db06f7cd1a84534624961 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 26 Jul 2019 07:56:02 +0900 Subject: [PATCH] Improved workshop example --- WORKSHOP.md | 9 ++------- desktop/sources/scripts/commander.js | 3 +++ desktop/sources/scripts/ronin.js | 7 ++++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/WORKSHOP.md b/WORKSHOP.md index f72c329..8ef0dd8 100644 --- a/WORKSHOP.md +++ b/WORKSHOP.md @@ -202,14 +202,9 @@ We can define a function that triggers when the `mouse-down` event is detected, ; define the function (defn draw-rect (e) - ( - (clear) - (fill - (rect - (of e :x) - (of e :y) 100 100) "red"))) + (fill e "red")) ; use the function -(on "mouse-down" draw-rect) +(on "mouse-up" draw-rect) ``` For more examples of functions, see the [examples](https://github.com/hundredrabbits/Ronin/tree/master/examples). diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index d2781b2..957042c 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -109,15 +109,18 @@ function Commander (ronin) { this.cache = this._input.value this.capture = function () { + if (this._input.value.indexOf('$') < 1) { return } console.log('capture') this.cache = this._input.value } this.injectPath = function (path) { + if (this._input.value.indexOf('$') < 1) { return } this._input.value = this._input.value.replace('$path', `"${path}"`) } this.commit = function (shape) { + if (this._input.value.indexOf('$') < 1) { return } console.log('inject') this._input.value = this.cache.replace('$rect', `(rect ${shape.x} ${shape.y} ${shape.w} ${shape.h})`).replace('$pos', `(pos ${shape.x} ${shape.y})`).replace('$line', `(line ${shape.a.x} ${shape.a.y} ${shape.b.x} ${shape.b.y})`) } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 1671678..52a32ec 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -61,8 +61,8 @@ function Ronin () { } this.log = function (...msg) { - this.commander.setStatus(msg.reduce((acc, val) => { - return acc + JSON.stringify(val).replace(/\"/g,'').trim() + ' ' + this.commander.setStatus(msg.reduce((acc, val) => { + return acc + JSON.stringify(val).replace(/\"/g, '').trim() + ' ' }, '')) } @@ -100,12 +100,13 @@ function Ronin () { } this.onMouseUp = (e, id = 'mouse-up') => { - this.mouseTouch = null const shape = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY }, id) + this.mouseTouch = null if (this.bindings[id]) { this.bindings[id](shape) } this.surface.clearGuide() + console.log(this.bindings) } this.makeMouseOffset = (pos, type) => {