Improved workshop example

This commit is contained in:
Devine Lu Linvega 2019-07-26 07:56:02 +09:00
parent f6089748ea
commit e3234195e7
3 changed files with 9 additions and 10 deletions

View File

@ -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).

View File

@ -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})`)
}

View File

@ -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) => {