State Manager¶
- class game_state.StateManager(window)¶
The State Manager used for managing multiple State(s).
- Parameters:
window (
Surface) – The main game window.
- change_state(state_name)¶
Changes the current state and updates the last state.
- connect_state_hook(path, **kwargs)¶
Calls the hook function of the state file.
- exit_game(**kwargs)¶
Exits the entire game.
- get_current_state()¶
Gets the current State instance.
- get_last_state()¶
Gets the previous State instance.
- get_state_map()¶
Gets the dictionary copy of all states.
- load_states(*states, force=False, **kwargs)¶
Loads the States into the StateManager.
- Parameters:
- The States to be loaded into the manager.
force (
bool) –DefaultFalse.Loads the State regardless of whether the State has already been loaded or notwithout raising any internal error.WARNING: If set toTrueit may lead to unexpected behavior.**kwargs (
Any) –The keyword arguments to be passed to the State’s subclass on instantiation.
- Raises:
StateLoadError- Raised when the state has already been loaded.Only raised when
forceis set toFalse.
- Return type:
- reload_state(state_name, force=False, **kwargs)¶
Reloads the specified State. A short hand to
StateManager.unload_state&StateManager.load_state.- Parameters:
state_name (
str) –TheStatename to be reloaded.force (
bool) –DefaultFalse.Reloads the State even if it’s an actively running State withoutraising any internal error.WARNING: If set toTrueit may lead to unexpected behavior.**kwargs (
Any) –The keyword arguments to be passed to theStateManager.unload_state&StateManager.load_state.
- Return type:
- Returns:
- Returns the newly made
Stateinstance. - Raises:
StateLoadError- Raised when the state has already been loaded.
- run_state(**kwargs)¶
The entry point to running the StateManager. To be only called once. For changing
States useStateManager.change_state&StateManager.update_state
- unload_state(state_name, force=False, **kwargs)¶
Unloads the
Statefrom theStateManager.- Parameters:
state_name (
str) –The State to be loaded into the manager.force (
bool) –DefaultFalse.Unloads the State even if it’s an actively running State without raising anyinternal error.WARNING: If set toTrueit may lead to unexpected behavior.**kwargs (
Any) –The keyword arguments to be passed on to the raised errors.
- Return type:
- Returns:
- The
Stateclass of the deleted State name. - Raises:
StateLoadError- Raised when the state doesn’t exist in the manager to be unloaded.
StateError- Raised when trying to unload an actively running State.Only raised when
forceis set toFalse.
- update_state(**kwargs)¶
Updates the changed State to take place.