"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MouseSelectAppObject = void 0;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MouseInput_1 = require("../../MouseInput");
const ZSpaceEntity_1 = require("../../zSpace/Entities/ZSpaceEntity");
const SelectAppObjectUC_1 = require("../UC/SelectAppObjectUC");
class MouseSelectAppObject extends core_1.AppObjectController {
    constructor(appObject) {
        super(appObject, MouseSelectAppObject.type);
        this.zSpaceEntity = undefined;
        this.allow = (e) => {
            return true;
        };
        this.onClick = (e) => {
            if (!this.selectUC) {
                return;
            }
            if (e.button !== 0) {
                return;
            }
            if (this.zSpaceEntity && this.zSpaceEntity.emulate)
                return;
            if (!this.allow(e))
                return;
            const ray = (0, Babylon_1.pixelToSceneRay)(e.position, this.appObjects);
            this.selectUC.trySelectAppObject(ray);
        };
        this.zSpaceEntity = ZSpaceEntity_1.ZSpaceEntity.get(this.appObjects);
        this.selectUC = appObject.getComponent(SelectAppObjectUC_1.SelectAppObjectUC.type);
        if (!this.selectUC) {
            console.warn("MouseSelect has been added to an App Object that does not have a SelectAppObjectUC. Add a SelectAppObjectUC before adding the Controller.");
            return;
        }
        const mouseInput = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
exports.MouseSelectAppObject = MouseSelectAppObject;
MouseSelectAppObject.type = "MouseSelectAppObject";
//# sourceMappingURL=MouseSelectAppObject.js.map