From 7424cb7304df208609debab520c968ff2eccd003 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 2 Apr 2026 19:41:37 +0200 Subject: [PATCH] Add playSound and stopSound interaction links --- src/app/App.tsx | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/app/App.tsx b/src/app/App.tsx index 28039745..ea69f974 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -1748,6 +1748,22 @@ export function App({ store, initialStatusMessage }: AppProps) { targetModelInstanceId: link.action.targetModelInstanceId }); break; + case "playSound": + nextLink = createPlaySoundInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetSoundEmitterId: link.action.targetSoundEmitterId + }); + break; + case "stopSound": + nextLink = createStopSoundInteractionLink({ + id: link.id, + sourceEntityId: link.sourceEntityId, + trigger, + targetSoundEmitterId: link.action.targetSoundEmitterId + }); + break; } commitInteractionLinkChange(link, nextLink, `Updated ${getInteractionTriggerLabel(trigger).toLowerCase()} trigger link.`); @@ -1838,6 +1854,51 @@ export function App({ store, initialStatusMessage }: AppProps) { return; } + if (actionType === "playSound" || actionType === "stopSound") { + const targetSoundEmitter = + (link.action.type === "playSound" || link.action.type === "stopSound" + ? editorState.document.entities[link.action.targetSoundEmitterId] + : undefined) ?? soundEmitterOptions.find(({ entity }) => { + if (entity.audioAssetId === null) { + return false; + } + + const asset = editorState.document.assets[entity.audioAssetId]; + return asset?.kind === "audio"; + })?.entity; + + if (targetSoundEmitter === undefined || targetSoundEmitter.kind !== "soundEmitter") { + setStatusMessage("Author a Sound Emitter with an audio asset before switching this link to sound playback."); + return; + } + + if (actionType === "playSound") { + commitInteractionLinkChange( + link, + createPlaySoundInteractionLink({ + id: link.id, + sourceEntityId: sourceEntity.id, + trigger: link.trigger, + targetSoundEmitterId: targetSoundEmitter.id + }), + "Switched link action to play sound." + ); + } else { + commitInteractionLinkChange( + link, + createStopSoundInteractionLink({ + id: link.id, + sourceEntityId: sourceEntity.id, + trigger: link.trigger, + targetSoundEmitterId: targetSoundEmitter.id + }), + "Switched link action to stop sound." + ); + } + + return; + } + const defaultBrush = visibilityBrushOptions[0]?.brush; if (defaultBrush === undefined) {