mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Allow adjusting TOTs after sim start.
This makes the start time in WaitingForStart dynamic, which is more expensive but probably still cheap enough. It also checks that the new TOT will not result in a start time in the past when the player changes the TOT. https://github.com/dcs-liberation/dcs_liberation/issues/1680
This commit is contained in:
parent
c6a8aeac1d
commit
ba10298dbc
@ -24,13 +24,10 @@ class FlightState(ABC):
|
||||
def reinitialize(self, now: datetime) -> None:
|
||||
from game.ato.flightstate import WaitingForStart
|
||||
|
||||
start_time = self.flight.flight_plan.startup_time()
|
||||
if start_time <= now:
|
||||
if self.flight.flight_plan.startup_time() <= now:
|
||||
self._set_active_flight_state(now)
|
||||
else:
|
||||
self.flight.set_state(
|
||||
WaitingForStart(self.flight, self.settings, start_time)
|
||||
)
|
||||
self.flight.set_state(WaitingForStart(self.flight, self.settings))
|
||||
|
||||
def _set_active_flight_state(self, now: datetime) -> None:
|
||||
from game.ato.flightstate import StartUp
|
||||
|
||||
@ -18,19 +18,17 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class WaitingForStart(AtDeparture):
|
||||
def __init__(
|
||||
self,
|
||||
flight: Flight,
|
||||
settings: Settings,
|
||||
start_time: datetime,
|
||||
) -> None:
|
||||
def __init__(self, flight: Flight, settings: Settings) -> None:
|
||||
super().__init__(flight, settings)
|
||||
self.start_time = start_time
|
||||
|
||||
@property
|
||||
def start_type(self) -> StartType:
|
||||
return self.flight.start_type
|
||||
|
||||
@property
|
||||
def start_time(self) -> datetime:
|
||||
return self.flight.flight_plan.startup_time()
|
||||
|
||||
def on_game_tick(
|
||||
self, events: GameUpdateEvents, time: datetime, duration: timedelta
|
||||
) -> None:
|
||||
|
||||
@ -185,10 +185,18 @@ class PackageModel(QAbstractListModel):
|
||||
"""Returns the flight located at the given index."""
|
||||
return self.package.flights[index.row()]
|
||||
|
||||
def set_tot(self, tot: datetime.datetime) -> None:
|
||||
def set_tot(self, tot: datetime.datetime) -> datetime:
|
||||
with self.game_model.sim_controller.paused_sim():
|
||||
previous_tot = self.package.time_over_target
|
||||
self.package.time_over_target = tot
|
||||
for flight in self.package.flights:
|
||||
if (
|
||||
flight.flight_plan.startup_time()
|
||||
< self.game_model.sim_controller.current_time_in_sim
|
||||
):
|
||||
self.package.time_over_target = previous_tot
|
||||
self.update_tot()
|
||||
return self.package.time_over_target
|
||||
|
||||
def set_asap(self, asap: bool) -> None:
|
||||
with self.game_model.sim_controller.paused_sim():
|
||||
|
||||
@ -149,11 +149,12 @@ class QPackageDialog(QDialog):
|
||||
def save_tot(self) -> None:
|
||||
# TODO: This is going to break horribly around midnight.
|
||||
time = self.tot_spinner.time()
|
||||
self.package_model.set_tot(
|
||||
tot = self.package_model.set_tot(
|
||||
self.package_model.package.time_over_target.replace(
|
||||
hour=time.hour(), minute=time.minute(), second=time.second()
|
||||
)
|
||||
)
|
||||
self.tot_spinner.setTime(self.tot_qtime())
|
||||
|
||||
def set_asap(self, checked: bool) -> None:
|
||||
self.package_model.set_asap(checked)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user