Deepcopy of waypoints for cloned flights

This commit is contained in:
Raffson 2024-06-08 21:51:09 +02:00
parent 9a55b4de1c
commit b2315efb6c
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 19 additions and 1 deletions

View File

@ -1,8 +1,9 @@
from __future__ import annotations
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from typing import Literal, TYPE_CHECKING
from typing import Literal, TYPE_CHECKING, Any, Dict, Optional
from dcs import Point
@ -56,3 +57,17 @@ class FlightWaypoint:
def __hash__(self) -> int:
return hash(id(self))
def __deepcopy__(self, memo: Optional[Dict[int, Any]] = None) -> FlightWaypoint:
obj = FlightWaypoint(self.name, self.waypoint_type, self.position)
for attr in dir(self):
if attr == "control_point":
obj.control_point = self.control_point
elif attr == "targets":
obj.targets = self.targets
elif "__" in attr or attr not in obj.__dataclass_fields__:
continue
else:
attr_copy = deepcopy(getattr(self, attr))
setattr(obj, attr, attr_copy)
return obj

View File

@ -235,6 +235,7 @@ class Package(RadioFrequencyContainer):
clone.time_over_target = deepcopy(package.time_over_target)
for f in package.flights:
cf = Flight.clone_flight(f)
cf.flight_plan.layout = deepcopy(f.flight_plan.layout)
cf.package = clone
clone.add_flight(cf)
return clone

View File

@ -1,5 +1,6 @@
"""Widgets for displaying air tasking orders."""
import logging
from copy import deepcopy
from typing import Optional
from PySide6.QtCore import (
@ -143,6 +144,7 @@ class QFlightList(QListView):
)
return
self.package_model.add_flight(clone)
clone.flight_plan.layout = deepcopy(flight.flight_plan.layout)
EventStream.put_nowait(GameUpdateEvents().new_flight(clone))
def cancel_or_abort_flight(self, index: QModelIndex) -> None: