From 7958bb7a82cf172766b2805a3c38aaa2e2a949fc Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sun, 17 Mar 2024 13:55:54 +0100 Subject: feat: add directional ability indicator --- src/client.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 886afd0..3860366 100644 --- a/src/client.rs +++ b/src/client.rs @@ -281,12 +281,13 @@ fn hovered_other_player( } fn gizmos_attack_indicator( + attack: Res, cameras: Query<(&Camera, &GlobalTransform)>, client_id: Res, hoverables: Query<(&PlayerId, &PlayerPosition)>, mut gizmos: Gizmos, - player_positions: Query<(&PlayerId, &PlayerPosition)>, player_champions: Query<(&PlayerId, &Champion)>, + player_positions: Query<(&PlayerId, &PlayerPosition)>, windows: Query<&Window>, ) { let Some(position) = player_position(&client_id, &player_positions) else { @@ -295,12 +296,28 @@ fn gizmos_attack_indicator( let Some(champion) = player_champion(&client_id, &player_champions) else { return; }; - if hovered_other_player(&cameras, &client_id, &hoverables, &windows).is_some() { - gizmos.circle_2d( - position.0, - Stats::from_champion(champion).attack_range, - Color::YELLOW, - ); + let Some(attack_key) = attack.0.or_else(|| { + hovered_other_player(&cameras, &client_id, &hoverables, &windows).map(|_| AttackKey::A) + }) else { + return; + }; + match champion.to_ability(attack_key) { + Ability::Targeted(_) => { + gizmos.circle_2d( + position.0, + Stats::from_champion(champion).attack_range, + Color::YELLOW, + ); + } + Ability::Directional(_) => { + let Some(world_position) = cursor_world_position(&windows, &cameras) else { + return; + }; + let Some(direction) = (world_position - position.0).try_normalize() else { + return; + }; + gizmos.arrow_2d(position.0, position.0 + 75. * direction, Color::YELLOW); + } } } -- cgit v1.2.3