Game.GameModeExtensions
Assembly:
Assembly-CSharp
Namespace:
Game
Type:
static class
Base:
System.Object
Summary:
Extension methods for the GameMode enum used by Cities: Skylines 2. Provides a method to get a localized/engine-rich-presence status string for a mode, and several bitwise helper predicates to determine whether a GameMode value represents editor/game states. These are implemented as extension methods to be called directly on GameMode values.
Fields
- This static class defines no instance or static fields.
Additional info: all functionality is exposed via extension methods; no internal state is stored.
Properties
- This static class defines no properties.
Additional info: there are no cached values or configuration properties associated with these helpers.
Constructors
- This static class has no public constructors (static classes cannot be instantiated).
Additional info: the class is purely static and only provides extension methods.
Methods
public static string ToRichPresence(this GameMode gameMode)
Returns a localization / rich-presence key for the provided game mode. Mapping:- GameMode.MainMenu => "#StatusInMainMenu"
- GameMode.Game => "#StatusInGame"
- GameMode.Editor => "#StatusInEditor"
- default/other => string.Empty
Additional info: the returned strings appear to be localization keys (prefixed with '#') used for showing the player's current status (e.g., in Steam/Discord presence or in UI). If the enum value is unknown or not one of the handled cases, an empty string is returned.
public static bool IsEditor(this GameMode gameMode)
Returns true if the GameMode has the Editor bit set:- Implementation uses bitwise AND and equality: (gameMode & GameMode.Editor) == GameMode.Editor
Additional info: useful when GameMode is a flags-like enum where multiple bits may be combined; this check ensures the Editor bit is present.
public static bool IsGame(this GameMode gameMode)
Returns true if the GameMode has the Game bit set:- Implementation uses: (gameMode & GameMode.Game) == GameMode.Game
Additional info: similar to IsEditor but checks the Game bit specifically.
public static bool IsGameOrEditor(this GameMode gameMode)
Returns true if either Game or Editor bits are set:- Implementation uses: (gameMode & GameMode.GameOrEditor) != 0
Additional info: assumes GameMode.GameOrEditor is a mask combining the Game and Editor bits; this method checks for any of those bits being present.
Usage Example
// Example usages of the GameModeExtensions methods
GameMode mode = GameMode.MainMenu;
// Get a localization/rich-presence key for the current mode
string presenceKey = mode.ToRichPresence();
// presenceKey == "#StatusInMainMenu"
// Check mode type using bitwise-aware helpers
bool inEditor = mode.IsEditor();
bool inGame = mode.IsGame();
bool inGameOrEditor = mode.IsGameOrEditor();
// Example usage in UI/logic:
if (mode.IsGame())
{
// enable in-game UI
}
else if (mode.IsEditor())
{
// enable editor tools
}
Additional info: Since these are extension methods on an enum type, call them directly on any GameMode value. They perform simple, fast operations (a small switch or bitwise checks) and are safe to use in performance-sensitive code paths.