Game.UI.InGame.CompanyProfitability
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: readonly struct
Base: System.ValueType, IJsonWritable
Summary:
Represents a company's profitability state for UI purposes. Encapsulates a CompanyProfitabilityKey and maps that key to a small set of SVG icon paths. Implements IJsonWritable to serialize its key name and corresponding icon path into JSON (writes the type name, a "key" property with the enum name, and an "iconPath" property with the resolved SVG path).
Fields
private static readonly string[] kHappinessPaths
Contains the file paths for the five profitability icons used by the UI. The array length is 5 and the entries (in index order) correspond to the profitability key values used by the code:- "Media/Game/Icons/CompanyBankrupt.svg"
- "Media/Game/Icons/CompanyLosingMoney.svg"
- "Media/Game/Icons/CompanyBreakingEven.svg"
-
"Media/Game/Icons/CompanyGettingBy.svg" The struct uses the enum value (cast to int) to index this array to pick the icon path.
-
private CompanyProfitabilityKey key { get; }
Private, read-only auto-property that stores the profitability key for this instance. The key determines both the serialized "key" value and which icon path is selected from kHappinessPaths.
Properties
private CompanyProfitabilityKey key { get; }
Private accessor for the stored CompanyProfitabilityKey. No public setter — value is set via constructors only.
Constructors
-
public CompanyProfitability(int profit)
Constructs the struct by converting a numeric profit value into a CompanyProfitabilityKey using CompanyUIUtils.GetProfitabilityKey(profit). Use this when you have a profit amount and want the appropriate UI state. -
public CompanyProfitability(CompanyProfitabilityKey key)
Constructs the struct directly from an existing CompanyProfitabilityKey.
Methods
public void Write(IJsonWriter writer) : System.Void
Implements IJsonWritable.Write. Serializes this CompanyProfitability instance into JSON by:- Calling writer.TypeBegin(typeof(CompanyProfitability).FullName)
- Writing a "key" property whose value is the enum name (via Enum.GetName)
- Writing an "iconPath" property whose value is the SVG path selected from kHappinessPaths[(int)key]
- Calling writer.TypeEnd() This produces a small JSON object containing the type, the key name, and the icon path.
Notes: - The code assumes the integer value of CompanyProfitabilityKey maps directly to the kHappinessPaths indices (0..4). - If CompanyProfitabilityKey has values outside 0..4, indexing kHappinessPaths would throw; ensure enum and array remain synchronized.
Usage Example
// Create from a profit value (e.g., profit = 12345)
var cpFromProfit = new CompanyProfitability(12345);
// Or create directly from the enum key
var cpFromKey = new CompanyProfitability(CompanyProfitabilityKey.Profitable);
// Write to an IJsonWriter implementation
IJsonWriter writer = /* obtain writer */;
cpFromProfit.Write(writer);
// Resulting JSON will contain the "key" (enum name) and "iconPath" (SVG path)