Game.Buildings.ValidationHelpers
Assembly: Game
Namespace: Game.Buildings
Type: static class
Base: System.Object
Summary:
A static helper class that provides validation routines for buildings and building upgrades. These methods are used by the validation pipeline (e.g., ValidationSystem) to detect common placement and upgrade errors (missing road access, insufficient groundwater, duplicate upgrades) and enqueue ErrorData items into a NativeQueue for further handling (warnings/errors shown to the player). The methods are designed to be usable from systems and worker jobs — they accept job-friendly collections such as NativeArray and NativeQueue<...>.ParallelWriter and rely on the ValidationSystem.EntityData container and related game systems (e.g., GroundWaterSystem, BuildingUtils).
Fields
- (none)
This static class defines no instance or static fields. All functionality is exposed via static methods that operate on data passed in by callers (ValidationSystem data structures, Native containers, and entity/component values).
Properties
- (none)
No properties are defined.
Constructors
- (none — static utility class)
ValidationHelpers is a static class and has no public constructors. Use its static methods directly.
Methods
public static void ValidateBuilding(Entity entity, Building building, Transform transform, PrefabRef prefabRef, ValidationSystem.EntityData data, NativeArray<GroundWater> groundWaterMap, NativeQueue<ErrorData>.ParallelWriter errorQueue)
Summary and behavior:- Validates a building entity for common placement issues and enqueues corresponding ErrorData entries when problems are found.
- Checks road access:
- If building.m_RoadEdge == Entity.Null and the building prefab has the RequireRoad flag, it calculates the building front position (via BuildingUtils.CalculateFrontPosition) and enqueues an ErrorData with:
- m_ErrorSeverity = Warning
- m_ErrorType = NoRoadAccess
- m_TempEntity = entity
- m_Position = calculated front position
- Checks groundwater availability:
- If the prefab is a water pumping station that accepts groundwater (data.m_WaterPumpingStationData.TryGetComponent(...) indicates AllowedWaterTypes.Groundwater) OR the prefab is powered from groundwater (data.m_GroundWaterPoweredData.HasComponent(prefab)), then it reads groundwater at the building position using GroundWaterSystem.GetGroundWater(transform.m_Position, groundWaterMap). If returned m_Max <= 500, it enqueues an ErrorData with:
- m_ErrorSeverity = Error
- m_ErrorType = NoGroundWater
- m_TempEntity = entity
- m_Position = transform.m_Position
- Parameters:
- entity: the building entity being validated.
- building: the Building component instance for the entity.
- transform: the Transform component instance for the entity (used for positions).
- prefabRef: PrefabRef identifying the building prefab.
- data: ValidationSystem.EntityData — provides access to prefab/component lookups and entity component arrays/buffers.
- groundWaterMap: NativeArray
map used by GroundWaterSystem.GetGroundWater. - errorQueue: NativeQueue
.ParallelWriter for thread-safe enqueue of validation errors.
-
Notes:
- This method assumes the provided ValidationSystem.EntityData contains the relevant prefab/component collections referenced (m_PrefabBuilding, m_WaterPumpingStationData, m_GroundWaterPoweredData, etc.).
- Uses NativeQueue<...>.ParallelWriter making it suitable for use inside parallel jobs or systems that have an appropriate writer.
- The groundwater threshold m_Max <= 500 is a hard-coded check as in the original implementation.
-
public static void ValidateUpgrade(Entity entity, Owner owner, PrefabRef prefabRef, ValidationSystem.EntityData data, NativeQueue<ErrorData>.ParallelWriter errorQueue)
Summary and behavior: - Validates installing an upgrade instance to ensure the same owner does not already have an upgrade of the same prefab installed.
- Early exit conditions:
- If the prefabRef.m_Prefab is recognized as a building prefab in data.m_PrefabBuilding (meaning it is a building), OR
- If data.m_Upgrades does not have a buffer for owner.m_Owner (no upgrade buffer present),
- then the method returns without reporting an error.
- Otherwise, reads the DynamicBuffer
buffer for the owner entity (data.m_Upgrades[owner.m_Owner]) and iterates it: - For each InstalledUpgrade entry, checks the upgrade entity reference. If an installed upgrade entity is not the same as the entity being validated and the installed upgrade's prefab (data.m_PrefabRef[upgrade].m_Prefab) equals prefabRef.m_Prefab, it enqueues an ErrorData with:
- m_ErrorSeverity = Error
- m_ErrorType = AlreadyUpgraded
- m_TempEntity = entity
- m_PermanentEntity = owner.m_Owner
- m_Position = data.m_Transform[owner.m_Owner].m_Position
- Parameters:
- entity: the upgrade entity being validated.
- owner: the Owner component identifying the owner entity (e.g., building/lot owner).
- prefabRef: PrefabRef of the upgrade being installed.
- data: ValidationSystem.EntityData with access to the upgrades buffer, prefab refs, transforms, etc.
- errorQueue: NativeQueue
.ParallelWriter to enqueue any detected errors.
- Notes:
- This method relies on the presence and correct population of the m_Upgrades dynamic buffer on owner entities.
- Designed to be callable from systems or jobs; the provided errorQueue is the ParallelWriter variant for safe multi-threaded enqueues.
Usage Example
// Example usage inside a validation system or job
// Assume `data` is ValidationSystem.EntityData populated for the current world,
// `groundWaterMap` is a NativeArray<GroundWater> produced by GroundWaterSystem,
// and `errorQueue` is a NativeQueue<ErrorData> with a ParallelWriter `errorQueueWriter`.
public void ValidateSomeBuilding(Entity buildingEntity)
{
Building building = data.m_Building[buildingEntity];
Transform transform = data.m_Transform[buildingEntity];
PrefabRef prefabRef = data.m_PrefabRef[buildingEntity];
// Single-threaded call (use errorQueue.Writer when not in a job)
ValidationHelpers.ValidateBuilding(buildingEntity, building, transform, prefabRef, data, groundWaterMap, errorQueue.Writer);
}
public void ValidateSomeUpgrade(Entity upgradeEntity)
{
Owner owner = data.m_Owner[upgradeEntity];
PrefabRef prefabRef = data.m_PrefabRef[upgradeEntity];
// Single-threaded call
ValidationHelpers.ValidateUpgrade(upgradeEntity, owner, prefabRef, data, errorQueue.Writer);
}
// In a parallel job, pass errorQueue.AsParallelWriter() as `errorQueue` and call the same methods.
Additional notes: - Ensure you pass the correct form of the NativeQueue writer depending on context: errorQueue.Writer for main-thread single usage, or errorQueue.AsParallelWriter() when invoking from parallel jobs. - These helpers do not mutate entity/component state: they only read components and enqueue ErrorData. Any response to errors (visualization, blocking placement, logging) is handled elsewhere in the validation pipeline.