From 48e54265f9d232e7e2e47099f087666e10c6f75a Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 8 Apr 2024 04:27:02 +0200 Subject: [PATCH] simplify --- src/hud.rs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/hud.rs b/src/hud.rs index 10ef84f..51fda48 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -439,7 +439,6 @@ fn update_hud( let integrity = suit.integrity * 100.0; text.sections[11].value = format!("{integrity:.0}%"); let speed = cam_v.length(); - let kmh = speed * 60.0 * 60.0 / 1000.0; let speed_readable = nature::readable_distance(speed); let gforce = gforce.gforce; //text.sections[17].value = format!("{speed_readable}/s / {kmh:.0}km/h / {gforce:.1}g"); @@ -469,28 +468,20 @@ fn update_hud( } } - let target_name: String; - let distance: String; - if dist_scalar.is_nan() { - distance = "UNKNOWN".to_string(); - } - else if dist_scalar != 0.0 { - distance = nature::readable_distance(dist_scalar); - } - else { - distance = "ERROR".to_string(); - } - if q_target.is_empty() { - text.sections[14].value = format!("\nv {speed_readable}/s + {gforce:.1}g"); - } - else { - let targets: Vec = q_target - .iter() - .map(|(_, clickable)| clickable.name.clone().unwrap_or("".to_string())) - .collect(); - target_name = targets.join(", "); + if let Ok((_, clickable)) = q_target.get_single() { + let distance = if dist_scalar.is_nan() { + "UNKNOWN".to_string() + } else if dist_scalar != 0.0 { + nature::readable_distance(dist_scalar) + } else { + "ERROR".to_string() + }; + let target_name = clickable.name.clone().unwrap_or("Unnamed".to_string()); text.sections[14].value = format!("\n\nTarget: {target_name}\nDistance: {distance}\nΔv {speed_readable}/s + {gforce:.1}g"); } + else { + text.sections[14].value = format!("\nv {speed_readable}/s + {gforce:.1}g"); + } } }