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) {
if (!data) { return }
if (!dotgrid.tool.layers[data.layer]) { return }
dotgrid.tool.index = data.layer
dotgrid.tool.addSegment(data.type, [data.from, data.to])
dotgrid.tool.addSegment(data.type, [data.from, data.to], data.layer)
}
function draw () {

View File

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