use the same StarResult type for all modes
This commit is contained in:
+6
-4
@@ -4,7 +4,7 @@ mod strain;
|
||||
pub use pp::*;
|
||||
use strain::Strain;
|
||||
|
||||
use crate::{Beatmap, HitObject, Mods};
|
||||
use crate::{Beatmap, HitObject, Mods, StarResult};
|
||||
|
||||
const SECTION_LEN: f32 = 400.0;
|
||||
const STAR_SCALING_FACTOR: f32 = 0.018;
|
||||
@@ -12,11 +12,11 @@ const STAR_SCALING_FACTOR: f32 = 0.018;
|
||||
/// Star calculation for osu!mania maps
|
||||
///
|
||||
/// In case of a partial play, e.g. a fail, one can specify the amount of passed objects.
|
||||
pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> f32 {
|
||||
pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> StarResult {
|
||||
let take = passed_objects.unwrap_or_else(|| map.hit_objects.len());
|
||||
|
||||
if take < 2 {
|
||||
return 0.0;
|
||||
return StarResult::Mania { stars: 0.0 };
|
||||
}
|
||||
|
||||
let clock_rate = mods.speed();
|
||||
@@ -58,7 +58,9 @@ pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> f
|
||||
|
||||
strain.save_current_peak();
|
||||
|
||||
strain.difficulty_value() * STAR_SCALING_FACTOR
|
||||
let stars = strain.difficulty_value() * STAR_SCALING_FACTOR;
|
||||
|
||||
StarResult::Mania { stars }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
+15
-6
@@ -1,5 +1,5 @@
|
||||
use super::stars;
|
||||
use crate::{Beatmap, Mods, PpResult};
|
||||
use crate::{Beatmap, Mods, PpResult, StarResult};
|
||||
|
||||
pub trait ManiaStarProvider {
|
||||
fn attributes(self) -> Option<f32>;
|
||||
@@ -11,9 +11,9 @@ impl ManiaStarProvider for f32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaStarProvider for PpResult {
|
||||
impl ManiaStarProvider for StarResult {
|
||||
fn attributes(self) -> Option<f32> {
|
||||
if let PpResult::Mania { stars, .. } = self {
|
||||
if let Self::Mania { stars } = self {
|
||||
Some(stars)
|
||||
} else {
|
||||
None
|
||||
@@ -21,6 +21,12 @@ impl ManiaStarProvider for PpResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaStarProvider for PpResult {
|
||||
fn attributes(self) -> Option<f32> {
|
||||
self.attributes.attributes()
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculator for pp on osu!mania maps.
|
||||
pub struct ManiaPP<'m> {
|
||||
map: &'m Beatmap,
|
||||
@@ -42,7 +48,7 @@ impl<'m> ManiaPP<'m> {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`ManiaStarsProvider`] is implemented by `f32`
|
||||
/// [`ManiaStarsProvider`] is implemented by `f32`, [`StarResult`](crate::StarResult),
|
||||
/// and by [`PpResult`](crate::PpResult) meaning you can give the
|
||||
/// result of a star calculation or a pp calculation.
|
||||
/// If you already calculated the attributes for the current map-mod combination,
|
||||
@@ -87,7 +93,7 @@ impl<'m> ManiaPP<'m> {
|
||||
pub fn calculate(self) -> PpResult {
|
||||
let stars = self
|
||||
.stars
|
||||
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects));
|
||||
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects).stars());
|
||||
|
||||
let ez = self.mods.ez();
|
||||
let nf = self.mods.nf();
|
||||
@@ -133,7 +139,10 @@ impl<'m> ManiaPP<'m> {
|
||||
|
||||
let pp = (strain_value.powf(1.1) + acc_value.powf(1.1)).powf(1.0 / 1.1) * multiplier;
|
||||
|
||||
PpResult::Mania { pp, stars }
|
||||
PpResult {
|
||||
pp,
|
||||
attributes: StarResult::Mania { stars },
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_strain(&self, score: f32, stars: f32) -> f32 {
|
||||
|
||||
Reference in New Issue
Block a user