Refactor interaction link handling in App.tsx and update tests
This commit is contained in:
@@ -84,7 +84,6 @@ import {
|
|||||||
DEFAULT_POINT_LIGHT_COLOR_HEX,
|
DEFAULT_POINT_LIGHT_COLOR_HEX,
|
||||||
DEFAULT_POINT_LIGHT_DISTANCE,
|
DEFAULT_POINT_LIGHT_DISTANCE,
|
||||||
DEFAULT_POINT_LIGHT_INTENSITY,
|
DEFAULT_POINT_LIGHT_INTENSITY,
|
||||||
DEFAULT_POINT_LIGHT_POSITION,
|
|
||||||
DEFAULT_SOUND_EMITTER_GAIN,
|
DEFAULT_SOUND_EMITTER_GAIN,
|
||||||
DEFAULT_SOUND_EMITTER_RADIUS,
|
DEFAULT_SOUND_EMITTER_RADIUS,
|
||||||
DEFAULT_TELEPORT_TARGET_YAW_DEGREES,
|
DEFAULT_TELEPORT_TARGET_YAW_DEGREES,
|
||||||
@@ -93,7 +92,6 @@ import {
|
|||||||
DEFAULT_SPOT_LIGHT_DISTANCE,
|
DEFAULT_SPOT_LIGHT_DISTANCE,
|
||||||
DEFAULT_SPOT_LIGHT_DIRECTION,
|
DEFAULT_SPOT_LIGHT_DIRECTION,
|
||||||
DEFAULT_SPOT_LIGHT_INTENSITY,
|
DEFAULT_SPOT_LIGHT_INTENSITY,
|
||||||
DEFAULT_SPOT_LIGHT_POSITION,
|
|
||||||
DEFAULT_TRIGGER_VOLUME_SIZE,
|
DEFAULT_TRIGGER_VOLUME_SIZE,
|
||||||
areEntityInstancesEqual,
|
areEntityInstancesEqual,
|
||||||
createInteractableEntity,
|
createInteractableEntity,
|
||||||
@@ -1623,21 +1621,45 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextLink =
|
let nextLink: InteractionLink;
|
||||||
link.action.type === "teleportPlayer"
|
|
||||||
? createTeleportPlayerInteractionLink({
|
switch (link.action.type) {
|
||||||
|
case "teleportPlayer":
|
||||||
|
nextLink = createTeleportPlayerInteractionLink({
|
||||||
id: link.id,
|
id: link.id,
|
||||||
sourceEntityId: link.sourceEntityId,
|
sourceEntityId: link.sourceEntityId,
|
||||||
trigger,
|
trigger,
|
||||||
targetEntityId: link.action.targetEntityId
|
targetEntityId: link.action.targetEntityId
|
||||||
})
|
});
|
||||||
: createToggleVisibilityInteractionLink({
|
break;
|
||||||
|
case "toggleVisibility":
|
||||||
|
nextLink = createToggleVisibilityInteractionLink({
|
||||||
id: link.id,
|
id: link.id,
|
||||||
sourceEntityId: link.sourceEntityId,
|
sourceEntityId: link.sourceEntityId,
|
||||||
trigger,
|
trigger,
|
||||||
targetBrushId: link.action.targetBrushId,
|
targetBrushId: link.action.targetBrushId,
|
||||||
visible: link.action.visible
|
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.`);
|
commitInteractionLinkChange(link, nextLink, `Updated ${getInteractionTriggerLabel(trigger).toLowerCase()} trigger link.`);
|
||||||
};
|
};
|
||||||
@@ -1671,14 +1693,17 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "playAnimation") {
|
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.");
|
setStatusMessage("Place a model instance before switching this link to play animation.");
|
||||||
return;
|
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] ?? "") : "";
|
const firstClip = asset?.kind === "model" ? (asset.metadata.animationNames[0] ?? "") : "";
|
||||||
|
|
||||||
if (firstClip === "") {
|
if (firstClip === "") {
|
||||||
@@ -1692,7 +1717,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
|||||||
id: link.id,
|
id: link.id,
|
||||||
sourceEntityId: sourceEntity.id,
|
sourceEntityId: sourceEntity.id,
|
||||||
trigger: link.trigger,
|
trigger: link.trigger,
|
||||||
targetModelInstanceId: firstInstance.modelInstance.id,
|
targetModelInstanceId: targetModelInstance.id,
|
||||||
clipName: firstClip
|
clipName: firstClip
|
||||||
}),
|
}),
|
||||||
"Switched link action to play animation."
|
"Switched link action to play animation."
|
||||||
@@ -1701,9 +1726,12 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "stopAnimation") {
|
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.");
|
setStatusMessage("Place a model instance before switching this link to stop animation.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1714,7 +1742,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
|||||||
id: link.id,
|
id: link.id,
|
||||||
sourceEntityId: sourceEntity.id,
|
sourceEntityId: sourceEntity.id,
|
||||||
trigger: link.trigger,
|
trigger: link.trigger,
|
||||||
targetModelInstanceId: firstInstance.modelInstance.id
|
targetModelInstanceId: targetModelInstance.id
|
||||||
}),
|
}),
|
||||||
"Switched link action to stop animation."
|
"Switched link action to stop animation."
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -226,7 +226,8 @@ describe("buildRuntimeSceneFromDocument", () => {
|
|||||||
};
|
};
|
||||||
document.world.background = {
|
document.world.background = {
|
||||||
mode: "image",
|
mode: "image",
|
||||||
assetId: imageAsset.id
|
assetId: imageAsset.id,
|
||||||
|
environmentIntensity: 0.75
|
||||||
};
|
};
|
||||||
document.world.ambientLight.intensity = 0.55;
|
document.world.ambientLight.intensity = 0.55;
|
||||||
document.world.sunLight.direction = {
|
document.world.sunLight.direction = {
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ describe("validateSceneDocument", () => {
|
|||||||
};
|
};
|
||||||
document.world.background = {
|
document.world.background = {
|
||||||
mode: "image",
|
mode: "image",
|
||||||
assetId: imageAsset.id
|
assetId: imageAsset.id,
|
||||||
|
environmentIntensity: 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
const validation = validateSceneDocument(document);
|
const validation = validateSceneDocument(document);
|
||||||
@@ -273,7 +274,8 @@ describe("validateSceneDocument", () => {
|
|||||||
};
|
};
|
||||||
document.world.background = {
|
document.world.background = {
|
||||||
mode: "image",
|
mode: "image",
|
||||||
assetId: "asset-missing-background"
|
assetId: "asset-missing-background",
|
||||||
|
environmentIntensity: 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
const validation = validateSceneDocument(document);
|
const validation = validateSceneDocument(document);
|
||||||
|
|||||||
@@ -42,14 +42,16 @@ describe("world settings helpers", () => {
|
|||||||
|
|
||||||
expect(imageBackground).toEqual({
|
expect(imageBackground).toEqual({
|
||||||
mode: "image",
|
mode: "image",
|
||||||
assetId: "asset-background-panorama"
|
assetId: "asset-background-panorama",
|
||||||
|
environmentIntensity: 0.5
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextImageBackground = changeWorldBackgroundMode(imageBackground, "image", "asset-background-panorama-2");
|
const nextImageBackground = changeWorldBackgroundMode(imageBackground, "image", "asset-background-panorama-2");
|
||||||
|
|
||||||
expect(nextImageBackground).toEqual({
|
expect(nextImageBackground).toEqual({
|
||||||
mode: "image",
|
mode: "image",
|
||||||
assetId: "asset-background-panorama-2"
|
assetId: "asset-background-panorama-2",
|
||||||
|
environmentIntensity: 0.5
|
||||||
});
|
});
|
||||||
|
|
||||||
const world = createDefaultWorldSettings();
|
const world = createDefaultWorldSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user