State Manager¶
- class game_state.StateManager(window)¶
The State Manager used for managing multiple State(s).
- Parameters:
window (
Surface) –
The State Manager’s init.
- Parameters:
window (
Surface) – The main game window.
- change_state(state_name)¶
Changes the current state and updates the last state.
Raises¶
AssertionErrorRaised when the state name doesn’t exist in the manager.
- connect_state_hook(path, **kwargs)¶
Calls the hook function of the state file.
- Parameters:
- Return type:
Raises¶
StateErrorRaised when the hook function was not found in the state file to be loaded.
- exit_game(**kwargs)¶
Exits the entire game.
- Parameters:
**kwargs (
Any) – The keyword arguments to be passed on to the raised errors.- Return type:
Raises¶
ExitGameRaised when the state has successfully exited.
- get_current_state()¶
Gets the current State instance.
Returns¶
- Optional[
State] Returns the current State instance.
- Optional[
- get_last_state()¶
Gets the previous State instance.
Returns¶
- Optional[
State] Returns the previous State instance.
- Optional[
- load_states(*states, force=False, **kwargs)¶
Loads the States into the StateManager.
- Parameters:
states (
type[State]) – The States to be loaded into the manager.force (
bool) – default False Loads the State regardless of whether the State has already been loaded or not without raising any internal error.**kwargs (
Any) – The keyword arguments to be passed to the State’s subclass on instantiation.
- Return type:
Raises¶
StateLoadErrorRaised when the state has already been loaded. Only raised when force is set to False.
- 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) – The State name to be reloaded.force (
bool) – default False Reloads the State even if it’s an actively running State without raising any internal error. WARNING: If set to `True` it may lead to unexpected behavior.**kwargs (
Any) – The keyword arguments to be passed to the StateManager.unload_state` & StateManager.load_state.
- Return type:
Returns¶
Raises¶
StateLoadErrorRaised when the state has already been loaded.
- run_state(**kwargs)¶
The entry point to running the StateManager. To be only called once. For changing State`s use `StateManager.change_state & StateManager.update_state
- Parameters:
**kwargs (
Any) – The keyword arguments to be passed on to the raised errors.- Return type:
Raises¶
StateErrorRaised when the current state is None i.e having no State to run.
- unload_state(state_name, force=False, **kwargs)¶
Unloads the State from the StateManager.
- Parameters:
*states – The States to be loaded into the manager.
force (
bool) – default False Unloads the State even if it’s an actively running State without raising any internal error. WARNING: If set to `True` it may lead to unexpected behavior.**kwargs (
Any) – The keyword arguments to be passed on to the raised errors.
- Return type:
Returns¶
Raises¶
StateLoadErrorRaised when the state doesn’t exist in the manager to be unloaded.
StateErrorRaised when trying to unload an actively running State. Only raised when force is set to False.
- param state_name:
- type state_name:
- update_state(**kwargs)¶
Updates the changed State to take place.
- Parameters:
**kwargs (
Any) – The keyword arguments to be passed on to the raised errors.- Return type:
Raises¶
ExitStateRaised when the state has successfully exited.
StateErrorRaised when the current state is None i.e having no State to update to.