Files
webeditor3d/src/commands/set-scene-loading-screen-command.ts
Victor Giers e205cea50c auto-git:
[change] src/app/app.css
 [change] src/commands/set-scene-loading-screen-command.ts
 [change] src/document/migrate-scene-document.ts
 [change] src/document/scene-document-validation.ts
 [change] src/document/scene-document.ts
 [change] src/runner-web/RunnerCanvas.tsx
 [change] src/runtime-three/first-person-navigation-controller.ts
 [change] src/runtime-three/navigation-controller.ts
 [change] src/runtime-three/orbit-visitor-navigation-controller.ts
 [change] src/runtime-three/runtime-host.ts
 [change] tests/domain/editor-store.test.ts
 [change] tests/serialization/local-draft-storage.test.ts
 [change] tests/serialization/project-document-json.test.ts
 [change] tests/serialization/project-package.test.ts
 [change] tests/unit/runner-canvas.test.tsx
 [change] tests/unit/runtime-host.test.ts
2026-04-11 04:19:51 +02:00

82 lines
2.2 KiB
TypeScript

import { createOpaqueId } from "../core/ids";
import {
cloneSceneLoadingScreenSettings,
type SceneLoadingScreenSettings
} from "../document/scene-document";
import type { EditorCommand } from "./command";
interface SetSceneLoadingScreenCommandOptions {
sceneId: string;
label: string;
loadingScreen: SceneLoadingScreenSettings;
}
export function createSetSceneLoadingScreenCommand(
options: SetSceneLoadingScreenCommandOptions
): EditorCommand {
const nextLoadingScreen = cloneSceneLoadingScreenSettings(
options.loadingScreen
);
let previousLoadingScreen: SceneLoadingScreenSettings | null = null;
return {
id: createOpaqueId("command"),
label: options.label,
execute(context) {
const currentProjectDocument = context.getProjectDocument();
const currentScene = currentProjectDocument.scenes[options.sceneId];
if (currentScene === undefined) {
throw new Error(
`Cannot update loading overlay for missing scene ${options.sceneId}.`
);
}
if (previousLoadingScreen === null) {
previousLoadingScreen = cloneSceneLoadingScreenSettings(
currentScene.loadingScreen
);
}
context.setProjectDocument({
...currentProjectDocument,
scenes: {
...currentProjectDocument.scenes,
[options.sceneId]: {
...currentScene,
loadingScreen: cloneSceneLoadingScreenSettings(nextLoadingScreen)
}
}
});
},
undo(context) {
if (previousLoadingScreen === null) {
return;
}
const currentProjectDocument = context.getProjectDocument();
const currentScene = currentProjectDocument.scenes[options.sceneId];
if (currentScene === undefined) {
throw new Error(
`Cannot restore loading overlay for missing scene ${options.sceneId}.`
);
}
context.setProjectDocument({
...currentProjectDocument,
scenes: {
...currentProjectDocument.scenes,
[options.sceneId]: {
...currentScene,
loadingScreen: cloneSceneLoadingScreenSettings(
previousLoadingScreen
)
}
}
});
}
};
}