[add] src/rendering/terrain-layer-material.ts [add] tests/domain/terrains.test.ts [change] src/app/App.tsx [change] src/core/terrain-brush.ts [change] src/document/migrate-scene-document.ts [change] src/document/scene-document-validation.ts [change] src/document/scene-document.ts [change] src/document/terrains.ts [change] src/geometry/terrain-brush.ts [change] src/geometry/terrain-mesh.ts [change] src/runtime-three/rapier-collision-world.ts [change] src/runtime-three/runtime-host.ts [change] src/runtime-three/runtime-scene-build.ts [change] src/viewport-three/ViewportCanvas.tsx [change] src/viewport-three/ViewportPanel.tsx [change] src/viewport-three/viewport-host.ts [change] tests/domain/build-runtime-scene.test.ts [change] tests/domain/rapier-collision-world.test.ts [change] tests/domain/terrain.command.test.ts [change] tests/domain/water-material.test.ts [change] tests/geometry/terrain-brush.test.ts [change] tests/geometry/terrain-mesh.test.ts [change] tests/serialization/scene-document-json.test.ts [change] tests/unit/terrain-foundation.integration.test.tsx [change] tests/unit/viewport-canvas.test.tsx
150 lines
3.7 KiB
TypeScript
150 lines
3.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { createEditorStore } from "../../src/app/editor-store";
|
|
import { createDeleteTerrainCommand } from "../../src/commands/delete-terrain-command";
|
|
import { createUpsertTerrainCommand } from "../../src/commands/upsert-terrain-command";
|
|
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
|
import { createTerrain } from "../../src/document/terrains";
|
|
|
|
describe("terrain commands", () => {
|
|
it("creates a terrain and restores it through undo and redo", () => {
|
|
const store = createEditorStore();
|
|
const terrain = createTerrain({
|
|
id: "terrain-create-main",
|
|
sampleCountX: 3,
|
|
sampleCountZ: 3,
|
|
cellSize: 2
|
|
});
|
|
|
|
store.executeCommand(
|
|
createUpsertTerrainCommand({
|
|
terrain,
|
|
label: "Create terrain fixture"
|
|
})
|
|
);
|
|
|
|
expect(store.getState().document.terrains[terrain.id]).toEqual(terrain);
|
|
expect(store.getState().selection).toEqual({
|
|
kind: "terrains",
|
|
ids: [terrain.id]
|
|
});
|
|
|
|
expect(store.undo()).toBe(true);
|
|
expect(store.getState().document.terrains).toEqual({});
|
|
|
|
expect(store.redo()).toBe(true);
|
|
expect(store.getState().document.terrains[terrain.id]).toEqual(terrain);
|
|
});
|
|
|
|
it("updates existing terrain data without replacing the terrain id", () => {
|
|
const existingTerrain = createTerrain({
|
|
id: "terrain-update-main",
|
|
sampleCountX: 3,
|
|
sampleCountZ: 3,
|
|
heights: [0, 0, 0, 0, 1, 0, 0, 0, 0]
|
|
});
|
|
const store = createEditorStore({
|
|
initialDocument: {
|
|
...createEmptySceneDocument({ name: "Terrain Update Scene" }),
|
|
terrains: {
|
|
[existingTerrain.id]: existingTerrain
|
|
}
|
|
}
|
|
});
|
|
const updatedTerrain = createTerrain({
|
|
id: existingTerrain.id,
|
|
name: "Raised Ridge",
|
|
position: {
|
|
x: -4,
|
|
y: 2,
|
|
z: -4
|
|
},
|
|
sampleCountX: 3,
|
|
sampleCountZ: 3,
|
|
cellSize: 1.5,
|
|
heights: [0, 1, 0, 1, 3, 1, 0, 1, 0],
|
|
paintWeights: [
|
|
0.2,
|
|
0,
|
|
0,
|
|
0.1,
|
|
0.3,
|
|
0,
|
|
0,
|
|
0.15,
|
|
0,
|
|
0.25,
|
|
0.25,
|
|
0,
|
|
0.05,
|
|
0.1,
|
|
0.1,
|
|
0,
|
|
0,
|
|
0,
|
|
0.2,
|
|
0,
|
|
0.2,
|
|
0,
|
|
0.1,
|
|
0,
|
|
0,
|
|
0,
|
|
0
|
|
]
|
|
});
|
|
|
|
store.executeCommand(
|
|
createUpsertTerrainCommand({
|
|
terrain: updatedTerrain,
|
|
label: "Update terrain fixture"
|
|
})
|
|
);
|
|
|
|
expect(store.getState().document.terrains[existingTerrain.id]).toEqual(
|
|
updatedTerrain
|
|
);
|
|
|
|
expect(store.undo()).toBe(true);
|
|
expect(store.getState().document.terrains[existingTerrain.id]).toEqual(
|
|
existingTerrain
|
|
);
|
|
|
|
expect(store.redo()).toBe(true);
|
|
expect(store.getState().document.terrains[existingTerrain.id]).toEqual(
|
|
updatedTerrain
|
|
);
|
|
});
|
|
|
|
it("deletes a terrain in one undoable command", () => {
|
|
const terrain = createTerrain({
|
|
id: "terrain-delete-main"
|
|
});
|
|
const store = createEditorStore({
|
|
initialDocument: {
|
|
...createEmptySceneDocument({ name: "Terrain Delete Scene" }),
|
|
terrains: {
|
|
[terrain.id]: terrain
|
|
}
|
|
}
|
|
});
|
|
store.setSelection({
|
|
kind: "terrains",
|
|
ids: [terrain.id]
|
|
});
|
|
|
|
store.executeCommand(createDeleteTerrainCommand(terrain.id));
|
|
|
|
expect(store.getState().document.terrains[terrain.id]).toBeUndefined();
|
|
expect(store.getState().selection).toEqual({
|
|
kind: "none"
|
|
});
|
|
|
|
expect(store.undo()).toBe(true);
|
|
expect(store.getState().document.terrains[terrain.id]).toEqual(terrain);
|
|
|
|
expect(store.redo()).toBe(true);
|
|
expect(store.getState().document.terrains[terrain.id]).toBeUndefined();
|
|
});
|
|
});
|