Un-dataclass Package.

This hasn't been very dataclass-like for a long time.
This commit is contained in:
Dan Albert 2022-09-02 20:16:02 -07:00
parent 71f68b3103
commit f4ecfe6da9

View File

@ -2,9 +2,8 @@ from __future__ import annotations
import logging import logging
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass, field
from datetime import timedelta from datetime import timedelta
from typing import Dict, List, Optional, TYPE_CHECKING from typing import Dict, Optional, TYPE_CHECKING
from game.db import Database from game.db import Database
from game.utils import Speed from game.utils import Speed
@ -19,28 +18,24 @@ if TYPE_CHECKING:
from game.theater import ControlPoint, MissionTarget from game.theater import ControlPoint, MissionTarget
@dataclass
class Package: class Package:
"""A mission package.""" """A mission package."""
#: The mission target. Currently can be either a ControlPoint or a def __init__(
#: TheaterGroundObject (non-ControlPoint map objectives). self, target: MissionTarget, db: Database[Flight], auto_asap: bool = False
target: MissionTarget ) -> None:
self.target = target
self._db = db
_db: Database[Flight] # True if the package ToT should be reset to ASAP whenever the player makes a
# change. This is really a UI property rather than a game property, but we want
# it to persist in the save.
self.auto_asap = auto_asap
self.flights: list[Flight] = []
#: The set of flights in the package. # Desired TOT as an offset from mission start.
flights: List[Flight] = field(default_factory=list) self.time_over_target: timedelta = timedelta()
self.waypoints: PackageWaypoints | None = None
#: True if the package ToT should be reset to ASAP whenever the player makes
#: a change. This is really a UI property rather than a game property, but
#: we want it to persist in the save.
auto_asap: bool = field(default=False)
#: Desired TOT as an offset from mission start.
time_over_target: timedelta = field(default=timedelta())
waypoints: Optional[PackageWaypoints] = field(default=None)
@property @property
def has_players(self) -> bool: def has_players(self) -> bool:
@ -209,7 +204,3 @@ class Package:
if flight.departure == airfield: if flight.departure == airfield:
return airfield return airfield
raise RuntimeError("Could not find any airfield assigned to this package") raise RuntimeError("Could not find any airfield assigned to this package")
def __hash__(self) -> int:
# TODO: Far from perfect. Number packages?
return hash(self.target.name)