"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SceneRootEntity = void 0;
exports.makeSceneRootEntity = makeSceneRootEntity;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Transform3D_1 = require("../../Transform3D");
class SceneRootEntity extends core_1.AppObjectEntity {
}
exports.SceneRootEntity = SceneRootEntity;
SceneRootEntity.type = "SCENE_ROOT_ENTITY";
SceneRootEntity.get = (appObjects) => (0, core_1.getSingletonComponent)(SceneRootEntity.type, appObjects);
function makeSceneRootEntity(appObj) {
    return new SceneRootImp(appObj);
}
class SceneRootImp extends SceneRootEntity {
    get position() {
        return this.transform.localPosition;
    }
    set position(p) {
        this.transform.localPosition = p;
    }
    get rotation() {
        return this.transform.localRotation;
    }
    set rotation(r) {
        this.transform.localRotation = r;
    }
    get scale() {
        return this.transform.localScale.x;
    }
    set scale(s) {
        this.transform.localScale = new core_2.Vector3(s, s, s);
    }
    get defaultPosition() {
        return this._defaultPosition;
    }
    get defaultRotation() {
        return this._defaultRotation;
    }
    get defaultScale() {
        return this._defaultScale;
    }
    get minScale() {
        return this._minScale;
    }
    get maxScale() {
        return this._maxScale;
    }
    constructor(appObject) {
        super(appObject, SceneRootEntity.type);
        this._defaultPosition = core_2.Vector3.Zero();
        this._defaultRotation = core_2.Quaternion.Identity();
        this._defaultScale = 1;
        this._minScale = 0.01;
        this._maxScale = 10;
        this.applyDefaultData = (data) => {
            this._defaultPosition = core_2.Vector3.FromArray(data.position);
            this._defaultRotation = core_2.Quaternion.FromArray(data.rotation);
            this._defaultScale = data.scale;
            this._maxScale = data.maxScale;
            this._minScale = data.minScale;
        };
        this.centerOnPoint = (point, durationMS, easeFn, onCompleted) => {
            const finalPosition = core_2.Vector3.Subtract(this.transform.worldPosition, point);
            const lerpDTO = {
                durationMS,
                ease: easeFn,
                desiredPosition: finalPosition,
                onCompletedCallback: onCompleted,
            };
            this.transform.lerp(lerpDTO);
        };
        this.bumpScaleAboutPoint = (amount, worldPoint) => {
            const localPickOffset = this.transform.worldPointToLocal(worldPoint);
            const currentScale = this.transform.worldScale.x;
            let newScale = currentScale + amount;
            if (newScale < this.minScale) {
                newScale = this.minScale;
            }
            else if (newScale > this.maxScale) {
                newScale = this.maxScale;
            }
            this.transform.worldScale = new core_2.Vector3(newScale, newScale, newScale);
            const worldPickOffset = this.transform.localPointToWorld(localPickOffset);
            const bump = core_2.Vector3.Subtract(worldPoint, worldPickOffset);
            this.transform.worldPosition = core_2.Vector3.Add(bump, this.transform.worldPosition);
        };
        this.lerpToDefault = (durationMS, easeFn, onCompleted) => {
            const lerpDTO = {
                durationMS,
                ease: easeFn,
                desiredPosition: this.defaultPosition,
                desiredRotation: this.defaultRotation,
                desiredScale: new core_2.Vector3(this.defaultScale, this.defaultScale, this.defaultScale),
                onCompletedCallback: onCompleted,
            };
            this.transform.lerp(lerpDTO);
        };
        this.transform = Transform3D_1.Transform3D.addIfMissing(appObject);
        this.transform.addChangeObserver(this.notifyOnChange);
    }
}
//# sourceMappingURL=SceneRootEntity.js.map