Add set-project-dialogues-command and update migrate-scene-document

This commit is contained in:
2026-04-14 19:54:15 +02:00
parent d800b9a2a5
commit 9b2be661d0
2 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { createOpaqueId } from "../core/ids";
import {
cloneProjectDialogueLibrary,
type ProjectDialogueLibrary
} from "../dialogues/project-dialogues";
import type { EditorCommand } from "./command";
interface SetProjectDialoguesCommandOptions {
label: string;
dialogues: ProjectDialogueLibrary;
}
export function createSetProjectDialoguesCommand(
options: SetProjectDialoguesCommandOptions
): EditorCommand {
const nextDialogues = cloneProjectDialogueLibrary(options.dialogues);
let previousDialogues: ProjectDialogueLibrary | null = null;
return {
id: createOpaqueId("command"),
label: options.label,
execute(context) {
const currentProjectDocument = context.getProjectDocument();
if (previousDialogues === null) {
previousDialogues = cloneProjectDialogueLibrary(
currentProjectDocument.dialogues
);
}
context.setProjectDocument({
...currentProjectDocument,
dialogues: cloneProjectDialogueLibrary(nextDialogues)
});
},
undo(context) {
if (previousDialogues === null) {
return;
}
const currentProjectDocument = context.getProjectDocument();
context.setProjectDocument({
...currentProjectDocument,
dialogues: cloneProjectDialogueLibrary(previousDialogues)
});
}
};
}