auto-git:

[change] src/commands/apply-terrain-brush-patch-command.ts
This commit is contained in:
2026-05-13 00:14:19 +02:00
parent 21955f147a
commit 83f8d2a860

View File

@@ -81,28 +81,11 @@ function mergeTerrainSampleIndexIntoBounds(
}; };
} }
export function createApplyTerrainBrushPatchCommand( export function applyTerrainBrushPatchToDocument(
options: ApplyTerrainBrushPatchCommandOptions currentDocument: ReturnType<CommandContext["getDocument"]>,
): EditorCommand { patch: TerrainBrushPatch,
const patch: TerrainBrushPatch = {
terrainId: options.patch.terrainId,
heightSamples: options.patch.heightSamples.map((entry) => ({ ...entry })),
paintWeights: options.patch.paintWeights.map((entry) => ({ ...entry })),
foliageMaskValues: options.patch.foliageMaskValues.map((entry) => ({
...entry
})),
foliageBlockerMaskValues: options.patch.foliageBlockerMaskValues.map(
(entry) => ({ ...entry })
)
};
let previousSelection: EditorSelection | null = null;
let previousToolMode: ToolMode | null = null;
const applyPatch = (
context: CommandContext,
direction: "forward" | "backward" direction: "forward" | "backward"
) => { ): ReturnType<CommandContext["getDocument"]> {
const currentDocument = context.getDocument();
const terrain = currentDocument.terrains[patch.terrainId]; const terrain = currentDocument.terrains[patch.terrainId];
if (terrain === undefined) { if (terrain === undefined) {
@@ -153,11 +136,7 @@ export function createApplyTerrainBrushPatchCommand(
} }
const mask = getOrCreateTerrainFoliageMask(terrain, entry.layerId); const mask = getOrCreateTerrainFoliageMask(terrain, entry.layerId);
assertValidPatchEntry( assertValidPatchEntry(entry, mask.values.length, "Terrain foliage mask");
entry,
mask.values.length,
"Terrain foliage mask"
);
mask.values[entry.index] = mask.values[entry.index] =
direction === "forward" ? entry.after : entry.before; direction === "forward" ? entry.after : entry.before;
renderDirtyBounds = mergeTerrainSampleIndexIntoBounds( renderDirtyBounds = mergeTerrainSampleIndexIntoBounds(
@@ -188,13 +167,43 @@ export function createApplyTerrainBrushPatchCommand(
markTerrainRenderSamplesDirty(terrain, renderDirtyBounds); markTerrainRenderSamplesDirty(terrain, renderDirtyBounds);
context.setDocument({ return {
...currentDocument, ...currentDocument,
terrains: { terrains: {
...currentDocument.terrains, ...currentDocument.terrains,
[patch.terrainId]: terrain [patch.terrainId]: terrain
} }
}); };
}
export function createApplyTerrainBrushPatchCommand(
options: ApplyTerrainBrushPatchCommandOptions
): EditorCommand {
const patch: TerrainBrushPatch = {
terrainId: options.patch.terrainId,
heightSamples: options.patch.heightSamples.map((entry) => ({ ...entry })),
paintWeights: options.patch.paintWeights.map((entry) => ({ ...entry })),
foliageMaskValues: options.patch.foliageMaskValues.map((entry) => ({
...entry
})),
foliageBlockerMaskValues: options.patch.foliageBlockerMaskValues.map(
(entry) => ({ ...entry })
)
};
let previousSelection: EditorSelection | null = null;
let previousToolMode: ToolMode | null = null;
const applyPatch = (
context: CommandContext,
direction: "forward" | "backward"
) => {
context.setDocument(
applyTerrainBrushPatchToDocument(
context.getDocument(),
patch,
direction
)
);
}; };
return { return {