Utils

class game_state.utils.StateArgs(*, state_name, **kwargs)

A dataclass to send data to states while loading them in the manager.

Added in version 2.1.

Parameters:
  • state_name (str) –

    The name of the state which the argument belongs to.

  • kwargs (Any) –

    The data that needs to be sent.

get_data()

Returns the data to be passed on to the state. The data returned does not contain state_name in it.

Added in version 2.1.

Return type:

Dict[str, Any]

Returns:

The data of the state arg. Does not include state_name in it.

game_state.utils.MISSING = _MissingSentinel()

Used in areas where an attribute doesn’t have a value by default but gets defined during runtime. Lesser type checking would be required by using this, opposed to using some other default value such as None.

Added in version 2.0.1.

game_state.utils.setup_logging(*, handler=None, formatter=None, level=None, root=True) = <function setup_logging>

A helper function to setup logging.

This is superficially similar to logging.basicConfig() but uses different defaults and a colour formatter if the stream can display colour.

Added in version 2.4.

Parameters:
  • handler (Optional[Handler]) –

    The log handler to use for the library’s logger.

    The default log handler if not provided is logging.StreamHandler.

  • formatter (Optional[Formatter]) –

    The formatter to use with the given log handler.
    If not provided then it defaults to a colour based logging formatter (if available).
    If colour is not available then a simple logging formatter is provided.

  • level (Optional[int]) –

    The default log level for the library’s logger. Defaults to logging.DEBUG.

  • root (bool) –

    Whether to set up the root logger rather than the library logger.

Return type:

None