yawning_titan.game_modes.game_mode_db.GameModeDB#
- class yawning_titan.game_modes.game_mode_db.GameModeDB[source]#
Bases:
object
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))
Methods
Add all yaml game modes in a given directory to the database.
Get all
GameMode
from the game mode DB.Count how many docs are in the db.
Get a game_mode config document from its uuid.
Insert a
GameMode
into the DB as.json
.Rebuild the db.
Remove a
GameMode
.Remove
GameMode
.Reset the default game_mode in the db.
Searches the
GameMode
with aGameModeSchema
query.Show details of all entries in the db.
Update a
GameMode
.Upsert a
GameMode
.- 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.