Improved workshop example
This commit is contained in:
parent
f6089748ea
commit
e3234195e7
@ -202,14 +202,9 @@ We can define a function that triggers when the `mouse-down` event is detected,
|
|||||||
; define the function
|
; define the function
|
||||||
(defn draw-rect
|
(defn draw-rect
|
||||||
(e)
|
(e)
|
||||||
(
|
(fill e "red"))
|
||||||
(clear)
|
|
||||||
(fill
|
|
||||||
(rect
|
|
||||||
(of e :x)
|
|
||||||
(of e :y) 100 100) "red")))
|
|
||||||
; use the function
|
; 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).
|
For more examples of functions, see the [examples](https://github.com/hundredrabbits/Ronin/tree/master/examples).
|
||||||
|
@ -109,15 +109,18 @@ function Commander (ronin) {
|
|||||||
this.cache = this._input.value
|
this.cache = this._input.value
|
||||||
|
|
||||||
this.capture = function () {
|
this.capture = function () {
|
||||||
|
if (this._input.value.indexOf('$') < 1) { return }
|
||||||
console.log('capture')
|
console.log('capture')
|
||||||
this.cache = this._input.value
|
this.cache = this._input.value
|
||||||
}
|
}
|
||||||
|
|
||||||
this.injectPath = function (path) {
|
this.injectPath = function (path) {
|
||||||
|
if (this._input.value.indexOf('$') < 1) { return }
|
||||||
this._input.value = this._input.value.replace('$path', `"${path}"`)
|
this._input.value = this._input.value.replace('$path', `"${path}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.commit = function (shape) {
|
this.commit = function (shape) {
|
||||||
|
if (this._input.value.indexOf('$') < 1) { return }
|
||||||
console.log('inject')
|
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})`)
|
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})`)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ function Ronin () {
|
|||||||
|
|
||||||
this.log = function (...msg) {
|
this.log = function (...msg) {
|
||||||
this.commander.setStatus(msg.reduce((acc, val) => {
|
this.commander.setStatus(msg.reduce((acc, val) => {
|
||||||
return acc + JSON.stringify(val).replace(/\"/g,'').trim() + ' '
|
return acc + JSON.stringify(val).replace(/\"/g, '').trim() + ' '
|
||||||
}, ''))
|
}, ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,12 +100,13 @@ function Ronin () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.onMouseUp = (e, id = 'mouse-up') => {
|
this.onMouseUp = (e, id = 'mouse-up') => {
|
||||||
this.mouseTouch = null
|
|
||||||
const shape = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY }, id)
|
const shape = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY }, id)
|
||||||
|
this.mouseTouch = null
|
||||||
if (this.bindings[id]) {
|
if (this.bindings[id]) {
|
||||||
this.bindings[id](shape)
|
this.bindings[id](shape)
|
||||||
}
|
}
|
||||||
this.surface.clearGuide()
|
this.surface.clearGuide()
|
||||||
|
console.log(this.bindings)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.makeMouseOffset = (pos, type) => {
|
this.makeMouseOffset = (pos, type) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user