Game.UI.MapMetadataSystem
Assembly: Assembly-CSharp
Namespace: Game.UI
Type: class
Base: GameSystemBase
Summary:
MapMetadataSystem collects and exposes high-level metadata about the currently loaded map for UI and mod usage. It aggregates map area and buildable land, resource totals (fertile land, forest, oil, ore, fish), water availability (surface and groundwater), outside connection types (road, train, air, ship, electricity, water), and planetary/climate info (latitude, longitude, climate prefab properties, theme). The system updates its cached values each frame in OnUpdate by querying map tiles and outside connection entities using ECS EntityQuery and buffer/component type handles.
Fields
-
private PlanetarySystem m_PlanetarySystem
Reference to the PlanetarySystem used to retrieve latitude/longitude. -
private CityConfigurationSystem m_CityConfigurationSystem
Reference to city configuration to obtain default theme prefab entity. -
private ClimateSystem m_ClimateSystem
Reference to current climate selection (used to read climate prefab data). -
private PrefabSystem m_PrefabSystem
Reference used to resolve prefabs (themes, climates, outside connection data). -
private float m_Area
Aggregated total map area (sum from MapFeatureElement buffers). -
private float m_BuildableLand
Aggregated buildable land total. -
private float m_SurfaceWaterAvailability
Aggregated surface water availability. -
private float m_GroundWaterAvailability
Aggregated ground water availability. -
private Resources m_Resources
Struct holding resource totals (fertile, forest, oil, ore, fish). -
private Connections m_Connections
Struct holding booleans for available outside connection types. -
private EntityQuery m_MapTileQuery
EntityQuery used to iterate map tiles (MapTile buffer, excluding Temp/Deleted). -
private EntityQuery m_OutsideConnectionQuery
EntityQuery used to find outside connections / outside connection prefabs. -
private TypeHandle __TypeHandle
Container of buffer/component type handles cached for efficient access (auto-generated helper).
Properties
-
public string mapName { get; set; }
Optional map name (nullable). Public get/set. -
public string theme { get; }
Returns the name of the default theme prefab if set in city configuration; otherwise null. -
public Bounds1 temperatureRange { get; }
Returns climate prefab temperature range if a current climate prefab is set; otherwise default(Bounds1). -
public float cloudiness { get; }
Returns the climate prefab averageCloudiness for the current climate; otherwise 0. -
public float precipitation { get; }
Returns the climate prefab averagePrecipitation for the current climate; otherwise 0. -
public float latitude { get; }
Proxy to m_PlanetarySystem.latitude. -
public float longitude { get; }
Proxy to m_PlanetarySystem.longitude. -
public float area { get; }
Gets the last computed total area (m_Area). -
public float buildableLand { get; }
Gets the last computed buildable land total (m_BuildableLand). -
public float surfaceWaterAvailability { get; }
Gets the last computed surface water availability. -
public float groundWaterAvailability { get; }
Gets the last computed ground water availability. -
public Resources resources { get; }
Returns the last computed Resources struct. -
public Connections connections { get; }
Returns the last computed Connections struct.
Nested Types
public struct Resources : IJsonWritable
Holds resource totals as floats: fertile, forest, oil, ore, fish. Includes:ProxyObject ToVariant()
— create a JSON/variant object representation.-
void Write(IJsonWriter writer)
— write typed JSON representation. -
public struct Connections : IJsonWritable
Holds booleans indicating availability of connection types: road, train, air, ship, electricity, water. Includes: ProxyObject ToVariant()
— create a JSON/variant object representation.-
void Write(IJsonWriter writer)
— write typed JSON representation. -
private struct TypeHandle
Auto-generated helper storing BufferTypeHandle/ComponentTypeHandle instances for MapFeatureElement, ElectricityOutsideConnection, WaterPipeOutsideConnection, and PrefabRef. Provides: void __AssignHandles(ref SystemState state)
— caches required type handles from the provided SystemState.
Constructors
public MapMetadataSystem()
Default constructor (preserved). Typical ECS system construction handled by framework; no custom initialization beyond base.
Methods
[Preserve] protected override void OnCreate()
Initializes system references and EntityQueries:- Resolves PlanetarySystem, CityConfigurationSystem, ClimateSystem, PrefabSystem via World.GetOrCreateSystemManaged.
- Creates m_MapTileQuery to read MapTile buffers and exclude Temp/Deleted.
-
Creates m_OutsideConnectionQuery to find entities that have any OutsideConnection/ElectricityOutsideConnection/WaterPipeOutsideConnection and exclude Temp/Deleted.
-
[Preserve] protected override void OnUpdate()
Main update executed each frame: - Calls CompleteDependency() to ensure dependencies are finished.
- Calls UpdateResources() to recompute area, buildable land, water availability and resource totals.
-
Calls UpdateConnections() to recompute available outside connection types.
-
private void UpdateResources()
Iterates m_MapTileQuery archetype chunks and reads MapFeatureElement dynamic buffers to accumulate: -
Area, buildable land, surface water, groundwater, and resource totals (fertile, forest, oil, ore, fish). Uses BufferTypeHandle
and disposes the temporary ArchetypeChunk array. -
private void UpdateConnections()
Iterates m_OutsideConnectionQuery archetype chunks and: - Checks for electricity / water connection components presence on chunks to set those flags.
-
Reads PrefabRef components and resolves OutsideConnectionData on their prefabs to determine if road/train/air/ship transfer types are supported by outside connections. Uses ComponentTypeHandle and disposes the temporary ArchetypeChunk array.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Auto-generated stub used at compile-time to set up queries; here it creates and disposes an EntityQueryBuilder (no-op in decompiled form). -
protected override void OnCreateForCompiler()
Compiler helper invoked to assign queries and type handles for the ECS job system (calls __AssignQueries and TypeHandle.__AssignHandles).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_PlanetarySystem = base.World.GetOrCreateSystemManaged<PlanetarySystem>();
m_CityConfigurationSystem = base.World.GetOrCreateSystemManaged<CityConfigurationSystem>();
m_ClimateSystem = base.World.GetOrCreateSystemManaged<ClimateSystem>();
m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
m_MapTileQuery = GetEntityQuery(ComponentType.ReadOnly<MapTile>(), ComponentType.Exclude<Temp>(), ComponentType.Exclude<Deleted>());
m_OutsideConnectionQuery = GetEntityQuery(new EntityQueryDesc
{
Any = new ComponentType[3]
{
ComponentType.ReadOnly<Game.Objects.OutsideConnection>(),
ComponentType.ReadOnly<Game.Objects.ElectricityOutsideConnection>(),
ComponentType.ReadOnly<Game.Objects.WaterPipeOutsideConnection>()
},
None = new ComponentType[2]
{
ComponentType.ReadOnly<Temp>(),
ComponentType.ReadOnly<Deleted>()
}
});
}
Notes: - The system is read-only with respect to map tile buffers and outside connection components; it only aggregates and caches info for UI consumption. - Resource/connection values reflect the last OnUpdate run and should be read from the system properties (resources, connections, area, etc.).