dcs_liberation/game/db/database.py
Dan Albert cba68549d8 Add a UUID -> Flight database to Game.
This will be expanded with other types as needed.
2022-02-19 12:57:41 -08:00

21 lines
508 B
Python

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]