GameTemplate
Template for the different Game classes
Attributes:
Name | Type | Description |
---|---|---|
config |
MutableMapping[str, Any] |
contains the configuration from the config file |
game_io
property
readonly
Instance of GameIO
used to control the whole game loop
game_state
property
readonly
State of the game
on_end(self)
async
Executed, when the game ends
Source code in game_sdk/game.py
async def on_end(self):
"""
Executed, when the game ends
"""
logging.info("ON END")
on_exit(self, err=None)
async
Executed, when the game loop is exited
Parameters:
Name | Type | Description | Default |
---|---|---|---|
err |
Exception |
Value of the exception when the game exited with none zero code |
None |
Source code in game_sdk/game.py
async def on_exit(self, err: Exception = None):
"""
Executed, when the game loop is exited
Arguments:
err: Value of the exception when the game exited with none zero code
"""
logging.info("ON EXIT")
if err:
logging.error(err)
on_init(self)
async
Executed, when the game is startet with Game.run()
Source code in game_sdk/game.py
async def on_init(self):
"""
Executed, when the game is startet with `Game.run()`
"""
logging.info("ON INIT")
on_pregame(self)
async
Executed, before a new game starts
Source code in game_sdk/game.py
async def on_pregame(self):
"""
Executed, before a new game starts
"""
logging.info("ON PREGAME")
on_start(self)
async
Executed, when a new game starts
Source code in game_sdk/game.py
async def on_start(self):
"""
Executed, when a new game starts
"""
logging.info("ON START")
run(self, conf_path='/home/pi/Gamecontrol/config.toml', log_level=<LogLevel.NOTSET: 0>)
Start the game engine
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf_path |
str |
Path to configuration.toml |
'/home/pi/Gamecontrol/config.toml' |
log_level |
LogLevel |
logging level |
<LogLevel.NOTSET: 0> |
Source code in game_sdk/game.py
def run(self, conf_path: str = '/home/pi/Gamecontrol/config.toml', log_level: LogLevel = LogLevel.NOTSET):
"""
Start the game engine
Arguments:
conf_path: Path to configuration.toml
log_level: logging level
"""
logging.getLogger().setLevel(log_level.value)
try:
try:
self.config = toml.load(conf_path)
logging.info("Config: \n%s", self.config)
except FileNotFoundError:
raise ConfigNotFound()
loop = asyncio.get_event_loop()
loop.run_until_complete(self._run())
except ConfigNotFound as err:
logging.error("No config found at: %s", conf_path)
except KeyboardInterrupt:
logging.info("Keyboard Interrupt")
finally:
loop = asyncio.get_event_loop()
loop.run_until_complete(self._on_exit())