From 74e7be5073a24f3d88b81820aa710c36d6b1c782 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 2 Apr 2026 19:19:54 +0200 Subject: [PATCH] Refactor interaction link handling in App.tsx and update tests --- src/app/App.tsx | 76 +++++++++++++------ tests/domain/build-runtime-scene.test.ts | 3 +- .../domain/scene-document-validation.test.ts | 6 +- tests/domain/world-settings.test.ts | 6 +- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index 80a4fd33..967f5613 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -84,7 +84,6 @@ import { DEFAULT_POINT_LIGHT_COLOR_HEX, DEFAULT_POINT_LIGHT_DISTANCE, DEFAULT_POINT_LIGHT_INTENSITY, - DEFAULT_POINT_LIGHT_POSITION, DEFAULT_SOUND_EMITTER_GAIN, DEFAULT_SOUND_EMITTER_RADIUS, DEFAULT_TELEPORT_TARGET_YAW_DEGREES, @@ -93,7 +92,6 @@ import { DEFAULT_SPOT_LIGHT_DISTANCE, DEFAULT_SPOT_LIGHT_DIRECTION, DEFAULT_SPOT_LIGHT_INTENSITY, - DEFAULT_SPOT_LIGHT_POSITION, DEFAULT_TRIGGER_VOLUME_SIZE, areEntityInstancesEqual, createInteractableEntity, @@ -1623,21 +1621,45 @@ export function App({ store, initialStatusMessage }: AppProps) { return; } - const nextLink = - link.action.type === "teleportPlayer" - ? createTeleportPlayerInteractionLink({ - id: link.id, - sourceEntityId: link.sourceEntityId, - trigger, - targetEntityId: link.action.targetEntityId - }) - : createToggleVisibilityInteractionLink({ - id: link.id, - sourceEntityId: link.sourceEntityId, - trigger, - targetBrushId: link.action.targetBrushId, - visible: link.action.visible - }); + let nextLink: InteractionLink; + + switch (link.action.type) { + case "teleportPlayer": + nextLink = createTeleportPlayerInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetEntityId: link.action.targetEntityId + }); + break; + case "toggleVisibility": + nextLink = createToggleVisibilityInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetBrushId: link.action.targetBrushId, + visible: link.action.visible + }); + break; + case "playAnimation": + nextLink = createPlayAnimationInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetModelInstanceId: link.action.targetModelInstanceId, + clipName: link.action.clipName, + loop: link.action.loop + }); + break; + case "stopAnimation": + nextLink = createStopAnimationInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetModelInstanceId: link.action.targetModelInstanceId + }); + break; + } commitInteractionLinkChange(link, nextLink, `Updated ${getInteractionTriggerLabel(trigger).toLowerCase()} trigger link.`); }; @@ -1671,14 +1693,17 @@ export function App({ store, initialStatusMessage }: AppProps) { } if (actionType === "playAnimation") { - const firstInstance = modelInstanceDisplayList[0]; + const targetModelInstance = + (link.action.type === "playAnimation" || link.action.type === "stopAnimation" + ? editorState.document.modelInstances[link.action.targetModelInstanceId] + : undefined) ?? modelInstanceDisplayList[0]?.modelInstance; - if (firstInstance === undefined) { + if (targetModelInstance === undefined) { setStatusMessage("Place a model instance before switching this link to play animation."); return; } - const asset = editorState.document.assets[firstInstance.modelInstance.assetId]; + const asset = editorState.document.assets[targetModelInstance.assetId]; const firstClip = asset?.kind === "model" ? (asset.metadata.animationNames[0] ?? "") : ""; if (firstClip === "") { @@ -1692,7 +1717,7 @@ export function App({ store, initialStatusMessage }: AppProps) { id: link.id, sourceEntityId: sourceEntity.id, trigger: link.trigger, - targetModelInstanceId: firstInstance.modelInstance.id, + targetModelInstanceId: targetModelInstance.id, clipName: firstClip }), "Switched link action to play animation." @@ -1701,9 +1726,12 @@ export function App({ store, initialStatusMessage }: AppProps) { } if (actionType === "stopAnimation") { - const firstInstance = modelInstanceDisplayList[0]; + const targetModelInstance = + (link.action.type === "playAnimation" || link.action.type === "stopAnimation" + ? editorState.document.modelInstances[link.action.targetModelInstanceId] + : undefined) ?? modelInstanceDisplayList[0]?.modelInstance; - if (firstInstance === undefined) { + if (targetModelInstance === undefined) { setStatusMessage("Place a model instance before switching this link to stop animation."); return; } @@ -1714,7 +1742,7 @@ export function App({ store, initialStatusMessage }: AppProps) { id: link.id, sourceEntityId: sourceEntity.id, trigger: link.trigger, - targetModelInstanceId: firstInstance.modelInstance.id + targetModelInstanceId: targetModelInstance.id }), "Switched link action to stop animation." ); diff --git a/tests/domain/build-runtime-scene.test.ts b/tests/domain/build-runtime-scene.test.ts index bf8063ae..69f57bff 100644 --- a/tests/domain/build-runtime-scene.test.ts +++ b/tests/domain/build-runtime-scene.test.ts @@ -226,7 +226,8 @@ describe("buildRuntimeSceneFromDocument", () => { }; document.world.background = { mode: "image", - assetId: imageAsset.id + assetId: imageAsset.id, + environmentIntensity: 0.75 }; document.world.ambientLight.intensity = 0.55; document.world.sunLight.direction = { diff --git a/tests/domain/scene-document-validation.test.ts b/tests/domain/scene-document-validation.test.ts index 2c428ddf..76bf7e71 100644 --- a/tests/domain/scene-document-validation.test.ts +++ b/tests/domain/scene-document-validation.test.ts @@ -237,7 +237,8 @@ describe("validateSceneDocument", () => { }; document.world.background = { mode: "image", - assetId: imageAsset.id + assetId: imageAsset.id, + environmentIntensity: 0.5 }; const validation = validateSceneDocument(document); @@ -273,7 +274,8 @@ describe("validateSceneDocument", () => { }; document.world.background = { mode: "image", - assetId: "asset-missing-background" + assetId: "asset-missing-background", + environmentIntensity: 0.5 }; const validation = validateSceneDocument(document); diff --git a/tests/domain/world-settings.test.ts b/tests/domain/world-settings.test.ts index 6c47a91c..bb24406f 100644 --- a/tests/domain/world-settings.test.ts +++ b/tests/domain/world-settings.test.ts @@ -42,14 +42,16 @@ describe("world settings helpers", () => { expect(imageBackground).toEqual({ mode: "image", - assetId: "asset-background-panorama" + assetId: "asset-background-panorama", + environmentIntensity: 0.5 }); const nextImageBackground = changeWorldBackgroundMode(imageBackground, "image", "asset-background-panorama-2"); expect(nextImageBackground).toEqual({ mode: "image", - assetId: "asset-background-panorama-2" + assetId: "asset-background-panorama-2", + environmentIntensity: 0.5 }); const world = createDefaultWorldSettings();