use the same PpResult type for all modes
This commit is contained in:
+2
-2
@@ -190,7 +190,7 @@ mod tests {
|
||||
|
||||
let result = TaikoPP::new(&map).mods(64).calculate();
|
||||
|
||||
println!("Stars: {}", result.stars);
|
||||
println!("PP: {}", result.pp);
|
||||
println!("Stars: {}", result.stars());
|
||||
println!("PP: {}", result.pp());
|
||||
}
|
||||
}
|
||||
|
||||
+29
-12
@@ -1,10 +1,23 @@
|
||||
use crate::{Beatmap, Mods};
|
||||
use crate::{Beatmap, Mods, PpResult};
|
||||
|
||||
/// Basic struct containing the result of a PP calculation.
|
||||
/// In osu!taiko's case, this will be just the pp value and the star value.
|
||||
pub struct PpResult {
|
||||
pub pp: f32,
|
||||
pub stars: f32,
|
||||
pub trait TaikoStarProvider {
|
||||
fn attributes(self) -> Option<f32>;
|
||||
}
|
||||
|
||||
impl TaikoStarProvider for f32 {
|
||||
fn attributes(self) -> Option<f32> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl TaikoStarProvider for PpResult {
|
||||
fn attributes(self) -> Option<f32> {
|
||||
if let PpResult::Taiko { stars, .. } = self {
|
||||
Some(stars)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculator for pp on osu!taiko maps.
|
||||
@@ -36,12 +49,16 @@ impl<'m> TaikoPP<'m> {
|
||||
}
|
||||
}
|
||||
|
||||
/// If you already know the stars of the map with the current mods,
|
||||
/// you should specify them so that they don't have to be calculated
|
||||
/// again while calculating PP.
|
||||
/// [`TaikoStarProvider`] is implemented by `f32`
|
||||
/// and by [`PpResult`](crate::PpResult) meaning you can give the
|
||||
/// result of a star calculation or a pp calculation.
|
||||
/// If you already calculated the stars for the current map-mod combination,
|
||||
/// be sure to put them in here so that they don't have to be recalculated.
|
||||
#[inline]
|
||||
pub fn stars(mut self, stars: f32) -> Self {
|
||||
self.stars.replace(stars);
|
||||
pub fn stars(mut self, stars: impl TaikoStarProvider) -> Self {
|
||||
if let Some(stars) = stars.attributes() {
|
||||
self.stars.replace(stars);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
@@ -109,7 +126,7 @@ impl<'m> TaikoPP<'m> {
|
||||
|
||||
let pp = (strain_value.powf(1.1) + acc_value.powf(1.1)).powf(1.0 / 1.1) * multiplier;
|
||||
|
||||
PpResult { stars, pp }
|
||||
PpResult::Taiko { stars, pp }
|
||||
}
|
||||
|
||||
fn compute_strain_value(&self, stars: f32) -> f32 {
|
||||
|
||||
Reference in New Issue
Block a user