mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix adding and removing waypoints in the UI.
This moves more of the logic out of the UI so mypy can actually spot these mistakes more often. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2495.
This commit is contained in:
parent
98e8fc88bd
commit
219b52fc12
@ -91,6 +91,12 @@ class Flight(SidcDescribable):
|
||||
def flight_plan(self) -> FlightPlan[Any]:
|
||||
return self._flight_plan_builder.get_or_build()
|
||||
|
||||
def degrade_to_custom_flight_plan(self) -> None:
|
||||
from .flightplans.custom import Builder as CustomBuilder
|
||||
|
||||
self._flight_plan_builder = CustomBuilder(self, self.flight_plan.waypoints[1:])
|
||||
self.recreate_flight_plan()
|
||||
|
||||
def __getstate__(self) -> dict[str, Any]:
|
||||
state = self.__dict__.copy()
|
||||
# Avoid persisting the flight state since that's not (currently) used outside
|
||||
|
||||
@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Type
|
||||
from .flightplan import FlightPlan, Layout
|
||||
from .ibuilder import IBuilder
|
||||
from .waypointbuilder import WaypointBuilder
|
||||
from .. import Flight
|
||||
from ..flightwaypointtype import FlightWaypointType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -55,9 +56,17 @@ class CustomFlightPlan(FlightPlan[CustomLayout]):
|
||||
|
||||
|
||||
class Builder(IBuilder[CustomFlightPlan, CustomLayout]):
|
||||
def __init__(
|
||||
self, flight: Flight, waypoints: list[FlightWaypoint] | None = None
|
||||
) -> None:
|
||||
super().__init__(flight)
|
||||
if waypoints is None:
|
||||
waypoints = []
|
||||
self.waypoints = waypoints
|
||||
|
||||
def layout(self) -> CustomLayout:
|
||||
builder = WaypointBuilder(self.flight, self.coalition)
|
||||
return CustomLayout(builder.takeoff(self.flight.departure), [])
|
||||
return CustomLayout(builder.takeoff(self.flight.departure), self.waypoints)
|
||||
|
||||
def build(self) -> CustomFlightPlan:
|
||||
return CustomFlightPlan(self.flight, self.layout())
|
||||
|
||||
@ -13,7 +13,7 @@ from PySide2.QtWidgets import (
|
||||
|
||||
from game import Game
|
||||
from game.ato.flight import Flight
|
||||
from game.ato.flightplans.custom import CustomFlightPlan, CustomLayout
|
||||
from game.ato.flightplans.custom import CustomFlightPlan
|
||||
from game.ato.flightplans.formationattack import FormationAttackFlightPlan
|
||||
from game.ato.flightplans.planningerror import PlanningError
|
||||
from game.ato.flightplans.waypointbuilder import WaypointBuilder
|
||||
@ -147,15 +147,7 @@ class QFlightWaypointTab(QFrame):
|
||||
|
||||
def degrade_to_custom_flight_plan(self) -> None:
|
||||
if not isinstance(self.flight.flight_plan, CustomFlightPlan):
|
||||
self.flight.flight_plan = CustomFlightPlan(
|
||||
self.flight,
|
||||
CustomLayout(
|
||||
departure=WaypointBuilder(self.flight, self.coalition).takeoff(
|
||||
self.flight.departure
|
||||
),
|
||||
custom_waypoints=self.flight.flight_plan.waypoints[1:],
|
||||
),
|
||||
)
|
||||
self.flight.degrade_to_custom_flight_plan()
|
||||
|
||||
def confirm_recreate(self, task: FlightType) -> None:
|
||||
result = QMessageBox.question(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user