"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CenterSceneRootOnPixelPickUC = void 0;
exports.makeCenterSceneRootOnPixelPickUC = makeCenterSceneRootOnPixelPickUC;
exports.centerOnPixel = centerOnPixel;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Dispatcher_1 = require("../../Dispatcher");
const SceneRootEntity_1 = require("../Entities/SceneRootEntity");
class CenterSceneRootOnPixelPickUC extends core_1.AppObjectUC {
}
exports.CenterSceneRootOnPixelPickUC = CenterSceneRootOnPixelPickUC;
CenterSceneRootOnPixelPickUC.type = "CenterSceneRootOnPixelPickUC";
CenterSceneRootOnPixelPickUC.get = (appObjects) => (0, core_1.getSingletonComponent)(CenterSceneRootOnPixelPickUC.type, appObjects);
function makeCenterSceneRootOnPixelPickUC(appObject) {
    return new CenterSceneRootOnPixelPickImp(appObject);
}
class CenterSceneRootOnPixelPickImp extends CenterSceneRootOnPixelPickUC {
    constructor(appObject) {
        super(appObject, CenterSceneRootOnPixelPickUC.type);
        this.durationMS = 500;
        this.easeFn = core_1.cubicInOut;
        this.centerOnPixel = (pixel) => {
            if (!this.sceneRoot)
                return;
            const scenePick = (0, Babylon_1.scenePixelPick)(pixel, this.appObjects);
            if (!scenePick?.worldPickPoint)
                return;
            this.sceneRoot.centerOnPoint(scenePick.worldPickPoint, this.durationMS, this.easeFn, () => this.onCenterCompleted());
        };
        this.onCenterCompleted = () => {
            (0, Dispatcher_1.dispatchStateChange)(this.appObjects);
        };
        this.sceneRoot = appObject.getComponent(SceneRootEntity_1.SceneRootEntity.type);
        if (!this.sceneRoot) {
            this.warn("BumpSceneRootScaleAboutPixelPointImp UC has been added to an App Object that does not have a SceneRoot Entity");
            return;
        }
    }
}
function centerOnPixel(pixel, appObjects) {
    const uc = CenterSceneRootOnPixelPickUC.get(appObjects);
    if (!uc) {
        appObjects.submitWarning("centerOnPixel", "Unable to find CenterSceneRootOnPixelPickUC");
        return;
    }
    return uc.centerOnPixel(pixel);
}
//# sourceMappingURL=CenterSceneRootOnPixelPick.js.map