22 lines
637 B
TypeScript
22 lines
637 B
TypeScript
import { commandIds } from "@commands/ids";
|
|
import type { Dispatch } from "@commands/dispatcher";
|
|
import type { KeybindEvent } from "./keyboard";
|
|
|
|
const toolKeybinds = {
|
|
b: "brush",
|
|
e: "eraser",
|
|
w: "magicWand",
|
|
p: "pan",
|
|
s: "select",
|
|
} as const;
|
|
|
|
export function handleToolKey(options: { event: KeybindEvent; dispatch: Dispatch }): boolean {
|
|
if (options.event.altKey || options.event.ctrlKey || options.event.metaKey) return false;
|
|
|
|
const tool = toolKeybinds[options.event.key.toLowerCase() as keyof typeof toolKeybinds];
|
|
if (!tool) return false;
|
|
|
|
options.dispatch(commandIds.toolSetActive, { tool });
|
|
return true;
|
|
}
|