GameState - alexneargarder/Broforce-Docs GitHub Wiki

GameState

Table of Contents

Core Singleton & Instance Management

Properties

public static GameState Instance { get; set; }

Gets the singleton instance of the GameState class, creating it if it doesn't exist. This singleton manages persistent game state across all scenes.


public byte sessionID { get; set; }

Gets or sets the current network session ID. Used to maintain session continuity across scene transitions in multiplayer games.


Fields

private static GameState instance

Private static field holding the singleton instance of GameState. Accessed through the Instance property.


private byte sessionID2 = byte.MaxValue

Private backing field for the sessionID property. Stores the network session identifier. Defaults to byte.MaxValue.


Campaign & Level

Properties

public string campaignName { get; set; }

Gets or sets the name of the current campaign being played. Used to track which campaign the player is in across level transitions.


Fields

public string _campaignName

Public backing field for the campaignName property. Stores the current campaign name.


public string customLevelID = string.Empty

The unique identifier for custom levels. Used when loading user-created content from Steam Workshop or Playtomic.


public int levelNumber

The current level number within the campaign. Used to track progression and determine which level to load.


public bool loadCustomCampaign

Flag indicating whether the game should load a custom campaign (user-created content) rather than built-in campaigns.


Core State Management

Methods

public void Apply()

Applies the current GameState values to their respective game systems. Sets the static instance, updates network session ID, level editor state, checkpoint data, and other persistent values. Called after loading to restore game state.


public void ClearSuperCheckPointStatus()

Clears all super checkpoint related data, resetting the load offsets and checkpoint position. Called when starting fresh or when checkpoint data should be discarded.


public void FullRefresh()

Performs a complete refresh of the GameState by pulling current values from various game systems. Updates session ID, scene name, level editor status, publish run data, and checkpoint information. Used before scene transitions to ensure state consistency.


public void PickRandomSeed()

Generates a new random seed based on the current time's millisecond value. Called during GameState construction and when a new random seed is needed.


public void ResetToDefault()

Resets all GameState values to their default states. This includes clearing scene data, campaign info, game modes, level editor status, and checkpoint data. Commonly called when returning to main menu or starting a new game session.


public void SelectiveRefresh()

Performs a selective refresh of the GameState, updating only session ID, scene name, level editor status, and publish run data. Does not update checkpoint-related data. Used for lighter state updates.


public override string ToString()

Returns a formatted string representation of all GameState values for debugging purposes. Includes scene info, campaign data, session details, game modes, checkpoint status, and other state information.

Returns:

  • string: A multi-line string containing all GameState values formatted for debug output.

Scene Transition

Methods

public static void FadeToNextScene(string nextScene = "")

Initiates a fade transition to the next scene. Blocks input during the fade, sets up the scene to load, and triggers the fade effect. Disables audio low pass filter for the transition.

Parameters:

  • string nextScene: Optional scene name to load. If empty, uses the scene stored in GameState.sceneToLoad.

public static bool GoBackToFreshMainMenuFromAnywhere()

Attempts to return to the main menu from any game screen or state. Handles different scenarios including being in menus, world map, hero select, or during loading. Returns false if unable to determine current state.

Returns:

  • bool: True if successfully initiated return to main menu, false if current state couldn't be determined.

public static void LoadLevel(string nextScene = "")

Loads the specified level or scene, handling all necessary setup including network handshakes, scene type detection, and custom campaign loading. This is the main method for transitioning between game scenes.

Parameters:

  • string nextScene: Optional scene name to load. If empty, uses the scene stored in GameState.sceneToLoad.

private static void OnCustomLevelLoad(Campaign camp)

Callback method invoked when a custom level finishes loading from Playtomic. Sets the loaded campaign as current and initiates the scene transition.

Parameters:

  • Campaign camp: The campaign data that was loaded from the online service.

Properties

public string sceneToLoad { get; set; }

Gets or sets the name of the scene that should be loaded next. This property is used to coordinate scene transitions throughout the game.


Fields

private static bool _blockInputForFade

Tracks whether input was blocked specifically for scene fade transitions. Used to properly restore input state after fade operations complete.


private string _sceneToLoad = string.Empty

Private backing field for the sceneToLoad property. Stores the name of the next scene to load.


Level Editor

Fields

public GameMode gameMode = GameMode.NotSet

The current game mode (Campaign, ExplosionRun, DeathMatch, BroDown, SuicideHorde, Cutscene, Race, or NotSet). Determines gameplay rules and objectives for the current session.


public bool levelEditorActive

Indicates whether the level editor is currently active. Synchronized with LevelEditorGUI.levelEditorActive during state refresh operations.


public MapLoadMode loadMode = MapLoadMode.NotSet

Specifies how the map should be loaded (Campaign, LoadFromMapdata, LoadFromFile, Generated, or NotSet). This determines the loading strategy when transitioning to a new level.


public bool publishRun

Indicates whether the current session is a publish run for testing a level before uploading. Synchronized with GameModeController.publishRun during state refresh operations.


public bool publishRunSuccessful

Indicates whether the publish run was completed successfully. Synchronized with LevelEditorGUI.publishRunSuccessful during state refresh operations.


World Map & Navigation

Fields

public bool immediatelyGoToCustomCampaign

Flag to bypass menus and immediately load a custom campaign. Used for quick-loading user-created content from various menu screens.


public bool returnToWorldMap

Flag indicating whether the game should return to the world map after the current level. Used to control navigation flow between levels and the campaign map.


public bool startNewWorldMapGame

Flag indicating whether to start a new world map campaign game. Used when initiating a fresh campaign playthrough from the main menu.


Checkpoint & Spawn Management

Fields

public int nextXLoadOffset

The X-axis offset for the next map load position. Used with super checkpoints to determine spawn location when continuing from a checkpoint.


public int nextYLoadOffset

The Y-axis offset for the next map load position. Used with super checkpoints to determine spawn location when continuing from a checkpoint.


public bool persistPastLevelLoad

Determines whether certain game elements should persist when loading a new level. Used to maintain continuity for specific objects or state across level transitions.


public bool startFromSuperCheckPoint

Indicates whether the level should start from a super checkpoint position. When true, uses superCheckpointStartPos to determine spawn location.


public GridPoint superCheckpointStartPos = new GridPoint()

The grid position where players should spawn when starting from a super checkpoint. Only used when startFromSuperCheckPoint is true.


Save Game & Progress

Properties

public bool hardCoreMode { get; set; }

Gets whether the game is currently in hardcore mode (Iron Bro mode). This mode features permanent death and is only available in world map campaigns.


public bool hardMode { get; set; }

Gets whether the game is currently in hard mode. Returns the world map hard mode status if in a world map campaign, otherwise returns arcade hard mode status.


Fields

public bool arcadeHardMode

Hard mode setting for arcade (non-world map) game modes. Used when currentWorldmapSave is null or not in a world map campaign.


public WorldMapProgressSaveSlot currentWorldmapSave

The current world map save slot data containing campaign progress. Holds information about unlocked levels, collected items, and difficulty settings for the active campaign.


Map Generation

Fields

public int mapGenSeed

The seed value used for procedural map generation when useRandomMapGenSeed is true. Allows for reproducible randomly generated levels.


public int randomSeed = 1

The random seed used for level generation and other randomized game elements. Used to ensure consistency in procedural generation.


public bool useRandomMapGenSeed

Determines whether to use a specific seed for map generation. When true, uses mapGenSeed value; when false, uses default generation behavior.