"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BumpSceneRootScaleAboutPixelPointUC = void 0;
exports.makeBumpSceneRootScaleAboutPixelPointUC = makeBumpSceneRootScaleAboutPixelPointUC;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Dispatcher_1 = require("../../Dispatcher");
const SceneRootEntity_1 = require("../Entities/SceneRootEntity");
class BumpSceneRootScaleAboutPixelPointUC extends core_1.AppObjectUC {
}
exports.BumpSceneRootScaleAboutPixelPointUC = BumpSceneRootScaleAboutPixelPointUC;
BumpSceneRootScaleAboutPixelPointUC.type = "BumpSceneRootScaleAboutPixelPoint";
BumpSceneRootScaleAboutPixelPointUC.get = (appObjects) => (0, core_1.getSingletonComponent)(BumpSceneRootScaleAboutPixelPointUC.type, appObjects);
function makeBumpSceneRootScaleAboutPixelPointUC(appObject) {
    return new BumpSceneRootScaleAboutPixelPointImp(appObject);
}
class BumpSceneRootScaleAboutPixelPointImp extends BumpSceneRootScaleAboutPixelPointUC {
    constructor(appObject) {
        super(appObject, BumpSceneRootScaleAboutPixelPointUC.type);
        this.sensitivity = 0.1;
        this.allow = () => {
            return true;
        };
        this.bump = (direction, pixelPosition) => {
            if (!this.sceneRoot)
                return;
            if (!this.allow())
                return;
            let bumpDirection = -1;
            if (direction === "IN") {
                bumpDirection = 1;
            }
            const currentScale = this.sceneRoot.scale;
            const scaleDelta = bumpDirection * this.sensitivity * currentScale;
            const pick = (0, Babylon_1.scenePixelPick)(pixelPosition, this.appObjects);
            const pickPoint = pick?.worldPickPoint ?? core_2.Vector3.Zero();
            this.sceneRoot.bumpScaleAboutPoint(scaleDelta, pickPoint);
            (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=BumpSceneRootScaleAboutPixelPoint.js.map