mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rewrite multiplier_to_percentage to return f32
This commit is contained in:
parent
75a0ce429f
commit
24569b544a
@ -2773,8 +2773,13 @@ fn splice_multiplier<'loc>(
|
||||
desc: &str,
|
||||
multipler: f32,
|
||||
) -> (&'loc str, Cow<'loc, str>) {
|
||||
let percentage = hud::multiplier_to_percentage(multipler).unsigned_abs();
|
||||
splice_constant(i18n, title, desc, percentage)
|
||||
let percentage = hud::multiplier_to_percentage(multipler).abs();
|
||||
|
||||
let title = i18n.get(title);
|
||||
let desc = i18n.get(desc);
|
||||
let desc = desc.replace("{boost}", &format!("{:.0}", percentage));
|
||||
|
||||
(title, Cow::Owned(desc))
|
||||
}
|
||||
|
||||
// Small helper function to get localized skill text.
|
||||
|
@ -4140,12 +4140,15 @@ pub fn angle_of_attack_text(
|
||||
}
|
||||
|
||||
/// Converts multiplier to percentage.
|
||||
/// NOTE: floats are not the most precise type.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use veloren_voxygen::hud::multiplier_to_percentage;
|
||||
///
|
||||
/// assert_eq!(multiplier_to_percentage(1.05), 5);
|
||||
/// assert_eq!(multiplier_to_percentage(0.85), -15);
|
||||
/// let positive = multiplier_to_percentage(1.05);
|
||||
/// assert!((positive - 5.0).abs() < 0.0001);
|
||||
/// let negative = multiplier_to_percentage(0.85);
|
||||
/// assert!((negative - (-15.0)).abs() < 0.0001);
|
||||
/// ```
|
||||
pub fn multiplier_to_percentage(value: f32) -> i32 { (value * 100.0 - 100.0).round() as i32 }
|
||||
pub fn multiplier_to_percentage(value: f32) -> f32 { value * 100.0 - 100.0 }
|
||||
|
Loading…
Reference in New Issue
Block a user