use bevy::ecs::system::{Commands, Query, Resource}; use clap::Parser; use guardian_commands::{ConsoleCommand, NamedCommand}; use guardian_core::{components::*, dcs::text::TextMessage, srs::voice::VoiceMessage}; use crate::tripwire::Tripwire; #[derive(Parser, Debug)] pub struct ClearTripwireCommand; impl NamedCommand for ClearTripwireCommand { fn name() -> &'static str { "clear [tripwire|warning]" } } impl Resource for ClearTripwireCommand {} pub fn clear_tripwire( mut commands: Commands, mut cmd: ConsoleCommand, callsign: Query<&Callsign>, ) { let Some(Ok(ClearTripwireCommand)) = cmd.take() else { return; }; let Some(pilot) = &cmd.pilot else { return; // no pilot }; let Some(operator) = &cmd.operator else { eprintln!("no operator"); return; }; let Ok(p_callsign) = callsign.get(*pilot) else { eprintln!("no player, died?"); return; }; let Ok(a_callsign) = callsign.get(*operator) else { eprintln!("no awacs, they died?"); return; }; commands.entity(*pilot).remove::(); let message = format!("{}, {}, tripwire cleared", p_callsign, a_callsign); let message_voice = format!( "{}, {}, tripwire cleared", p_callsign.to_voice(), a_callsign.to_voice(), ); commands.spawn(TextMessage::new(message)); commands .entity(*operator) .insert(VoiceMessage::new(message_voice)); }