added ScoreState::total_hits

This commit is contained in:
MaxOhn
2022-11-29 00:29:30 +01:00
parent 9e0001d9d9
commit 07ea95a6c0
2 changed files with 24 additions and 1 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
## Upcoming
Nothing as of now
- __Additions:__
- Added the method `ScoreState::total_hits`
# v0.9.2 (2022-11-08)
+22
View File
@@ -51,6 +51,7 @@ pub enum GradualDifficultyAttributes<'map> {
impl<'map> GradualDifficultyAttributes<'map> {
/// Create a new gradual difficulty calculator for maps of any mode.
#[inline]
pub fn new(map: &'map Beatmap, mods: u32) -> Self {
match map.mode {
GameMode::Osu => Self::Osu(OsuGradualDifficultyAttributes::new(map, mods)),
@@ -115,9 +116,27 @@ pub struct ScoreState {
impl ScoreState {
/// Create a new empty score state.
#[inline]
pub fn new() -> Self {
Self::default()
}
/// Return the total amount of hits by adding everything up based on the mode.
#[inline]
pub fn total_hits(&self, mode: GameMode) -> usize {
let mut amount = self.n300 + self.n100 + self.n_misses;
if mode != GameMode::Taiko {
amount += self.n50;
if mode != GameMode::Osu {
amount += self.n_katu;
amount += (mode != GameMode::Catch) as usize * self.n_geki;
}
}
amount
}
}
impl From<ScoreState> for OsuScoreState {
@@ -282,6 +301,7 @@ pub enum GradualPerformanceAttributes<'map> {
impl<'map> GradualPerformanceAttributes<'map> {
/// Create a new gradual performance calculator for maps of any mode.
#[inline]
pub fn new(map: &'map Beatmap, mods: u32) -> Self {
match map.mode {
GameMode::Osu => Self::Osu(OsuGradualPerformanceAttributes::new(map, mods)),
@@ -293,6 +313,7 @@ impl<'map> GradualPerformanceAttributes<'map> {
/// Process the next hit object and calculate the
/// performance attributes for the resulting score.
#[inline]
pub fn process_next_object(&mut self, state: ScoreState) -> Option<PerformanceAttributes> {
self.process_next_n_objects(state, 1)
}
@@ -303,6 +324,7 @@ impl<'map> GradualPerformanceAttributes<'map> {
/// If `n` is 0 it will be considered as 1.
/// If there are still objects to be processed but `n` is larger than the amount
/// of remaining objects, `n` will be considered as the amount of remaining objects.
#[inline]
pub fn process_next_n_objects(
&mut self,
state: ScoreState,