"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FocusOnPixelUC = void 0;
exports.makeFocusOnPixelUC = makeFocusOnPixelUC;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Dispatcher_1 = require("../../Dispatcher");
const SceneRootEntity_1 = require("../Entities/SceneRootEntity");
class FocusOnPixelUC extends core_1.AppObjectUC {
}
exports.FocusOnPixelUC = FocusOnPixelUC;
FocusOnPixelUC.type = "FocusOnPixelUC";
FocusOnPixelUC.get = (appObjects) => (0, core_1.getSingletonComponent)(FocusOnPixelUC.type, appObjects);
function makeFocusOnPixelUC(appObject) {
    return new FocusOnPixelImp(appObject);
}
class FocusOnPixelImp extends FocusOnPixelUC {
    constructor(appObject) {
        super(appObject, FocusOnPixelUC.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) {
                this.sceneRoot.centerOnPoint(scenePick.worldPickPoint, this.durationMS, this.easeFn, () => this.onCenterCompleted());
            }
            else {
                this.sceneRoot.lerpToDefault(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;
        }
    }
}
//# sourceMappingURL=FocusOnPixel.js.map