2026-04-11 04:18:23 +02:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
|
|
|
|
import {
|
2026-04-11 13:26:46 +02:00
|
|
|
DEFAULT_PROJECT_NAME,
|
|
|
|
|
PLAYER_START_GAMEPAD_CAMERA_LOOK_SCENE_DOCUMENT_VERSION,
|
2026-04-11 04:40:23 +02:00
|
|
|
RUNNER_LOADING_SCREEN_SCENE_DOCUMENT_VERSION,
|
2026-04-11 04:18:23 +02:00
|
|
|
SCENE_DOCUMENT_VERSION,
|
|
|
|
|
createEmptyProjectDocument,
|
|
|
|
|
createEmptyProjectScene
|
|
|
|
|
} from "../../src/document/scene-document";
|
2026-04-11 04:40:23 +02:00
|
|
|
import {
|
|
|
|
|
createSceneEntryEntity,
|
|
|
|
|
createSceneExitEntity
|
|
|
|
|
} from "../../src/entities/entity-instances";
|
2026-04-11 04:18:23 +02:00
|
|
|
import {
|
|
|
|
|
parseProjectDocumentJson,
|
|
|
|
|
serializeProjectDocument
|
|
|
|
|
} from "../../src/serialization/scene-document-json";
|
|
|
|
|
|
|
|
|
|
describe("project document JSON", () => {
|
2026-04-11 13:26:46 +02:00
|
|
|
it("round-trips the project name and authored scene loading overlay settings", () => {
|
2026-04-11 04:40:23 +02:00
|
|
|
const cellarEntry = createSceneEntryEntity({
|
|
|
|
|
id: "entity-scene-entry-cellar-stairs",
|
|
|
|
|
position: {
|
|
|
|
|
x: 1,
|
|
|
|
|
y: 0,
|
|
|
|
|
z: -2
|
|
|
|
|
},
|
|
|
|
|
yawDegrees: 180
|
|
|
|
|
});
|
|
|
|
|
const mainExit = createSceneExitEntity({
|
|
|
|
|
id: "entity-scene-exit-main-hatch",
|
|
|
|
|
position: {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 1,
|
|
|
|
|
z: 3
|
|
|
|
|
},
|
|
|
|
|
targetSceneId: "scene-cellar",
|
|
|
|
|
targetEntryEntityId: cellarEntry.id
|
|
|
|
|
});
|
2026-04-11 04:18:23 +02:00
|
|
|
const document = {
|
2026-04-11 13:26:46 +02:00
|
|
|
...createEmptyProjectDocument({
|
|
|
|
|
name: "Castle Project",
|
|
|
|
|
sceneName: "Entry"
|
|
|
|
|
}),
|
2026-04-11 04:18:23 +02:00
|
|
|
activeSceneId: "scene-cellar",
|
|
|
|
|
scenes: {
|
|
|
|
|
"scene-main": createEmptyProjectScene({
|
|
|
|
|
id: "scene-main",
|
|
|
|
|
name: "Entry"
|
|
|
|
|
}),
|
|
|
|
|
"scene-cellar": createEmptyProjectScene({
|
|
|
|
|
id: "scene-cellar",
|
|
|
|
|
name: "Cellar",
|
|
|
|
|
loadingScreen: {
|
|
|
|
|
colorHex: "#233041",
|
|
|
|
|
headline: "Descending",
|
|
|
|
|
description: "Dust and echoes settle before the next room appears."
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-04-11 04:40:23 +02:00
|
|
|
document.scenes["scene-main"].entities[mainExit.id] = mainExit;
|
|
|
|
|
document.scenes["scene-cellar"].entities[cellarEntry.id] = cellarEntry;
|
2026-04-11 04:18:23 +02:00
|
|
|
|
|
|
|
|
const serializedDocument = serializeProjectDocument(document);
|
|
|
|
|
|
|
|
|
|
expect(parseProjectDocumentJson(serializedDocument)).toEqual(document);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-11 13:26:46 +02:00
|
|
|
it("migrates pre-project-name multi-scene documents to Untitled Project", () => {
|
|
|
|
|
const migratedDocument = parseProjectDocumentJson(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
version: PLAYER_START_GAMEPAD_CAMERA_LOOK_SCENE_DOCUMENT_VERSION,
|
|
|
|
|
activeSceneId: "scene-main",
|
|
|
|
|
scenes: {
|
|
|
|
|
"scene-main": createEmptyProjectScene({
|
|
|
|
|
id: "scene-main",
|
|
|
|
|
name: "Legacy Entry"
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
materials: createEmptyProjectDocument().materials,
|
|
|
|
|
textures: {},
|
|
|
|
|
assets: {}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
|
|
|
|
|
expect(migratedDocument.name).toBe(DEFAULT_PROJECT_NAME);
|
|
|
|
|
expect(migratedDocument.scenes["scene-main"]?.name).toBe("Legacy Entry");
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-11 04:40:33 +02:00
|
|
|
it("migrates v23 project documents without Scene Entry and Scene Exit entities", () => {
|
2026-04-11 04:18:23 +02:00
|
|
|
const legacyScene = createEmptyProjectScene({
|
|
|
|
|
id: "scene-main",
|
|
|
|
|
name: "Legacy Entry"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const migratedDocument = parseProjectDocumentJson(
|
|
|
|
|
JSON.stringify({
|
2026-04-11 04:40:23 +02:00
|
|
|
version: RUNNER_LOADING_SCREEN_SCENE_DOCUMENT_VERSION,
|
2026-04-11 04:18:23 +02:00
|
|
|
activeSceneId: "scene-main",
|
|
|
|
|
scenes: {
|
2026-04-11 04:40:33 +02:00
|
|
|
"scene-main": legacyScene
|
2026-04-11 04:18:23 +02:00
|
|
|
},
|
|
|
|
|
materials: createEmptyProjectDocument().materials,
|
|
|
|
|
textures: {},
|
|
|
|
|
assets: {}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
|
|
|
|
|
expect(migratedDocument.scenes["scene-main"]?.loadingScreen).toEqual(
|
2026-04-11 04:40:33 +02:00
|
|
|
legacyScene.loadingScreen
|
2026-04-11 04:18:23 +02:00
|
|
|
);
|
|
|
|
|
});
|
2026-04-11 04:41:24 +02:00
|
|
|
|
|
|
|
|
it("rejects Scene Exit targets that point at a missing Scene Entry", () => {
|
|
|
|
|
const document = createEmptyProjectDocument({ sceneName: "Outside" });
|
|
|
|
|
const targetScene = createEmptyProjectScene({
|
|
|
|
|
id: "scene-house",
|
|
|
|
|
name: "House"
|
|
|
|
|
});
|
|
|
|
|
document.scenes[targetScene.id] = targetScene;
|
|
|
|
|
document.scenes["scene-main"].entities["entity-scene-exit-door"] =
|
|
|
|
|
createSceneExitEntity({
|
|
|
|
|
id: "entity-scene-exit-door",
|
|
|
|
|
targetSceneId: targetScene.id,
|
|
|
|
|
targetEntryEntityId: "missing-entry"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(() =>
|
2026-04-11 04:41:32 +02:00
|
|
|
parseProjectDocumentJson(JSON.stringify(document))
|
2026-04-11 04:41:24 +02:00
|
|
|
).toThrow("target entry");
|
|
|
|
|
});
|
2026-04-11 04:18:23 +02:00
|
|
|
});
|