From 419e125ca097bc02f7314d18ae1831c016cc1c84 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 14:09:14 +0200 Subject: [PATCH] Add types, constants, and normalization functions for terrain grid resize directions --- src/document/terrains.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/document/terrains.ts b/src/document/terrains.ts index 64611e9e..8b653866 100644 --- a/src/document/terrains.ts +++ b/src/document/terrains.ts @@ -38,6 +38,9 @@ export interface Terrain { foliageBlockerMask: TerrainFoliageBlockerMask; } +export type TerrainGridResizeDirectionX = "east" | "west"; +export type TerrainGridResizeDirectionZ = "north" | "south"; + export interface TerrainHeightPatchEntry { index: number; before: number; @@ -87,6 +90,10 @@ export const TERRAIN_LAYER_COUNT = 4; export const MIN_TERRAIN_LAYER_COUNT = 1; export const MAX_TERRAIN_LAYER_COUNT = 8; export const TERRAIN_SHADER_LAYER_COUNT = 8; +export const DEFAULT_TERRAIN_GRID_RESIZE_DIRECTION_X: TerrainGridResizeDirectionX = + "east"; +export const DEFAULT_TERRAIN_GRID_RESIZE_DIRECTION_Z: TerrainGridResizeDirectionZ = + "north"; export const DEFAULT_TERRAIN_LAYER_MATERIAL_IDS = [ "patchy_grass_ground_250x250", "patchy_weedy_dirt_ground_300x300", @@ -158,6 +165,34 @@ export function normalizeTerrainCellSize(value: number): number { return value; } +export function normalizeTerrainGridResizeDirectionX( + value: TerrainGridResizeDirectionX | undefined +): TerrainGridResizeDirectionX { + if (value === undefined) { + return DEFAULT_TERRAIN_GRID_RESIZE_DIRECTION_X; + } + + if (value !== "east" && value !== "west") { + throw new Error("Terrain X resize direction must be east or west."); + } + + return value; +} + +export function normalizeTerrainGridResizeDirectionZ( + value: TerrainGridResizeDirectionZ | undefined +): TerrainGridResizeDirectionZ { + if (value === undefined) { + return DEFAULT_TERRAIN_GRID_RESIZE_DIRECTION_Z; + } + + if (value !== "north" && value !== "south") { + throw new Error("Terrain Z resize direction must be north or south."); + } + + return value; +} + function normalizeTerrainLayerMaterialId( value: string | null | undefined, label: string