Add a UUID -> Flight database to Game.

This will be expanded with other types as needed.
This commit is contained in:
Dan Albert
2022-02-19 12:46:29 -08:00
parent ab6f44cb6f
commit cba68549d8
14 changed files with 89 additions and 53 deletions

2
game/db/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
from .database import Database
from .gamedb import GameDb

20
game/db/database.py Normal file
View File

@@ -0,0 +1,20 @@
from typing import Generic, TypeVar
from uuid import UUID
T = TypeVar("T")
class Database(Generic[T]):
def __init__(self) -> None:
self.objects: dict[UUID, T] = {}
def add(self, uuid: UUID, obj: T) -> None:
if uuid in self.objects:
raise KeyError(f"Object with UUID {uuid} already exists")
self.objects[uuid] = obj
def get(self, uuid: UUID) -> T:
return self.objects[uuid]
def remove(self, uuid: UUID) -> None:
del self.objects[uuid]

11
game/db/gamedb.py Normal file
View File

@@ -0,0 +1,11 @@
from typing import TYPE_CHECKING
from .database import Database
if TYPE_CHECKING:
from game.ato import Flight
class GameDb:
def __init__(self) -> None:
self.flights: Database[Flight] = Database()