Handle IADS updates properly.

This adds the missing events in the backend, and handles them properly in the front end.
This commit is contained in:
Raffson
2022-06-30 03:58:49 +02:00
committed by GitHub
parent 5f071a6138
commit 27dff95df5
7 changed files with 47 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ from game.server.combat.models import FrozenCombatJs
from game.server.controlpoints.models import ControlPointJs
from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs
from game.server.iadsnetwork.models import IadsConnectionJs
from game.server.leaflet import LeafletPoint
from game.server.mapzones.models import UnculledZoneJs
@@ -34,6 +35,8 @@ class GameUpdateEventsJs(BaseModel):
deleted_front_lines: set[UUID]
updated_tgos: set[UUID]
updated_control_points: list[ControlPointJs]
updated_iads: list[IadsConnectionJs]
deleted_iads: set[UUID]
reset_on_map_center: LeafletPoint | None
game_unloaded: bool
new_turn: bool
@@ -48,6 +51,7 @@ class GameUpdateEventsJs(BaseModel):
new_combats = []
updated_combats = []
updated_unculled_zones = []
updated_iads = []
if game is not None:
new_combats = [
FrozenCombatJs.for_combat(c, game.theater) for c in events.new_combats
@@ -57,6 +61,8 @@ class GameUpdateEventsJs(BaseModel):
for c in events.updated_combats
]
updated_unculled_zones = UnculledZoneJs.from_game(game)
for node in events.updated_iads:
updated_iads.extend(IadsConnectionJs.connections_for_node(node))
return GameUpdateEventsJs(
updated_flight_positions={
@@ -87,6 +93,8 @@ class GameUpdateEventsJs(BaseModel):
ControlPointJs.for_control_point(cp)
for cp in events.updated_control_points
],
updated_iads=updated_iads,
deleted_iads=events.deleted_iads_connections,
reset_on_map_center=events.reset_on_map_center,
game_unloaded=events.game_unloaded,
new_turn=events.new_turn,

View File

@@ -12,6 +12,7 @@ if TYPE_CHECKING:
from game.ato import Flight, Package
from game.sim.combat import FrozenCombat
from game.theater import ControlPoint, FrontLine, TheaterGroundObject
from game.theater.iadsnetwork.iadsnetwork import IadsNetworkNode
@dataclass
@@ -33,6 +34,8 @@ class GameUpdateEvents:
deleted_front_lines: set[UUID] = field(default_factory=set)
updated_tgos: set[UUID] = field(default_factory=set)
updated_control_points: set[ControlPoint] = field(default_factory=set)
updated_iads: set[IadsNetworkNode] = field(default_factory=set)
deleted_iads_connections: set[UUID] = field(default_factory=set)
reset_on_map_center: LatLng | None = None
game_unloaded: bool = False
new_turn: bool = False
@@ -121,6 +124,14 @@ class GameUpdateEvents:
self.updated_control_points.add(control_point)
return self
def update_iads_node(self, iads_node: IadsNetworkNode) -> GameUpdateEvents:
self.updated_iads.add(iads_node)
return self
def delete_iads_connection(self, connection_id: UUID) -> GameUpdateEvents:
self.deleted_iads_connections.add(connection_id)
return self
def game_loaded(self, game: Game | None) -> GameUpdateEvents:
if game is None:
self.game_unloaded = True

View File

@@ -843,7 +843,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
tgo, VehicleGroupGroundObject
):
if isinstance(tgo, IadsGroundObject):
game.theater.iads_network.update_tgo(tgo)
game.theater.iads_network.update_tgo(tgo, events)
conflict_heading = game.theater.heading_to_conflict_from(tgo.position)
tgo.rotate(conflict_heading or tgo.heading)
if not tgo.is_control_point:

View File

@@ -18,6 +18,7 @@ from game.theater.theatergroup import IadsGroundGroup
if TYPE_CHECKING:
from game.game import Game
from game.sim import GameUpdateEvents
class IadsNetworkException(Exception):
@@ -133,19 +134,21 @@ class IadsNetwork:
skynet_nodes.append(skynet_node)
return skynet_nodes
def update_tgo(self, tgo: TheaterGroundObject) -> None:
def update_tgo(self, tgo: TheaterGroundObject, events: GameUpdateEvents) -> None:
"""Update the IADS Network for the given TGO"""
# Remove existing nodes for the given tgo
for cn in self.nodes:
if cn.group.ground_object == tgo:
self.nodes.remove(cn)
for cID in cn.connections:
events.delete_iads_connection(cID)
# Create a new node for the tgo
node = self.node_for_tgo(tgo)
if node is None:
# Not participating
return
# TODO Add the connections or calculate them..
events.update_iads_node(node)
def node_for_group(self, group: IadsGroundGroup) -> IadsNetworkNode:
"""Get existing node from the iads network or create a new node"""