mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add a UUID -> Flight database to Game.
This will be expanded with other types as needed.
This commit is contained in:
2
game/db/__init__.py
Normal file
2
game/db/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .database import Database
|
||||
from .gamedb import GameDb
|
||||
20
game/db/database.py
Normal file
20
game/db/database.py
Normal 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
11
game/db/gamedb.py
Normal 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()
|
||||
Reference in New Issue
Block a user