/// In charge of updating/removing the TurnDisplayer struct
In charge of updating/removing the TurnDisplayer struct
In charge of updating / removing the TurnDisplayer struct
pub fn update_turn_animations(
  mut commands: Commands,
  time: ResMut<Time>,
  mut turn_phase_events: EventWriter<StartTurn>,
  mut turn_end_events: EventWriter<EndTurn>,
  mut player_animation_q: Query<
    (Entity, &mut TurnDisplayer),
    (With<PlayerTurnAnimating>, Without<EnemyTurnAnimating>),
  >,
  mut enemy_animation_q: Query<
    (Entity, &mut TurnDisplayer),
    (With<EnemyTurnAnimating>, Without<PlayerTurnAnimating>),
  >,
) {
  let is_player_animating = !player_animation_q.is_empty();
  let is_enemy_animation = !enemy_animation_q.is_empty();
  // can't do both at once
  assert!(!(is_player_animating && is_enemy_animation));
  if let Ok((e, mut displayer)) = player_animation_q
    .get_single_mut()
    .or(enemy_animation_q.get_single_mut())
  {
    displayer.timer.tick(time.delta());
    if displayer.timer.finished() {
      commands.entity(e).despawn_recursive();
      if is_player_animating {
        turn_phase_events.send(StartTurn(TurnStatus::EnemyRunning));
      } else if is_enemy_animation {
        turn_end_events.send(EndTurn);
      } else {
        panic!("TurnDisplayer component exists without marker!");
      }
    }
  }
}
pub fn update_turn_animations ( mut commands : Commands , time : ResMut < Time > , mut turn_phase_events : EventWriter < StartTurn > , mut turn_end_events : EventWriter < EndTurn > , mut player_animation_q : Query < ( Entity , & mut TurnDisplayer ) , ( With < PlayerTurnAnimating > , Without < EnemyTurnAnimating > ) , > , mut enemy_animation_q : Query < ( Entity , & mut TurnDisplayer ) , ( With < EnemyTurnAnimating > , Without < PlayerTurnAnimating > ) , > , ) { let is_player_animating = ! player_animation_q . is_empty ( ) ; let is_enemy_animation = ! enemy_animation_q . is_empty ( ) ; // can't do both at once assert ! ( ( is_player_animating is_enemy_animation ) ) ; if let Ok ( ( e , mut displayer ) ) = player_animation_q . get_single_mut ( ) . or ( enemy_animation_q . get_single_mut ( ) ) { displayer . timer . tick ( time . delta ( ) ) ; if displayer . timer . finished ( ) { commands . entity ( e ) . despawn_recursive ( ) ; if is_player_animating { turn_phase_events . send ( StartTurn ( TurnStatus :: EnemyRunning ) ) ; } else if is_enemy_animation { turn_end_events . send ( EndTurn ) ; } else { panic ! ( " " ) ; } } } }
In charge of updating/removing the TurnDisplayer struct
In charge of updating / removing the TurnDisplayer struct
commands
Commands
time
ResMut<Time>
turn_phase_events
EventWriter<StartTurn>
turn_end_events
EventWriter<EndTurn>
player_animation_q
Query<
    (Entity, &mut TurnDisplayer),
    (With<PlayerTurnAnimating>, Without<EnemyTurnAnimating>),
  >
enemy_animation_q
Query<
    (Entity, &mut TurnDisplayer),
    (With<EnemyTurnAnimating>, Without<PlayerTurnAnimating>),
  >