From cc2fac6d4b4fed349bc6ff40371c1c067fdfcdf9 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 13 Jan 2019 12:32:03 +1200 Subject: [PATCH] Don't switch layer on addSeg --- desktop/sources/scripts/listener.js | 3 +-- desktop/sources/scripts/tool.js | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/desktop/sources/scripts/listener.js b/desktop/sources/scripts/listener.js index 51a9771..b226f6f 100644 --- a/desktop/sources/scripts/listener.js +++ b/desktop/sources/scripts/listener.js @@ -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 () { diff --git a/desktop/sources/scripts/tool.js b/desktop/sources/scripts/tool.js index c29b5a0..22230f4 100644 --- a/desktop/sources/scripts/tool.js +++ b/desktop/sources/scripts/tool.js @@ -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) {