"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZSpaceDisplayPM = exports.defaultZSpaceDisplayVM = void 0;
exports.makeZSpaceDisplayPM = makeZSpaceDisplayPM;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const ZSpaceDisplayEntity_1 = require("../Entities/ZSpaceDisplayEntity");
const ZSpaceEntity_1 = require("../Entities/ZSpaceEntity");
exports.defaultZSpaceDisplayVM = {
    pixelSize: core_2.Vector2.Zero(),
    show: false,
    worldSize: core_2.Vector2.Zero(),
};
class ZSpaceDisplayPM extends core_1.AppObjectPM {
}
exports.ZSpaceDisplayPM = ZSpaceDisplayPM;
ZSpaceDisplayPM.type = "ZSpaceDisplayPM";
ZSpaceDisplayPM.get = (appObjects) => (0, core_1.getSingletonComponent)(ZSpaceDisplayPM.type, appObjects);
function makeZSpaceDisplayPM(appObject) {
    return new ZSpaceDisplayPMImp(appObject);
}
class ZSpaceDisplayPMImp extends ZSpaceDisplayPM {
    get zSpaceDisplay() {
        return this.getCachedSingleton(ZSpaceDisplayEntity_1.ZSpaceDisplayEntity.type);
    }
    get zSpaceEntity() {
        return this.getCachedSingleton(ZSpaceEntity_1.ZSpaceEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.show === b.show &&
            core_2.Vector2.Equal(a.pixelSize, b.pixelSize) &&
            core_2.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