import { AppObjectController } from "@vived/core";
import { KeyboardInputEntity } from "../../KeyboardInput";
import { ToolRepository } from "../Entities/ToolRepository";
export class ToolHotkeys extends AppObjectController {
    constructor(appObject) {
        super(appObject, ToolHotkeys.type);
        this.onKeyDown = (e) => {
            if (!this.toolRepo)
                return;
            if (e.repeat)
                return;
            const currentKey = {
                keyCode: e.code,
                alt: e.altKey,
                control: e.ctrlKey,
                meta: e.metaKey,
                shift: e.shiftKey,
            };
            const tool = this.toolRepo.getToolForHotkey(currentKey);
            if (!tool || !tool.toolType)
                return;
            this.toolRepo.triggerTool(tool.toolType);
        };
        this.toolRepo = appObject.getComponent(ToolRepository.type);
        if (!this.toolRepo) {
            this.warn("Controller has been added to an App Object that does not have ToolRepository. Add one first.");
            return;
        }
        const keyboardInput = KeyboardInputEntity.get(appObject.appObjectRepo);
        if (keyboardInput) {
            keyboardInput.registerController(this);
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
    }
}
ToolHotkeys.type = "ToolHotkeys";
//# sourceMappingURL=ToolHotkeys.js.map