import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { Vector2 } from "@vived/core";
import { ZSpaceDisplayEntity } from "../Entities/ZSpaceDisplayEntity";
import { ZSpaceEntity } from "../Entities/ZSpaceEntity";
export const defaultZSpaceDisplayVM = {
    pixelSize: Vector2.Zero(),
    show: false,
    worldSize: Vector2.Zero(),
};
export class ZSpaceDisplayPM extends AppObjectPM {
}
ZSpaceDisplayPM.type = "ZSpaceDisplayPM";
ZSpaceDisplayPM.get = (appObjects) => getSingletonComponent(ZSpaceDisplayPM.type, appObjects);
export function makeZSpaceDisplayPM(appObject) {
    return new ZSpaceDisplayPMImp(appObject);
}
class ZSpaceDisplayPMImp extends ZSpaceDisplayPM {
    get zSpaceDisplay() {
        return this.getCachedSingleton(ZSpaceDisplayEntity.type);
    }
    get zSpaceEntity() {
        return this.getCachedSingleton(ZSpaceEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.show === b.show &&
            Vector2.Equal(a.pixelSize, b.pixelSize) &&
            Vector2.Equal(a.worldSize, b.worldSize)) {
            return true;
        }
        else {
            return false;
        }
    }
    constructor(appObject) {
        super(appObject, ZSpaceDisplayPM.type);
        this.onZSpaceChange = () => {
            if (!this.zSpaceDisplay)
                return;
            const show = this.zSpaceEntity?.enabled ?? false;
            const vm = {
                show,
                pixelSize: this.zSpaceDisplay.displaySizePixels,
                worldSize: this.zSpaceDisplay.displaySizeMeters,
            };
            this.doUpdateView(vm);
        };
        this.zSpaceDisplay?.addChangeObserver(this.onZSpaceChange);
        this.zSpaceEntity?.addChangeObserver(this.onZSpaceChange);
        this.onZSpaceChange();
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ZSpaceDisplayPM.js.map