Feat: Implement foliage layer management commands (create, delete, update)

This commit is contained in:
2026-05-02 03:58:47 +02:00
parent 796760c00a
commit c9adcd9cd3
3 changed files with 157 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { createOpaqueId } from "../core/ids";
import { cloneFoliageLayer, type FoliageLayer } from "../foliage/foliage";
import type { EditorCommand } from "./command";
interface CreateFoliageLayerCommandOptions {
layer: FoliageLayer;
label?: string;
}
export function createCreateFoliageLayerCommand(
options: CreateFoliageLayerCommandOptions
): EditorCommand {
const nextLayer = cloneFoliageLayer(options.layer);
return {
id: createOpaqueId("command"),
label: options.label ?? "Create foliage layer",
execute(context) {
const currentDocument = context.getDocument();
if (currentDocument.foliageLayers[nextLayer.id] !== undefined) {
throw new Error(`Foliage layer ${nextLayer.id} already exists.`);
}
context.setDocument({
...currentDocument,
foliageLayers: {
...currentDocument.foliageLayers,
[nextLayer.id]: cloneFoliageLayer(nextLayer)
}
});
},
undo(context) {
const currentDocument = context.getDocument();
const nextFoliageLayers = {
...currentDocument.foliageLayers
};
delete nextFoliageLayers[nextLayer.id];
context.setDocument({
...currentDocument,
foliageLayers: nextFoliageLayers
});
}
};
}