mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Deepcopy of waypoints for cloned flights
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user