"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MouseLandmark = void 0;
exports.makeMouseLandmark = makeMouseLandmark;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MouseInput_1 = require("../../MouseInput");
const TryAddNewLandmarkUC_1 = require("../UseCases/TryAddNewLandmarkUC");
const TryPreviewLandmarkUC_1 = require("../UseCases/TryPreviewLandmarkUC");
class MouseLandmark extends core_1.AppObjectController {
    constructor() {
        super(...arguments);
        this.addingLandmark = false;
        this.pressed = false;
    }
}
exports.MouseLandmark = MouseLandmark;
MouseLandmark.type = "Mouse_Landmark_Controller";
function makeMouseLandmark(appObject) {
    return new MouseLandmarkImp(appObject);
}
class MouseLandmarkImp extends MouseLandmark {
    get tryPreviewLandmarkUc() {
        return this.getCachedSingleton(TryPreviewLandmarkUC_1.TryPreviewLandmarkUC.type);
    }
    get tryAddLandmarkUc() {
        return this.getCachedSingleton(TryAddNewLandmarkUC_1.TryAddNewLandmarkUC.type);
    }
    constructor(appObject) {
        super(appObject, MouseLandmark.type);
        this.addingLandmark = false;
        this.pressed = false;
        this.allow = (e) => {
            return true;
        };
        this.onMove = (e) => {
            if (!this.allow(e))
                return;
            if (!this.tryPreviewLandmarkUc) {
                return;
            }
            const ray = (0, Babylon_1.pixelToSceneRay)(e.position, this.appObjects);
            this.tryPreviewLandmarkUc.tryPreviewLandmark(ray, this.pressed);
        };
        this.onDown = (e) => {
            this.addingLandmark = false;
            if (e.button !== 0)
                return;
            if (!this.allow(e))
                return;
            if (!this.tryPreviewLandmarkUc) {
                return;
            }
            const ray = (0, Babylon_1.pixelToSceneRay)(e.position, this.appObjects);
            const pressed = true;
            this.tryPreviewLandmarkUc.tryPreviewLandmark(ray, pressed);
            this.addingLandmark = true;
            this.pressed = true;
        };
        this.onUp = (e) => {
            if (!this.allow(e))
                return;
            if (!this.addingLandmark)
                return;
            if (!this.tryAddLandmarkUc)
                return;
            if (!this.tryPreviewLandmarkUc)
                return;
            const ray = (0, Babylon_1.pixelToSceneRay)(e.position, this.appObjects);
            this.tryAddLandmarkUc.addFromRay(ray);
            this.tryPreviewLandmarkUc.hidePreview();
            this.addingLandmark = false;
            this.pressed = false;
        };
        const mouseInput = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
//# sourceMappingURL=MouseLandmark.js.map