Skip to content

Game.PrisonSection

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

Type: class

Base: InfoSectionBase

Summary:
PrisonSection is an in-game UI info section that provides prisoner statistics for a selected prison building. It checks whether the currently selected entity has a Prison component, reads the prison's configured capacity from the building's PrisonData (respecting upgrades), counts current occupants from the Occupant buffer, and exposes these values to the UI/JSON writer as "prisonerCount" and "prisonerCapacity". The class is compiler-generated and preserved for linkers via attributes seen in the source.


Fields

  • <prisonerCount>k__BackingField (private int, compiler-generated)
    Backing field for the private auto-property prisonerCount. Stores the current number of prisoners computed during OnProcess().

  • <prisonerCapacity>k__BackingField (private int, compiler-generated)
    Backing field for the private auto-property prisonerCapacity. Stores the configured prisoner capacity read from PrisonData (including upgrades) during OnProcess().

Properties

  • protected override string group { get; }
    Returns the group name used by the InfoSection system: "PrisonSection". This identifies this info section within the UI framework.

  • private int prisonerCount { get; set; }
    Holds the current number of prisoners (updated in OnProcess()). Private to this class; exposed to the JSON writer in OnWriteProperties() as "prisonerCount".

  • private int prisonerCapacity { get; set; }
    Holds the configured prisoner capacity for the selected prison prefab (updated in OnProcess()). Private to this class; exposed to the JSON writer in OnWriteProperties() as "prisonerCapacity".

Constructors

  • public PrisonSection()
    Default constructor. Marked with [Preserve] in source to prevent stripping by the linker; no additional initialization is performed in the constructor itself.

Methods

  • protected override void Reset()
    Resets internal counters to zero. Called by the lifecycle when the section should clear its state. Sets prisonerCount = 0 and prisonerCapacity = 0.

  • private bool Visible()
    Determines visibility of this info section by checking whether the currently selected entity has a Game.Buildings.Prison component using the EntityManager. Returns true only if the selected entity is a prison building.

  • [Preserve] protected override void OnUpdate()
    Update hook used by the info section system. The override sets base.visible based on the Visible() check (so the UI will show/hide the section depending on whether the selected entity is a prison).

  • protected override void OnProcess()
    Main processing logic executed when the section is active. It:

  • Attempts to read PrisonData for the selected entity (via TryGetComponentWithUpgrades) to obtain m_PrisonerCapacity and assign it to prisonerCapacity.
  • Tries to read a read-only DynamicBuffer for the selected entity via the EntityManager; if present, sets prisonerCount to buffer.Length (current occupant count).

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes the prisonerCount and prisonerCapacity as JSON properties for the UI or other consumers:

  • Writes "prisonerCount" with the current prisonerCount value.
  • Writes "prisonerCapacity" with the current prisonerCapacity value.

Notes and remarks: - The class relies on members inherited from InfoSectionBase such as selectedEntity, selectedPrefab, EntityManager, TryGetComponentWithUpgrades, and base.visible. - TryGetComponentWithUpgrades is used to respect prefab upgrades when reading PrisonData. - The Occupant buffer is read-only when counting occupants to avoid modifying ECS state. - The class is minimal and focuses solely on obtaining and exposing these two numeric values for UI consumption.

Usage Example

// This snippet illustrates how PrisonSection updates visibility and writes properties.
// (Taken from the class behavior — for reference or testing when creating a similar section.)

[Preserve]
protected override void OnUpdate()
{
    // Ensure the section is only visible when the selected entity is a prison.
    base.visible = base.EntityManager.HasComponent<Game.Buildings.Prison>(selectedEntity);
}

protected override void OnProcess()
{
    // Read configured capacity (including upgrades) from PrisonData
    if (TryGetComponentWithUpgrades<PrisonData>(selectedEntity, selectedPrefab, out var data))
    {
        prisonerCapacity = data.m_PrisonerCapacity;
    }

    // Count current occupants from the Occupant buffer
    if (base.EntityManager.TryGetBuffer(selectedEntity, isReadOnly: true, out DynamicBuffer<Occupant> buffer))
    {
        prisonerCount = buffer.Length;
    }
}

public override void OnWriteProperties(IJsonWriter writer)
{
    writer.PropertyName("prisonerCount");
    writer.Write(prisonerCount);
    writer.PropertyName("prisonerCapacity");
    writer.Write(prisonerCapacity);
}

If you plan to extend or debug this section: - Verify selectedEntity and selectedPrefab values come from the UI selection flow in InfoSectionBase. - Use the EntityManager to inspect components and buffers when testing in-game. - Ensure the [Preserve] attribute is kept if constructing similar classes intended to survive code stripping.