Sync package wpts when primary flight's wpts change

Also recreates all other flight-plans in the package to ensure JOIN, INGRESS & SPLIT are updated
This commit is contained in:
Raffson
2024-10-28 23:45:04 +01:00
parent b124c6cc61
commit 6a5097659b
3 changed files with 40 additions and 6 deletions

View File

@@ -78,5 +78,32 @@ def set_position(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Could not find PackageModel owning {flight}",
)
events = GameUpdateEvents()
update_package_waypoints_if_primary_flight(waypoint, flight, events)
package_model.update_tot()
EventStream.put_nowait(GameUpdateEvents().update_flight(flight))
EventStream.put_nowait(events.update_flight(flight))
def update_package_waypoints_if_primary_flight(
waypoint: FlightWaypoint,
flight: Flight,
events: GameUpdateEvents,
) -> None:
wpts = flight.package.waypoints
if flight is flight.package.primary_flight and wpts:
if waypoint.waypoint_type is FlightWaypointType.JOIN:
wpts.join = waypoint.position
elif waypoint.waypoint_type is FlightWaypointType.SPLIT:
wpts.split = waypoint.position
elif waypoint.waypoint_type is FlightWaypointType.REFUEL:
wpts.refuel = waypoint.position
elif "INGRESS" in waypoint.waypoint_type.name:
wpts.ingress = waypoint.position
wpts.initial = wpts.get_initial_point(
waypoint.position, flight.package.target.position
)
for f in flight.package.flights:
if f is flight:
continue
f.recreate_flight_plan()
events.update_flight(f)