Don't switch layer on addSeg

This commit is contained in:
Devine Lu Linvega 2019-01-13 12:32:03 +12:00
parent 3392ab87d2
commit cc2fac6d4b
2 changed files with 8 additions and 9 deletions

View File

@ -24,8 +24,7 @@ function Listener (dotgrid) {
function operate (data) { function operate (data) {
if (!data) { return } if (!data) { return }
if (!dotgrid.tool.layers[data.layer]) { return } if (!dotgrid.tool.layers[data.layer]) { return }
dotgrid.tool.index = data.layer dotgrid.tool.addSegment(data.type, [data.from, data.to], data.layer)
dotgrid.tool.addSegment(data.type, [data.from, data.to])
} }
function draw () { function draw () {

View File

@ -153,12 +153,12 @@ function Tool (dotgrid) {
return null return null
} }
this.addSegment = function (type, vertices) { this.addSegment = function (type, vertices, index = this.index) {
let append_target = this.canAppend({ type: type, vertices: vertices }) let append_target = this.canAppend({ type: type, vertices: vertices })
if (append_target) { if (append_target) {
this.layer()[append_target].vertices = this.layer()[append_target].vertices.concat(vertices) this.layer(index)[append_target].vertices = this.layer(index)[append_target].vertices.concat(vertices)
} else { } else {
this.layer().push({ type: type, vertices: vertices }) this.layer(index).push({ type: type, vertices: vertices })
} }
} }
@ -346,11 +346,11 @@ function Tool (dotgrid) {
// Layers // Layers
this.layer = function () { this.layer = function (index = this.index) {
if (!this.layers[this.index]) { if (!this.layers[index]) {
this.layers[this.index] = [] this.layers[index] = []
} }
return this.layers[this.index] return this.layers[index]
} }
this.selectLayer = function (id) { this.selectLayer = function (id) {