import { AppObjectEntity, getSingletonComponent, } from "@vived/core";
import { Quaternion, Vector3 } from "@vived/core";
import { Transform3D } from "../../Transform3D";
export class SceneRootEntity extends AppObjectEntity {
}
SceneRootEntity.type = "SCENE_ROOT_ENTITY";
SceneRootEntity.get = (appObjects) => getSingletonComponent(SceneRootEntity.type, appObjects);
export 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 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 = Vector3.Zero();
        this._defaultRotation = Quaternion.Identity();
        this._defaultScale = 1;
        this._minScale = 0.01;
        this._maxScale = 10;
        this.applyDefaultData = (data) => {
            this._defaultPosition = Vector3.FromArray(data.position);
            this._defaultRotation = Quaternion.FromArray(data.rotation);
            this._defaultScale = data.scale;
            this._maxScale = data.maxScale;
            this._minScale = data.minScale;
        };
        this.centerOnPoint = (point, durationMS, easeFn, onCompleted) => {
            const finalPosition = 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 Vector3(newScale, newScale, newScale);
            const worldPickOffset = this.transform.localPointToWorld(localPickOffset);
            const bump = Vector3.Subtract(worldPoint, worldPickOffset);
            this.transform.worldPosition = Vector3.Add(bump, this.transform.worldPosition);
        };
        this.lerpToDefault = (durationMS, easeFn, onCompleted) => {
            const lerpDTO = {
                durationMS,
                ease: easeFn,
                desiredPosition: this.defaultPosition,
                desiredRotation: this.defaultRotation,
                desiredScale: new Vector3(this.defaultScale, this.defaultScale, this.defaultScale),
                onCompletedCallback: onCompleted,
            };
            this.transform.lerp(lerpDTO);
        };
        this.transform = Transform3D.addIfMissing(appObject);
        this.transform.addChangeObserver(this.notifyOnChange);
    }
}
//# sourceMappingURL=SceneRootEntity.js.map