hud: display mass of target. Wow, the masses are all waaay off.

This commit is contained in:
yuni 2024-11-29 20:38:15 +01:00
parent 90d7e01b95
commit 4c8a4278a2

View file

@ -986,7 +986,7 @@ fn update_hud(
), ),
>, >,
settings: Res<Settings>, settings: Res<Settings>,
q_target: Query<(&IsClickable, &Transform, Option<&Position>, Option<&LinearVelocity>), With<IsTargeted>>, q_target: Query<(&IsClickable, &Transform, Option<&Mass>, Option<&Position>, Option<&LinearVelocity>), With<IsTargeted>>,
) { ) {
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering { if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
let q_camera_result = q_camera.get_single(); let q_camera_result = q_camera.get_single();
@ -1013,12 +1013,13 @@ fn update_hud(
_, _,
_, _,
_, _,
_,
)) = q_target.get_single() )) = q_target.get_single()
{ {
dist_scalar = *dist; dist_scalar = *dist;
} else { } else {
let target: Option<DVec3>; let target: Option<DVec3>;
if let Ok((_, _, Some(targetpos), _)) = q_target.get_single() { if let Ok((_, _, _, Some(targetpos), _)) = q_target.get_single() {
target = Some(targetpos.0); target = Some(targetpos.0);
} 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));
@ -1041,7 +1042,7 @@ fn update_hud(
text.sections[0].value = "ERROR: MULTIPLE TARGETS\n\n".to_string(); text.sections[0].value = "ERROR: MULTIPLE TARGETS\n\n".to_string();
} else if target_error { } else if target_error {
text.sections[0].value = "ERROR: FAILED TO AQUIRE TARGET\n\n".to_string(); text.sections[0].value = "ERROR: FAILED TO AQUIRE TARGET\n\n".to_string();
} else if let Ok((clickable, trans, _, _)) = q_target.get_single() { } else if let Ok((clickable, trans, mass, _, _)) = 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 {
@ -1056,8 +1057,11 @@ fn update_hud(
"".to_string() "".to_string()
}; };
let size = nature::readable_si(trans.scale.x as f64 * 2.0); let size = nature::readable_si(trans.scale.x as f64 * 2.0);
let mass = if let Some(mass) = mass {
nature::readable_si(mass.0 * 0.001)
} else { String::from("?") };
text.sections[0].value = text.sections[0].value =
format!("Target: {target_name}\n{pronoun}Distance: {distance}\nSize: {size}m\n\n"); format!("Target: {target_name}\n{pronoun}Distance: {distance}\nSize: {size}m\nMass: {mass}g\n\n");
} else { } else {
text.sections[0].value = "".to_string(); text.sections[0].value = "".to_string();
} }