"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CanBeStuckPM = void 0;
exports.makeCanBeStuckPM = makeCanBeStuckPM;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Transform3D_1 = require("../Entities/Transform3D");
class CanBeStuckPM extends core_1.AppObjectPM {
    static getForID(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(CanBeStuckPM.type);
    }
}
exports.CanBeStuckPM = CanBeStuckPM;
CanBeStuckPM.type = "CanBeStuckPM";
function makeCanBeStuckPM(appObject) {
    return new CanBeStuckPMImp(appObject);
}
class CanBeStuckPMImp extends CanBeStuckPM {
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, CanBeStuckPM.type);
        this.onTransformChange = () => {
            if (!this.transform)
                return;
            const pos = this.transform.localPosition;
            const canBeStuck = !core_2.Vector3.Close(pos, core_2.Vector3.Zero());
            this.doUpdateView(canBeStuck);
        };
        this.dispose = () => {
            super.dispose();
            this.transform?.removeChangeObserver(this.onTransformChange);
            this.transform?.removeOnDisposeObserver(this.dispose);
        };
        this.transform = Transform3D_1.Transform3D.get(appObject);
        if (!this.transform) {
            this.warn("Unable to find Transform3D Entity");
            return;
        }
        else {
            this.transform.addChangeObserver(this.onTransformChange);
            this.transform.addOnDisposeObserver(this.dispose);
            this.onTransformChange();
        }
    }
}
//# sourceMappingURL=CanBeStuckPM.js.map