better error handling with target acquisition

This commit is contained in:
yuni 2024-04-16 15:56:12 +02:00
parent fd16d6931e
commit 3079b17a1b

View file

@ -422,6 +422,8 @@ fn update_hud(
// Target display // Target display
let dist_scalar: f64; 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() { if let Ok((IsClickable { distance: Some(dist), .. }, _, _)) = q_target.get_single() {
dist_scalar = *dist; dist_scalar = *dist;
} }
@ -433,7 +435,12 @@ fn update_hud(
else if q_target.is_empty() { else if q_target.is_empty() {
target = Some(DVec3::new(0.0, 0.0, 0.0)); target = Some(DVec3::new(0.0, 0.0, 0.0));
} }
else if q_target.iter().len() > 1 {
target_multiple = true;
target = None;
}
else { else {
target_error = true;
target = None; target = None;
} }
if let Some(target_pos) = target { if let Some(target_pos) = target {
@ -458,7 +465,13 @@ fn update_hud(
let speed_readable = nature::readable_distance(speed); let speed_readable = nature::readable_distance(speed);
text.sections[14].value = format!("\n{speed_readable}/s\n{gforce:.1}g{dev_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() { let distance = if dist_scalar.is_nan() {
"UNKNOWN".to_string() "UNKNOWN".to_string()
} else if dist_scalar != 0.0 { } else if dist_scalar != 0.0 {