diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 88bda0e..b774509 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -118,26 +118,28 @@ function Commander (ronin) { this._input.value = this._input.value.replace('$path', `"${path}"`) } - this.commit = function (shape) { + this.commit = function (shape, end = false) { if (this.cache.indexOf('$') < 0) { return } const segs = this.cache.split('$') const seg = segs[1] const words = seg.split(' ') const word = words[0] - if (word === 'rect' && shape.rect) { + if (word.substr(0, 4) === 'rect' && shape.rect) { const rect = shape.rect this._input.value = this.cache.replace('$rect', `(rect ${rect.x} ${rect.y} ${rect.w} ${rect.h})`) - } else if (word === 'pos' && shape.pos) { + } else if (word.substr(0, 3) === 'pos' && shape.pos) { const pos = shape.pos this._input.value = this.cache.replace('$pos', `(pos ${pos.x} ${pos.y})`) - } else if (word === 'line' && shape.line) { + } else if (word.substr(0, 4) === 'line' && shape.line) { const line = shape.line this._input.value = this.cache.replace('$line', `(line ${line.a.x} ${line.a.y} ${line.b.x} ${line.b.y})`) - } else if (word === 'circle' && shape.circle) { + } else if (word.substr(0, 6) === 'circle' && shape.circle) { const circle = shape.circle - console.log(circle) this._input.value = this.cache.replace('$circle', `(circle ${circle.cx} ${circle.cy} ${circle.r})`) } + if (end === true) { + this.cache = this._input.value + } } // Display diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index db384a9..51e094b 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -96,7 +96,7 @@ function Ronin () { this.bindings[id](shape) } if (this.mouseOrigin) { - this.commander.commit(shape) + this.commander.commit(shape, false) this.surface.drawGuide(shape) } } @@ -107,6 +107,9 @@ function Ronin () { if (this.bindings[id]) { this.bindings[id](shape) } + if (this.mouseOrigin) { + this.commander.commit(shape, true) + } this.mouseOrigin = null this.surface.clearGuide() } diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 7ca5e34..6ac6fce 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -166,12 +166,13 @@ function Surface (ronin) { this.drawGuide = function (shape, context = this.guide) { this.clearGuide() - this.stroke(shape.rect, 3, 'black', context) - this.stroke(shape.line, 3, 'black', context) - this.stroke(shape.circle, 3, 'black', context) - this.stroke(shape.rect, 1.5, 'white', context) - this.stroke(shape.line, 1.5, 'white', context) - this.stroke(shape.circle, 1.5, 'white', context) + if (!shape) { return } + this.stroke(shape.rect || shape, 3, 'black', context) + if (shape.line) { this.stroke(shape.line, 3, 'black', context) } + if (shape.circle) { this.stroke(shape.circle, 3, 'black', context) } + this.stroke(shape.rect || shape, 1.5, 'white', context) + if (shape.line) { this.stroke(shape.line, 1.5, 'white', context) } + if (shape.circle) { this.stroke(shape.circle, 1.5, 'white', context) } } this.clone = function (a, b) {