Skip to content

Game.Areas.Storage

Assembly: Game
Namespace: Game.Areas

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Storage is a lightweight ECS component that holds two simple values used by area systems: an integer amount and a floating-point "work" amount. It implements Colossal's ISerializable so instances can be written to and restored from saved data. The Deserialize method contains a version check (Version.garbageFacilityRefactor) to preserve compatibility with older save formats where the work amount may not have been stored.


Fields

  • public int m_Amount
    This field stores the primary integer quantity tracked by the component (for example stored units, count of items, or similar). As a public field on a struct component, it is stored directly in the entity's component data and defaults to 0.

  • public float m_WorkAmount
    A floating-point value representing an associated "work" or progress amount related to m_Amount (for example accumulated work or fractional progress). Defaults to 0.0f. This value is serialized conditionally based on the save format version (see Deserialize).

Properties

  • None. Storage exposes plain public fields and does not define C# properties.

Constructors

  • public Storage() (implicit)
    As a struct, Storage has the implicit parameterless constructor which initializes m_Amount to 0 and m_WorkAmount to 0.0f. No explicit constructors are defined.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component state to the provided writer. The method writes m_Amount first (int) and then m_WorkAmount (float). This method implements the ISerializable contract used by the game's serialization system.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component state from the provided reader. It always reads m_Amount. It reads m_WorkAmount only when reader.context.version >= Version.garbageFacilityRefactor to maintain backward compatibility with older save versions that did not store the work amount. The method uses ref locals to assign directly into the struct fields.

Notes: - Both methods are generic over writer/reader types constrained to IWriter/IReader from Colossal.Serialization.Entities. - The version guard prevents reading a float from streams that do not contain that value.

Usage Example

// Creating and using Storage as a component value
var storage = new Storage
{
    m_Amount = 100,
    m_WorkAmount = 12.5f
};

// Example pseudo-serialization flow
// writer and reader represent the game's IWriter/IReader implementations
writer.Write(storage.m_Amount);
writer.Write(storage.m_WorkAmount);

// When loading, Deserialize will only read m_WorkAmount if the save version includes it:
ref int amount = ref storage.m_Amount;
reader.Read(out amount);
if (reader.context.version >= Version.garbageFacilityRefactor)
{
    ref float workAmount = ref storage.m_WorkAmount;
    reader.Read(out workAmount);
}