Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Send event when a flight plan is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
jdno committed Mar 14, 2022
1 parent d2cdf94 commit 59f2570
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/atc-game/src/systems/update_flight_plan.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
use bevy::prelude::*;

use crate::command::CommandBus;
use crate::command::{Command, CommandBus};
use crate::components::{AirplaneId, FlightPlan};
use crate::Command;
use crate::event::{Event, EventBus};

pub fn update_flight_plan(
mut query: Query<(&AirplaneId, &mut FlightPlan)>,
mut command_bus: Local<CommandBus>,
event_bus: Local<EventBus>,
) {
while let Ok(command) = command_bus.receiver().try_recv() {
let Command::UpdateFlightPlan(airplane_id, new_flight_plan) = command;

for (id, mut current_flight_plan) in query.iter_mut() {
if *id == airplane_id {
*current_flight_plan = new_flight_plan;
*current_flight_plan = new_flight_plan.clone();

event_bus
.sender()
.send(Event::FlightPlanUpdated(
airplane_id.clone(),
new_flight_plan,
))
.expect("failed to send event"); // TODO: Handle error

break;
}
}
Expand Down

0 comments on commit 59f2570

Please sign in to comment.