yawning_titan.game_modes.game_mode_db#

Provides an API for the game_mode.json TinyDB file, and a Schema class that defines the game_mode DB fields.

Functions

dcbo_game_mode

The DCBO game mode.

default_game_mode

The default Yawning Titan game mode.

Classes

GameModeDB

The GameModeDB class extends YawningTitanDB.

GameModeSchema

A schema-like class that defines the game_mode DB fields.

class yawning_titan.game_modes.game_mode_db.GameModeDB[source]#

The GameModeDB class extends YawningTitanDB.

The below code blocks demonstrate how to use the GameModeDB class.

  • Instantiate the GameMode DB:

    >>> from yawning_titan.game_modes.game_mode_db import GameModeDB, GameModeSchema
    >>> db = GameModeDB()
    
  • Search for all game modes that work with a minimum of 18 nodes in the game_mode:

    >>> db.search(GameModeSchema.NODE_COUNT.min(18))
    
__init__()[source]#
insert(game_mode, name=None, description=None, author=None)[source]#

Insert a GameMode into the DB as .json.

Parameters:
Returns:

The inserted GameMode.

all()[source]#

Get all GameMode from the game mode DB.

Returns:

A list of GameMode.

show(verbose=False)[source]#

Show details of all entries in the db.

Parameters:

verbose – If True, all doc metadata details are shown, otherwise just the name is shown.

get(uuid)[source]#

Get a game_mode config document from its uuid.

Parameters:

uuid – A target document uuid.

Returns:

The game_mode config document as an instance of :class:~yawning_titan.game_modes.game_mode.GameMode` if the uuid exists, otherwise None.

search(query)[source]#

Searches the GameMode with a GameModeSchema query.

Parameters:

query – A YawningTitanQuery.

Returns:

A list of GameMode.

count(cond=None)[source]#

Count how many docs are in the db. Extends tinydb.table.Table.count.

A YawningTitanQuery can be used to filter the count.

Parameters:

cond – An optional YawningTitanQuery. Has a default value of None.

Returns:

The number of docs counted.

update(game_mode, name=None, description=None, author=None)[source]#

Update a GameMode. in the db.

Parameters:
  • game_mode – An instance of GameMode.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The updated GameMode.

upsert(game_mode, name=None, description=None, author=None)[source]#

Upsert a GameMode. in the db.

Parameters:
  • game_mode – An instance of GameMode.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The upserted GameMode.

remove(game_mode)[source]#

Remove a GameMode. from the db.

Parameters:

game_mode – An instance of GameMode.

Returns:

The uuid of the removed GameMode.

remove_by_cond(cond)[source]#

Remove GameMode. from the db that match the query.

Parameters:

cond – A YawningTitanQuery.

Returns:

The list of uuids of the removed GameMode.

reset_default_game_modes_in_db(force=False)[source]#

Reset the default game_mode in the db.

Achieves this by loading the default yawning_titan/game_modes/_package_data/game_mode.json db file into TinyDB, then iterating over all docs and forcing an update of each one in the main game_modes db from its uuid if they do not match.

Parameters:

force – Forces a reset without checking for equality when True. Has a default value of False.

rebuild_db()[source]#

Rebuild the db.

Actions taken:

Warning

This function completely rebuilds the database. Any custom game_modes saved in the db will be lost. The default game_modes can be reset using the reset_default_game_modes_in_db() function.

add_yaml_game_modes_to_db(directory=None)[source]#

Add all yaml game modes in a given directory to the database.

Parameters:

directory – The directory containing the files to add as a Path.

class yawning_titan.game_modes.game_mode_db.GameModeSchema[source]#

A schema-like class that defines the game_mode DB fields.

Fields are defined using the YawningTitanQuery class so that schema paths can be used directly within tinydb.table.Table.search() function calls. All fields are mapped to a property in the :class:~`yawning_titan.game_modes.game_mode.GameMode` class.

Example:

>>> from yawning_titan.game_modes.game_mode_db import GameModeDB, GameModeSchema
>>> db = GameModeDB()
>>> game_modes = db.search(GameModeSchema.NODE_COUNT.min(18))
CONFIGURATION#

Use this to access the full schema of the database structured in the same nested format as :class:~`yawning_titan.game_modes.game_mode.GameMode`.

alias of GameModeConfigurationSchema