dcs-retribution/game/server/dependencies.py
2022-03-03 02:17:13 -08:00

47 lines
1.1 KiB
Python

from __future__ import annotations
from typing import Callable, TYPE_CHECKING
from game.theater import MissionTarget
if TYPE_CHECKING:
from game import Game
from qt_ui.models import GameModel
class GameContext:
_game_model: GameModel
@classmethod
def set_model(cls, game_model: GameModel) -> None:
cls._game_model = game_model
@classmethod
def get(cls) -> Game:
if cls._game_model.game is None:
raise RuntimeError("GameContext has no Game set")
return cls._game_model.game
@classmethod
def get_model(cls) -> GameModel:
return cls._game_model
class QtCallbacks:
def __init__(self, create_new_package: Callable[[MissionTarget], None]) -> None:
self.create_new_package = create_new_package
class QtContext:
_callbacks: QtCallbacks
@classmethod
def set_callbacks(cls, callbacks: QtCallbacks) -> None:
cls._callbacks = callbacks
@classmethod
def get(cls) -> QtCallbacks:
if cls._callbacks is None:
raise RuntimeError("QtContext has no callbacks set")
return cls._callbacks