Update sound emitter tests and add audio asset support in scene document serialization
This commit is contained in:
@@ -21,10 +21,11 @@ test("user can place and select typed entities from the entity foundation workfl
|
|||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
await page.getByTestId("add-entity-soundEmitter").click();
|
await page.getByTestId("add-entity-soundEmitter").click();
|
||||||
await expect(page.getByTestId("sound-emitter-radius")).toHaveValue("6");
|
await expect(page.getByTestId("sound-emitter-ref-distance")).toHaveValue("6");
|
||||||
|
await expect(page.getByTestId("sound-emitter-max-distance")).toHaveValue("24");
|
||||||
|
|
||||||
await page.getByTestId("sound-emitter-radius").fill("9");
|
await page.getByTestId("sound-emitter-ref-distance").fill("9");
|
||||||
await page.getByTestId("sound-emitter-radius").press("Tab");
|
await page.getByTestId("sound-emitter-ref-distance").press("Tab");
|
||||||
|
|
||||||
await page.getByTestId("add-entity-interactable").click();
|
await page.getByTestId("add-entity-interactable").click();
|
||||||
await expect(page.getByTestId("interactable-prompt")).toHaveValue("Use");
|
await expect(page.getByTestId("interactable-prompt")).toHaveValue("Use");
|
||||||
@@ -35,7 +36,7 @@ test("user can place and select typed entities from the entity foundation workfl
|
|||||||
.first()
|
.first()
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
await expect(page.getByTestId("sound-emitter-radius")).toHaveValue("9");
|
await expect(page.getByTestId("sound-emitter-ref-distance")).toHaveValue("9");
|
||||||
await expect(page.getByTestId("interactable-prompt")).toHaveCount(0);
|
await expect(page.getByTestId("interactable-prompt")).toHaveCount(0);
|
||||||
|
|
||||||
expect(pageErrors).toEqual([]);
|
expect(pageErrors).toEqual([]);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import { createBoxBrush } from "../../src/document/brushes";
|
import { createBoxBrush } from "../../src/document/brushes";
|
||||||
import {
|
import {
|
||||||
|
ANIMATION_PLAYBACK_SCENE_DOCUMENT_VERSION,
|
||||||
ENTITY_SYSTEM_FOUNDATION_SCENE_DOCUMENT_VERSION,
|
ENTITY_SYSTEM_FOUNDATION_SCENE_DOCUMENT_VERSION,
|
||||||
FIRST_ROOM_POLISH_SCENE_DOCUMENT_VERSION,
|
FIRST_ROOM_POLISH_SCENE_DOCUMENT_VERSION,
|
||||||
LOCAL_LIGHTS_AND_SKYBOX_SCENE_DOCUMENT_VERSION,
|
LOCAL_LIGHTS_AND_SKYBOX_SCENE_DOCUMENT_VERSION,
|
||||||
@@ -21,10 +22,17 @@ import {
|
|||||||
createTeleportTargetEntity,
|
createTeleportTargetEntity,
|
||||||
createTriggerVolumeEntity
|
createTriggerVolumeEntity
|
||||||
} from "../../src/entities/entity-instances";
|
} from "../../src/entities/entity-instances";
|
||||||
import { createTeleportPlayerInteractionLink, createToggleVisibilityInteractionLink, createPlayAnimationInteractionLink, createStopAnimationInteractionLink } from "../../src/interactions/interaction-links";
|
import {
|
||||||
|
createPlayAnimationInteractionLink,
|
||||||
|
createPlaySoundInteractionLink,
|
||||||
|
createStopAnimationInteractionLink,
|
||||||
|
createStopSoundInteractionLink,
|
||||||
|
createTeleportPlayerInteractionLink,
|
||||||
|
createToggleVisibilityInteractionLink
|
||||||
|
} from "../../src/interactions/interaction-links";
|
||||||
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
|
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
|
||||||
import { createModelInstance } from "../../src/assets/model-instances";
|
import { createModelInstance } from "../../src/assets/model-instances";
|
||||||
import { createProjectAssetStorageKey, type ImageAssetRecord, type ModelAssetRecord } from "../../src/assets/project-assets";
|
import { createProjectAssetStorageKey, type AudioAssetRecord, type ImageAssetRecord, type ModelAssetRecord } from "../../src/assets/project-assets";
|
||||||
import { parseSceneDocumentJson, serializeSceneDocument } from "../../src/serialization/scene-document-json";
|
import { parseSceneDocumentJson, serializeSceneDocument } from "../../src/serialization/scene-document-json";
|
||||||
|
|
||||||
describe("scene document JSON", () => {
|
describe("scene document JSON", () => {
|
||||||
@@ -211,6 +219,21 @@ describe("scene document JSON", () => {
|
|||||||
const playerStart = createPlayerStartEntity({
|
const playerStart = createPlayerStartEntity({
|
||||||
id: "entity-player-start-main"
|
id: "entity-player-start-main"
|
||||||
});
|
});
|
||||||
|
const audioAsset = {
|
||||||
|
id: "asset-audio-main",
|
||||||
|
kind: "audio" as const,
|
||||||
|
sourceName: "lobby-loop.ogg",
|
||||||
|
mimeType: "audio/ogg",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||||
|
byteLength: 4096,
|
||||||
|
metadata: {
|
||||||
|
kind: "audio" as const,
|
||||||
|
durationSeconds: 4.5,
|
||||||
|
channelCount: 2,
|
||||||
|
sampleRateHz: 48000,
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies AudioAssetRecord;
|
||||||
const soundEmitter = createSoundEmitterEntity({
|
const soundEmitter = createSoundEmitterEntity({
|
||||||
id: "entity-sound-main",
|
id: "entity-sound-main",
|
||||||
position: {
|
position: {
|
||||||
@@ -218,8 +241,10 @@ describe("scene document JSON", () => {
|
|||||||
y: 2,
|
y: 2,
|
||||||
z: 3
|
z: 3
|
||||||
},
|
},
|
||||||
radius: 7,
|
audioAssetId: audioAsset.id,
|
||||||
gain: 0.6,
|
volume: 0.6,
|
||||||
|
refDistance: 7,
|
||||||
|
maxDistance: 18,
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
loop: true
|
loop: true
|
||||||
});
|
});
|
||||||
@@ -258,6 +283,9 @@ describe("scene document JSON", () => {
|
|||||||
});
|
});
|
||||||
const document = {
|
const document = {
|
||||||
...createEmptySceneDocument({ name: "Typed Entity Scene" }),
|
...createEmptySceneDocument({ name: "Typed Entity Scene" }),
|
||||||
|
assets: {
|
||||||
|
[audioAsset.id]: audioAsset
|
||||||
|
},
|
||||||
entities: {
|
entities: {
|
||||||
[playerStart.id]: playerStart,
|
[playerStart.id]: playerStart,
|
||||||
[soundEmitter.id]: soundEmitter,
|
[soundEmitter.id]: soundEmitter,
|
||||||
@@ -273,6 +301,59 @@ describe("scene document JSON", () => {
|
|||||||
expect(roundTripDocument.modelInstances).toEqual({});
|
expect(roundTripDocument.modelInstances).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("round-trips authored playSound and stopSound interaction links", () => {
|
||||||
|
const audioAsset = {
|
||||||
|
id: "asset-audio-main",
|
||||||
|
kind: "audio" as const,
|
||||||
|
sourceName: "lobby-loop.ogg",
|
||||||
|
mimeType: "audio/ogg",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||||
|
byteLength: 4096,
|
||||||
|
metadata: {
|
||||||
|
kind: "audio" as const,
|
||||||
|
durationSeconds: 4.5,
|
||||||
|
channelCount: 2,
|
||||||
|
sampleRateHz: 48000,
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies AudioAssetRecord;
|
||||||
|
const triggerVolume = createTriggerVolumeEntity({
|
||||||
|
id: "entity-trigger-main"
|
||||||
|
});
|
||||||
|
const soundEmitter = createSoundEmitterEntity({
|
||||||
|
id: "entity-sound-main",
|
||||||
|
audioAssetId: audioAsset.id
|
||||||
|
});
|
||||||
|
const playLink = createPlaySoundInteractionLink({
|
||||||
|
id: "link-play-sound",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
trigger: "enter",
|
||||||
|
targetSoundEmitterId: soundEmitter.id
|
||||||
|
});
|
||||||
|
const stopLink = createStopSoundInteractionLink({
|
||||||
|
id: "link-stop-sound",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
trigger: "exit",
|
||||||
|
targetSoundEmitterId: soundEmitter.id
|
||||||
|
});
|
||||||
|
const document = {
|
||||||
|
...createEmptySceneDocument({ name: "Sound Link Scene" }),
|
||||||
|
assets: {
|
||||||
|
[audioAsset.id]: audioAsset
|
||||||
|
},
|
||||||
|
entities: {
|
||||||
|
[triggerVolume.id]: triggerVolume,
|
||||||
|
[soundEmitter.id]: soundEmitter
|
||||||
|
},
|
||||||
|
interactionLinks: {
|
||||||
|
[playLink.id]: playLink,
|
||||||
|
[stopLink.id]: stopLink
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||||
|
});
|
||||||
|
|
||||||
it("round-trips imported model assets and placed model instances", () => {
|
it("round-trips imported model assets and placed model instances", () => {
|
||||||
const asset = {
|
const asset = {
|
||||||
id: "asset-model-triangle",
|
id: "asset-model-triangle",
|
||||||
|
|||||||
Reference in New Issue
Block a user