Skip to content

Game.UI.InGame.CitizenHappiness

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

Type: readonly struct

Base: System.ValueType, IJsonWritable

Summary:
Represents a small value object used to serialize a citizen happiness value to JSON for UI consumption. Encapsulates a CitizenHappinessKey and maps that key to a predefined SVG icon path for use by the in-game UI. Implements IJsonWritable so it can write its data into an IJsonWriter in the expected format.


Fields

  • private static readonly string[] kHappinessPaths
    Contains the 5 SVG icon paths used to represent happiness states (Depressed, Sad, Neutral, Content, Happy). Indexed by the integer value of CitizenHappinessKey.

Properties

  • private CitizenHappinessKey key { get; }
    Holds the happiness key value for this instance. It is an immutable (readonly) auto-property used when serializing the object.

Constructors

  • public CitizenHappiness(CitizenHappinessKey key)
    Creates a new CitizenHappiness instance with the provided CitizenHappinessKey. Stores the key for later serialization.

Methods

  • public void Write(IJsonWriter writer)
    Serializes this CitizenHappiness to the provided IJsonWriter. The method writes a JSON type wrapper using the full type name, then writes two properties:
  • "key": the enum name of the CitizenHappinessKey (via Enum.GetName)
  • "iconPath": the SVG path selected from kHappinessPaths based on the key's integer value Finally it closes the type wrapper. This method relies on the kHappinessPaths array having entries corresponding to the CitizenHappinessKey enum values (0..4).

Usage Example

// Example: create a CitizenHappiness and write it using an IJsonWriter
var happiness = new CitizenHappiness(CitizenHappinessKey.Happy);

// Obtain an IJsonWriter from your JSON system (pseudo-code)
IJsonWriter writer = GetJsonWriter(); // replace with actual writer creation

happiness.Write(writer);

// Expected output (conceptually):
// {
//   "$type": "Game.UI.InGame.CitizenHappiness",
//   "key": "Happy",
//   "iconPath": "Media/Game/Icons/Happy.svg"
// }