From 3079b17a1b4c42b068cabd8b24638fa37dd7419b Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 16 Apr 2024 15:56:12 +0200 Subject: [PATCH] better error handling with target acquisition --- src/hud.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/hud.rs b/src/hud.rs index b4d8814..23929d6 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -422,6 +422,8 @@ fn update_hud( // Target display let dist_scalar: f64; + let mut target_multiple = false; + let mut target_error = false; if let Ok((IsClickable { distance: Some(dist), .. }, _, _)) = q_target.get_single() { dist_scalar = *dist; } @@ -433,7 +435,12 @@ fn update_hud( else if q_target.is_empty() { target = Some(DVec3::new(0.0, 0.0, 0.0)); } + else if q_target.iter().len() > 1 { + target_multiple = true; + target = None; + } else { + target_error = true; target = None; } if let Some(target_pos) = target { @@ -458,7 +465,13 @@ fn update_hud( let speed_readable = nature::readable_distance(speed); text.sections[14].value = format!("\n{speed_readable}/s\n{gforce:.1}g{dev_speed}"); - if let Ok((clickable, _, target_v_maybe)) = q_target.get_single() { + if target_multiple { + text.sections[15].value = "\n\nERROR: MULTIPLE TARGETS".to_string(); + } + else if target_error { + text.sections[15].value = "\n\nERROR: FAILED TO AQUIRE TARGET".to_string(); + } + else if let Ok((clickable, _, target_v_maybe)) = q_target.get_single() { let distance = if dist_scalar.is_nan() { "UNKNOWN".to_string() } else if dist_scalar != 0.0 {