Game.PSI.Internal.Helpers
Assembly: Assembly-CSharp
Namespace: Game.PSI.Internal
Type: public static class Helpers
Base: System.Object (static class)
Summary:
Utility helper methods and small nested enums used by the PSI telemetry and settings conversion layer. Provides:
- a read-only mapping from UnityEngine.SystemLanguage to ISO language codes,
- extension methods to convert game settings types (DisplayMode, ScreenResolution, GameMode, bool) into telemetry-friendly representations,
- two nested enums used as the telemetry JSON representations for display mode and gameplay mode.
This class depends on Colossal.PSI.Common (TelemetryException), Game.Settings (DisplayMode, ScreenResolution, GameMode), and UnityEngine (Application.systemLanguage, SystemLanguage).
Fields
-
private static readonly IReadOnlyDictionary<SystemLanguage, string> s_SystemLanguageToISO
Mapping dictionary from UnityEngine.SystemLanguage to ISO language code strings. Used by GetSystemLanguage() to return a short language identifier for telemetry. The mapping covers many languages including explicit entries for Chinese Simplified ("zh-HANS") and Chinese Traditional ("zh-HANT"). If a language is not present in the dictionary, GetSystemLanguage returns an empty string. -
public enum json_displaymode
Nested enum representing telemetry display-mode values: - fullscreen
- windowed
- borderless_window
Used as the telemetry representation returned by the DisplayMode extension method.
public enum json_gameplay_mode
Nested enum representing telemetry gameplay-mode values:- sandbox
- editor
Used as the telemetry representation returned by the GameMode extension method.
Properties
- This static helper class exposes no properties.
Constructors
- No constructors — class is static and cannot be instantiated.
Methods
-
public static string GetSystemLanguage()
Returns the ISO language code string corresponding to UnityEngine.Application.systemLanguage using s_SystemLanguageToISO. If the current system language is not present in the mapping, returns an empty string. -
public static json_displaymode ToTelemetry(this DisplayMode mode)
Extension method converting Game.Settings.DisplayMode into the telemetry enum json_displaymode: - DisplayMode.Fullscreen => json_displaymode.fullscreen
- DisplayMode.Window => json_displaymode.windowed
- DisplayMode.FullscreenWindow => json_displaymode.borderless_window
Throws Colossal.PSI.Common.TelemetryException if an unexpected DisplayMode value is provided.
-
public static string ToTelemetry(this ScreenResolution resolution)
Extension method that converts a ScreenResolution into a "WIDTHxHEIGHT" string (e.g., "1920x1080") for telemetry. -
public static int AsInt(this bool value)
Extension method that converts a bool to integer: true => 1, false => 0. Useful when telemetry expects numeric values. -
public static json_gameplay_mode ToTelemetry(this GameMode gameMode)
Extension method converting Game.Settings.GameMode into the telemetry enum json_gameplay_mode: - GameMode.Game => json_gameplay_mode.sandbox
- GameMode.Editor => json_gameplay_mode.editor
Throws Colossal.PSI.Common.TelemetryException if an unexpected GameMode value is provided.
Notes: - The ToTelemetry methods for DisplayMode and GameMode validate inputs and throw TelemetryException for unknown enum values — callers should handle or allow these to propagate. - All conversion methods (except GetSystemLanguage) are implemented as extension methods; include the appropriate using/import to access them as instance methods.
Usage Example
using Game.PSI.Internal;
using Game.Settings;
using UnityEngine;
// Get the current system language as ISO code
string iso = Helpers.GetSystemLanguage();
// or, since GetSystemLanguage is static, call directly:
Debug.Log($"System language ISO: {iso}");
// Convert display mode to telemetry enum
DisplayMode dm = DisplayMode.Window;
var telemetryDisplay = dm.ToTelemetry(); // json_displaymode.windowed
// Convert screen resolution to string
ScreenResolution res = new ScreenResolution { width = 1920, height = 1080 };
string resTelemetry = res.ToTelemetry(); // "1920x1080"
// Bool to int
int flag = true.AsInt(); // 1
// Game mode to telemetry enum
GameMode gm = GameMode.Game;
var telemetryGame = gm.ToTelemetry(); // json_gameplay_mode.sandbox
Remarks: - Ensure you have references to the Game.Settings types and Colossal.PSI.Common in your project to compile and use these helpers. - The language mapping contains many common languages; for any missing systemLanguage values GetSystemLanguage will return an empty string.