auto-git:
[change] src/commands/apply-terrain-brush-patch-command.ts
This commit is contained in:
@@ -81,28 +81,11 @@ function mergeTerrainSampleIndexIntoBounds(
|
||||
};
|
||||
}
|
||||
|
||||
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,
|
||||
export function applyTerrainBrushPatchToDocument(
|
||||
currentDocument: ReturnType<CommandContext["getDocument"]>,
|
||||
patch: TerrainBrushPatch,
|
||||
direction: "forward" | "backward"
|
||||
) => {
|
||||
const currentDocument = context.getDocument();
|
||||
): ReturnType<CommandContext["getDocument"]> {
|
||||
const terrain = currentDocument.terrains[patch.terrainId];
|
||||
|
||||
if (terrain === undefined) {
|
||||
@@ -153,11 +136,7 @@ export function createApplyTerrainBrushPatchCommand(
|
||||
}
|
||||
|
||||
const mask = getOrCreateTerrainFoliageMask(terrain, entry.layerId);
|
||||
assertValidPatchEntry(
|
||||
entry,
|
||||
mask.values.length,
|
||||
"Terrain foliage mask"
|
||||
);
|
||||
assertValidPatchEntry(entry, mask.values.length, "Terrain foliage mask");
|
||||
mask.values[entry.index] =
|
||||
direction === "forward" ? entry.after : entry.before;
|
||||
renderDirtyBounds = mergeTerrainSampleIndexIntoBounds(
|
||||
@@ -188,13 +167,43 @@ export function createApplyTerrainBrushPatchCommand(
|
||||
|
||||
markTerrainRenderSamplesDirty(terrain, renderDirtyBounds);
|
||||
|
||||
context.setDocument({
|
||||
return {
|
||||
...currentDocument,
|
||||
terrains: {
|
||||
...currentDocument.terrains,
|
||||
[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 {
|
||||
|
||||
Reference in New Issue
Block a user