Polished previous bug fix

Now it's possible to use all non-resizable tool and even copy a locked layer to paste it on an unlocked one.
This commit is contained in:
Nicola 2021-12-12 22:50:21 +01:00
parent 1d9ef0f372
commit 62130ae90d
6 changed files with 16 additions and 6 deletions

View File

@ -59,7 +59,7 @@ const ToolManager = (() => {
else if (Input.isAltPressed()) { else if (Input.isAltPressed()) {
tools["eyedropper"].onStart(mousePos, mouseEvent.target); tools["eyedropper"].onStart(mousePos, mouseEvent.target);
} }
else if (!currFile.currentLayer.isLocked){ else if (!currFile.currentLayer.isLocked || !((Object.getPrototypeOf(currTool) instanceof DrawingTool))) {
currTool.onStart(mousePos, mouseEvent.target); currTool.onStart(mousePos, mouseEvent.target);
} }
break; break;
@ -91,7 +91,7 @@ const ToolManager = (() => {
else if (Input.isAltPressed()) { else if (Input.isAltPressed()) {
tools["eyedropper"].onDrag(mousePos, mouseEvent.target); tools["eyedropper"].onDrag(mousePos, mouseEvent.target);
} }
else if (!currFile.currentLayer.isLocked){ else if (!currFile.currentLayer.isLocked || !((Object.getPrototypeOf(currTool) instanceof DrawingTool))){
currTool.onDrag(mousePos, mouseEvent.target); currTool.onDrag(mousePos, mouseEvent.target);
} }
break; break;
@ -122,7 +122,7 @@ const ToolManager = (() => {
else if (Input.isAltPressed()) { else if (Input.isAltPressed()) {
tools["eyedropper"].onEnd(mousePos, mouseEvent.target); tools["eyedropper"].onEnd(mousePos, mouseEvent.target);
} }
else if (!currFile.currentLayer.isLocked){ else if (!currFile.currentLayer.isLocked || !((Object.getPrototypeOf(currTool) instanceof DrawingTool))) {
currTool.onEnd(mousePos); currTool.onEnd(mousePos);
} }
break; break;

View File

@ -29,6 +29,7 @@
//=include layers/PixelGrid.js //=include layers/PixelGrid.js
/** TOOLS **/ /** TOOLS **/
//=include tools/DrawingTool.js
//=include tools/ResizableTool.js //=include tools/ResizableTool.js
//=include tools/SelectionTool.js //=include tools/SelectionTool.js

5
js/tools/DrawingTool.js Normal file
View File

@ -0,0 +1,5 @@
class DrawingTool extends Tool {
constructor (name, options) {
super(name, options);
}
}

View File

@ -1,4 +1,4 @@
class FillTool extends Tool { class FillTool extends DrawingTool {
constructor(name, options, switchFunction) { constructor(name, options, switchFunction) {
super(name, options); super(name, options);

View File

@ -1,4 +1,4 @@
class MoveSelectionTool extends Tool { class MoveSelectionTool extends DrawingTool {
currSelection = undefined; currSelection = undefined;
selectionTool = undefined; selectionTool = undefined;
endTool = undefined; endTool = undefined;
@ -25,6 +25,8 @@ class MoveSelectionTool extends Tool {
} }
cutSelection() { cutSelection() {
if (currFile.currentLayer.isLocked)
return;
this.cutting = true; this.cutting = true;
this.lastCopiedSelection = this.currSelection; this.lastCopiedSelection = this.currSelection;
this.endSelection(); this.endSelection();
@ -35,6 +37,8 @@ class MoveSelectionTool extends Tool {
} }
pasteSelection() { pasteSelection() {
if (currFile.currentLayer.isLocked)
return;
if (this.lastCopiedSelection === undefined) if (this.lastCopiedSelection === undefined)
return; return;
// Finish the current selection and start a new one with the same data // Finish the current selection and start a new one with the same data

View File

@ -1,4 +1,4 @@
class ResizableTool extends Tool { class ResizableTool extends DrawingTool {
startResizePos = undefined; startResizePos = undefined;
currSize = 1; currSize = 1;
prevSize = 1; prevSize = 1;