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
The DCBO game mode. |
|
The default Yawning Titan game mode. |
Classes
The |
|
A schema-like class that defines the game_mode DB fields. |
- class yawning_titan.game_modes.game_mode_db.GameModeDB[source]#
The
GameModeDB
class extendsYawningTitanDB
.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))
- insert(game_mode, name=None, description=None, author=None)[source]#
Insert a
GameMode
into the DB as.json
.- Parameters:
game_mode – An instance of
GameMode
DocMetadata
.DocMetadata
.DocMetadata
.name – The config name.
description – The config description.
author – The config author.
- Returns:
The inserted
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 aGameModeSchema
query.- Parameters:
query – A
YawningTitanQuery
.- Returns:
- 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 ofNone
.- Returns:
The number of docs counted.
- 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:
clear the query cache
truncate the db
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.
- 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 withintinydb.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