Skip to content

Game.SimulationDateTime

Assembly: Game
Namespace: Game.Assets

Type: struct

Base: System.ValueType
Implements: IEquatable, IJsonReadable, IJsonWritable

Summary:
Represents a simple simulation date/time value used by the game (year, month, hour, minute). Provides equality semantics, value-type AOT support registration for JSON, and JSON read/write support via Colossal.Json interfaces. This struct is suitable for lightweight storage and comparison of in-game date/time snapshots.


Fields

  • public int year
    Represents the simulation year.

  • public int month
    Represents the simulation month (presumably 1–12).

  • public int hour
    Represents the simulation hour (0–23).

  • public int minute
    Represents the simulation minute (0–59).

Properties

  • None.
    This struct exposes its data via public fields rather than properties.

Constructors

  • public SimulationDateTime(int year, int month, int hour, int minute)
    Creates a new SimulationDateTime initialized with the provided year, month, hour and minute.

Methods

  • private static void SupportValueTypesForAOT()
    Registers this value type with the JSON system to ensure correct AOT behavior. Internally calls JSON.SupportTypeForAOT(). This method is private and used to work around Ahead-Of-Time compilation limitations when serializing value types.

  • public bool Equals(SimulationDateTime other)
    IEquatable implementation that compares year, month, hour and minute for equality.

  • public override bool Equals(object obj)
    Overrides Object.Equals to support equality comparison with boxed instances.

  • public override int GetHashCode()
    Generates a combined hash code from (year, month, hour, minute) tuple.

  • public static bool operator ==(SimulationDateTime left, SimulationDateTime right)
    Equality operator that delegates to Equals.

  • public static bool operator !=(SimulationDateTime left, SimulationDateTime right)
    Inequality operator that delegates to Equals.

  • public void Read(IJsonReader reader)
    IJsonReadable implementation. Reads a map containing properties "year", "month", "hour", "minute" from the provided reader and assigns them to the corresponding fields. Expects the JSON map ordering used in code (year -> month -> hour -> minute) and calls reader.ReadMapBegin()/ReadMapEnd().

  • public void Write(IJsonWriter writer)
    IJsonWritable implementation. Writes a typed object using writer.TypeBegin(GetType().FullName) and writes the "year", "month", "hour", "minute" properties in that order, then calls writer.TypeEnd().

Usage Example

// Constructing a SimulationDateTime
var simTime = new SimulationDateTime(year: 2035, month: 4, hour: 14, minute: 30);

// Comparing two instances
var a = new SimulationDateTime(2035, 4, 14, 30);
var b = new SimulationDateTime(2035, 4, 14, 30);
bool equal = (a == b); // true

// Using with JSON writer (Colossal.Json)
IJsonWriter writer = /* obtain writer from context */;
simTime.Write(writer);

// Using with JSON reader (Colossal.Json)
IJsonReader reader = /* obtain reader positioned at a SimulationDateTime map */;
SimulationDateTime parsed = default;
parsed.Read(reader);

// AOT support (called internally where needed)
SimulationDateTime.SupportValueTypesForAOT();

Notes: - Because this type uses public fields and simple primitives, it's efficient for frequent creation and comparison in the simulation. - The Read/Write implementations rely on the Colossal.Json reader/writer contracts; ensure the reader/writer you use matches those expected by the game's modding APIs.