2026-04-11 04:18:23 +02:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
|
|
|
|
import {
|
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", () => {
|
|
|
|
|
it("round-trips 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 = {
|
|
|
|
|
...createEmptyProjectDocument({ sceneName: "Entry" }),
|
|
|
|
|
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 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
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|