#178 : switch tool mode with key shortcuts in zone editor
This commit is contained in:
parent
95d322a63c
commit
9b474909b3
@ -171,13 +171,26 @@ function handleClick(tool: string) {
|
|||||||
selectEraserOpen.value = tool === 'eraser' ? !selectEraserOpen.value : false
|
selectEraserOpen.value = tool === 'eraser' ? !selectEraserOpen.value : false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key bindings
|
function cycleToolMode(tool: 'pencil' | 'eraser') {
|
||||||
|
const modes = ['tile', 'object', 'teleport', 'blocking tile'];
|
||||||
|
const currentMode = tool === 'pencil' ? zoneEditorStore.drawMode : zoneEditorStore.eraserMode;
|
||||||
|
const currentIndex = modes.indexOf(currentMode);
|
||||||
|
const nextIndex = (currentIndex + 1) % modes.length;
|
||||||
|
const nextMode = modes[nextIndex];
|
||||||
|
|
||||||
|
if (tool === 'pencil') {
|
||||||
|
setDrawMode(nextMode);
|
||||||
|
} else {
|
||||||
|
setEraserMode(nextMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initKeyShortcuts(event: KeyboardEvent) {
|
function initKeyShortcuts(event: KeyboardEvent) {
|
||||||
if (!zoneEditorStore.zone) return
|
if (!zoneEditorStore.zone) return
|
||||||
// prevent if focused on composables
|
// prevent if focused on composables
|
||||||
if (document.activeElement?.tagName === 'INPUT') return
|
if (document.activeElement?.tagName === 'INPUT') return
|
||||||
|
|
||||||
const keyActions: any = {
|
const keyActions: { [key: string]: string } = {
|
||||||
m: 'move',
|
m: 'move',
|
||||||
p: 'pencil',
|
p: 'pencil',
|
||||||
e: 'eraser',
|
e: 'eraser',
|
||||||
@ -186,7 +199,12 @@ function initKeyShortcuts(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keyActions.hasOwnProperty(event.key)) {
|
if (keyActions.hasOwnProperty(event.key)) {
|
||||||
handleClick(keyActions[event.key])
|
const tool = keyActions[event.key];
|
||||||
|
if ((tool === 'pencil' || tool === 'eraser') && zoneEditorStore.tool === tool) {
|
||||||
|
cycleToolMode(tool);
|
||||||
|
} else {
|
||||||
|
handleClick(tool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user