Skip to content

Game.UI.InGame.CitizenCondition

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: readonly struct

Base: IJsonWritable, IComparable

Summary:
Represents a compact, immutable value describing a citizen's condition for UI purposes. Stores an internal key (a CitizenConditionKey enum) and exposes a mapping from that key to an icon path. Implements IJsonWritable to serialize a minimal JSON representation (type name, key name, iconPath) and IComparable to enable sorting by the underlying key value. The struct is immutable and safe to pass by value in UI code.


Fields

  • private static readonly string[] kConditionPaths
    An internal, readonly array of 7 SVG icon paths. The array maps each CitizenConditionKey (by its integral value) to a corresponding icon file:
  • index 0: "Media/Game/Icons/ConditionSick.svg"
  • index 1: "Media/Game/Icons/ConditionInjured.svg"
  • index 2: "Media/Game/Icons/ConditionHomeless.svg"
  • index 3: "Media/Game/Icons/ConditionMalcontent.svg"
  • index 4: "Media/Game/Icons/ConditionWeak.svg"
  • index 5: "Media/Game/Icons/ConditionInDistress.svg"
  • index 6: "Media/Game/Icons/ConditionEvacuated.svg" This array is shared across all instances and should not be modified.

Properties

  • private CitizenConditionKey key { get; }
    Internal read-only property that stores the condition key for this instance. It is private, so callers cannot access it directly; it is used by the struct's methods to determine icon path and to compare instances. The key is expected to correspond to indices in kConditionPaths (0..6).

Constructors

  • public CitizenCondition(CitizenConditionKey key)
    Creates a new CitizenCondition with the specified key. Because the struct is readonly, the key is set once at construction and cannot be changed afterward.

Methods

  • public void Write(IJsonWriter writer)
    Serializes the instance using the provided IJsonWriter. The method writes a type block named with typeof(CitizenCondition).FullName and emits two properties:
  • "key": the enum name of the key (Enum.GetName(...))
  • "iconPath": the corresponding entry from kConditionPaths based on the key's integer value Notes: This produces a compact representation suitable for UI state persistence or debugging. The method assumes the key's integral value is within the bounds of kConditionPaths.

  • public int CompareTo(CitizenCondition other)
    Compares this instance to another by comparing their underlying keys (uses the enum's natural ordering). Useful for sorting lists of conditions in deterministic order.

Usage Example

// Create a condition and serialize it
var condition = new CitizenCondition(CitizenConditionKey.ConditionSick);
using (var writer = /* obtain IJsonWriter instance */)
{
    condition.Write(writer);
}

// Sort an array of conditions
CitizenCondition[] conditions = {
    new CitizenCondition(CitizenConditionKey.ConditionHomeless),
    new CitizenCondition(CitizenConditionKey.ConditionSick),
    new CitizenCondition(CitizenConditionKey.ConditionEvacuated)
};
Array.Sort(conditions); // sorts by the underlying key values

Additional notes: - Expected enum values for CitizenConditionKey correspond to the icon names (ConditionSick, ConditionInjured, ConditionHomeless, ConditionMalcontent, ConditionWeak, ConditionInDistress, ConditionEvacuated) in the same order as kConditionPaths. - The struct is designed for UI usage (displaying icons and serializing state) and keeps the mapping internal to avoid duplication across UI components.