Add test for round-tripping expanded control effect families in serialization
This commit is contained in:
@@ -70,6 +70,103 @@ describe("control interaction link serialization", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("round-trips expanded control effect families", () => {
|
||||||
|
const audioAsset = {
|
||||||
|
id: "asset-audio-main",
|
||||||
|
kind: "audio" as const,
|
||||||
|
sourceName: "loop.ogg",
|
||||||
|
mimeType: "audio/ogg",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||||
|
byteLength: 1024,
|
||||||
|
metadata: {
|
||||||
|
kind: "audio" as const,
|
||||||
|
durationSeconds: 3,
|
||||||
|
channelCount: 2,
|
||||||
|
sampleRateHz: 48000,
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies AudioAssetRecord;
|
||||||
|
const modelAsset = {
|
||||||
|
id: "asset-model-main",
|
||||||
|
kind: "model" as const,
|
||||||
|
sourceName: "animated.glb",
|
||||||
|
mimeType: "model/gltf-binary",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-model-main"),
|
||||||
|
byteLength: 2048,
|
||||||
|
metadata: {
|
||||||
|
kind: "model" as const,
|
||||||
|
format: "glb" as const,
|
||||||
|
sceneName: null,
|
||||||
|
nodeCount: 1,
|
||||||
|
meshCount: 1,
|
||||||
|
materialNames: [],
|
||||||
|
textureNames: [],
|
||||||
|
animationNames: ["Idle"],
|
||||||
|
boundingBox: null,
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies ModelAssetRecord;
|
||||||
|
const triggerVolume = createTriggerVolumeEntity({
|
||||||
|
id: "entity-trigger-main"
|
||||||
|
});
|
||||||
|
const pointLight = createPointLightEntity({
|
||||||
|
id: "entity-point-light-main"
|
||||||
|
});
|
||||||
|
const soundEmitter = createSoundEmitterEntity({
|
||||||
|
id: "entity-sound-main",
|
||||||
|
audioAssetId: audioAsset.id
|
||||||
|
});
|
||||||
|
const modelInstance = createModelInstance({
|
||||||
|
id: "model-instance-main",
|
||||||
|
assetId: modelAsset.id
|
||||||
|
});
|
||||||
|
const document = {
|
||||||
|
...createEmptySceneDocument(),
|
||||||
|
assets: {
|
||||||
|
[audioAsset.id]: audioAsset,
|
||||||
|
[modelAsset.id]: modelAsset
|
||||||
|
},
|
||||||
|
modelInstances: {
|
||||||
|
[modelInstance.id]: modelInstance
|
||||||
|
},
|
||||||
|
entities: {
|
||||||
|
[triggerVolume.id]: triggerVolume,
|
||||||
|
[pointLight.id]: pointLight,
|
||||||
|
[soundEmitter.id]: soundEmitter
|
||||||
|
},
|
||||||
|
interactionLinks: {
|
||||||
|
"link-hide-model": createControlInteractionLink({
|
||||||
|
id: "link-hide-model",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
effect: createSetModelInstanceVisibleControlEffect({
|
||||||
|
target: createModelInstanceControlTargetRef(modelInstance.id),
|
||||||
|
visible: false
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
"link-sound-volume": createControlInteractionLink({
|
||||||
|
id: "link-sound-volume",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
effect: createSetSoundVolumeControlEffect({
|
||||||
|
target: createSoundEmitterControlTargetRef(soundEmitter.id),
|
||||||
|
volume: 0.25
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
"link-ambient-color": createControlInteractionLink({
|
||||||
|
id: "link-ambient-color",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
effect: createSetAmbientLightColorControlEffect({
|
||||||
|
target: createActiveSceneControlTargetRef(),
|
||||||
|
colorHex: "#112233"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(
|
||||||
|
document
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("migrates v44 documents without changing existing interaction links", () => {
|
it("migrates v44 documents without changing existing interaction links", () => {
|
||||||
const audioAsset = {
|
const audioAsset = {
|
||||||
id: "asset-audio-main",
|
id: "asset-audio-main",
|
||||||
@@ -120,4 +217,39 @@ describe("control interaction link serialization", () => {
|
|||||||
legacyDocument.interactionLinks
|
legacyDocument.interactionLinks
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("migrates v46 control interaction documents without rewriting effects", () => {
|
||||||
|
const triggerVolume = createTriggerVolumeEntity({
|
||||||
|
id: "entity-trigger-main"
|
||||||
|
});
|
||||||
|
const pointLight = createPointLightEntity({
|
||||||
|
id: "entity-point-light-main"
|
||||||
|
});
|
||||||
|
const legacyDocument = {
|
||||||
|
...createEmptySceneDocument(),
|
||||||
|
version: PROJECT_SCHEDULER_FOUNDATION_SCENE_DOCUMENT_VERSION,
|
||||||
|
entities: {
|
||||||
|
[triggerVolume.id]: triggerVolume,
|
||||||
|
[pointLight.id]: pointLight
|
||||||
|
},
|
||||||
|
interactionLinks: {
|
||||||
|
"link-light-off": createControlInteractionLink({
|
||||||
|
id: "link-light-off",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
trigger: "enter",
|
||||||
|
effect: createSetLightEnabledControlEffect({
|
||||||
|
target: createLightControlTargetRef("pointLight", pointLight.id),
|
||||||
|
enabled: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const migratedDocument = migrateSceneDocument(legacyDocument);
|
||||||
|
|
||||||
|
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
|
||||||
|
expect(migratedDocument.interactionLinks).toEqual(
|
||||||
|
legacyDocument.interactionLinks
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user