"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolHotkeys = void 0;
const core_1 = require("@vived/core");
const KeyboardInput_1 = require("../../KeyboardInput");
const ToolRepository_1 = require("../Entities/ToolRepository");
class ToolHotkeys extends core_1.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_1.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 = KeyboardInput_1.KeyboardInputEntity.get(appObject.appObjectRepo);
        if (keyboardInput) {
            keyboardInput.registerController(this);
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
    }
}
exports.ToolHotkeys = ToolHotkeys;
ToolHotkeys.type = "ToolHotkeys";
//# sourceMappingURL=ToolHotkeys.js.map