refactor: use is_convert of attrs
This commit is contained in:
+14
-12
@@ -43,7 +43,7 @@ use crate::{
|
|||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
pub struct ManiaPP<'map> {
|
pub struct ManiaPP<'map> {
|
||||||
map_or_attrs: MapOrElse<Cow<'map, Beatmap>, ManiaDifficultyAttributes>,
|
map_or_attrs: MapOrElse<Cow<'map, Beatmap>, ManiaDifficultyAttributes>,
|
||||||
is_convert: bool,
|
is_convert_overwrite: Option<bool>,
|
||||||
mods: u32,
|
mods: u32,
|
||||||
passed_objects: Option<usize>,
|
passed_objects: Option<usize>,
|
||||||
clock_rate: Option<f64>,
|
clock_rate: Option<f64>,
|
||||||
@@ -66,8 +66,8 @@ impl<'map> ManiaPP<'map> {
|
|||||||
let map = map.convert_mode(GameMode::Mania);
|
let map = map.convert_mode(GameMode::Mania);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
is_convert: matches!(map, Cow::Owned(_)),
|
|
||||||
map_or_attrs: MapOrElse::Map(map),
|
map_or_attrs: MapOrElse::Map(map),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods: 0,
|
mods: 0,
|
||||||
passed_objects: None,
|
passed_objects: None,
|
||||||
clock_rate: None,
|
clock_rate: None,
|
||||||
@@ -198,7 +198,7 @@ impl<'map> ManiaPP<'map> {
|
|||||||
/// This only needs to be specified if the map was converted manually beforehand.
|
/// This only needs to be specified if the map was converted manually beforehand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_convert(mut self, is_convert: bool) -> Self {
|
pub fn is_convert(mut self, is_convert: bool) -> Self {
|
||||||
self.is_convert = is_convert;
|
self.is_convert_overwrite = Some(is_convert);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -726,9 +726,14 @@ impl<'map> ManiaPP<'map> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_attributes(&self, map: &Beatmap) -> ManiaDifficultyAttributes {
|
fn generate_attributes(&self, map: &Beatmap) -> ManiaDifficultyAttributes {
|
||||||
let mut calculator = ManiaStars::new(map)
|
let is_convert = self
|
||||||
.mods(self.mods)
|
.is_convert_overwrite
|
||||||
.is_convert(self.is_convert);
|
.unwrap_or_else(|| match self.map_or_attrs {
|
||||||
|
MapOrElse::Map(ref map) => matches!(map, Cow::Owned(_)),
|
||||||
|
MapOrElse::Else(ref attrs) => attrs.is_convert,
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut calculator = ManiaStars::new(map).mods(self.mods).is_convert(is_convert);
|
||||||
|
|
||||||
if let Some(passed_objects) = self.passed_objects {
|
if let Some(passed_objects) = self.passed_objects {
|
||||||
calculator = calculator.passed_objects(passed_objects);
|
calculator = calculator.passed_objects(passed_objects);
|
||||||
@@ -771,8 +776,8 @@ impl<'map> ManiaPP<'map> {
|
|||||||
let map = map.into_inner().convert_mode(GameMode::Mania);
|
let map = map.into_inner().convert_mode(GameMode::Mania);
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
is_convert: matches!(map, Cow::Owned(_)),
|
|
||||||
map_or_attrs: MapOrElse::Map(map),
|
map_or_attrs: MapOrElse::Map(map),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods,
|
mods,
|
||||||
passed_objects,
|
passed_objects,
|
||||||
clock_rate,
|
clock_rate,
|
||||||
@@ -797,13 +802,10 @@ impl<'map> ManiaPP<'map> {
|
|||||||
/// Returns `None` only if the [`ManiaAttributeProvider`] did not contain
|
/// Returns `None` only if the [`ManiaAttributeProvider`] did not contain
|
||||||
/// attributes for mania e.g. if it's [`DifficultyAttributes::Taiko`].
|
/// attributes for mania e.g. if it's [`DifficultyAttributes::Taiko`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn try_from_attributes(
|
pub fn try_from_attributes(attributes: impl ManiaAttributeProvider) -> Option<Self> {
|
||||||
attributes: impl ManiaAttributeProvider,
|
|
||||||
is_convert: bool,
|
|
||||||
) -> Option<Self> {
|
|
||||||
attributes.attributes().map(|attrs| Self {
|
attributes.attributes().map(|attrs| Self {
|
||||||
is_convert,
|
|
||||||
map_or_attrs: MapOrElse::Else(attrs),
|
map_or_attrs: MapOrElse::Else(attrs),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods: 0,
|
mods: 0,
|
||||||
passed_objects: None,
|
passed_objects: None,
|
||||||
clock_rate: None,
|
clock_rate: None,
|
||||||
|
|||||||
+14
-12
@@ -39,7 +39,7 @@ use crate::{
|
|||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
pub struct TaikoPP<'map> {
|
pub struct TaikoPP<'map> {
|
||||||
pub(crate) map_or_attrs: MapOrElse<Cow<'map, Beatmap>, TaikoDifficultyAttributes>,
|
pub(crate) map_or_attrs: MapOrElse<Cow<'map, Beatmap>, TaikoDifficultyAttributes>,
|
||||||
is_convert: bool,
|
is_convert_overwrite: Option<bool>,
|
||||||
mods: u32,
|
mods: u32,
|
||||||
combo: Option<usize>,
|
combo: Option<usize>,
|
||||||
acc: Option<f64>,
|
acc: Option<f64>,
|
||||||
@@ -59,8 +59,8 @@ impl<'map> TaikoPP<'map> {
|
|||||||
let map = map.convert_mode(GameMode::Taiko);
|
let map = map.convert_mode(GameMode::Taiko);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
is_convert: matches!(map, Cow::Owned(_)),
|
|
||||||
map_or_attrs: MapOrElse::Map(map),
|
map_or_attrs: MapOrElse::Map(map),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods: 0,
|
mods: 0,
|
||||||
combo: None,
|
combo: None,
|
||||||
acc: None,
|
acc: None,
|
||||||
@@ -173,7 +173,7 @@ impl<'map> TaikoPP<'map> {
|
|||||||
/// This only needs to be specified if the map was converted manually beforehand.
|
/// This only needs to be specified if the map was converted manually beforehand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_convert(mut self, is_convert: bool) -> Self {
|
pub fn is_convert(mut self, is_convert: bool) -> Self {
|
||||||
self.is_convert = is_convert;
|
self.is_convert_overwrite = Some(is_convert);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -306,9 +306,14 @@ impl<'map> TaikoPP<'map> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_attributes(&self, map: &Beatmap) -> TaikoDifficultyAttributes {
|
fn generate_attributes(&self, map: &Beatmap) -> TaikoDifficultyAttributes {
|
||||||
let mut calculator = TaikoStars::new(map)
|
let is_convert = self
|
||||||
.mods(self.mods)
|
.is_convert_overwrite
|
||||||
.is_convert(self.is_convert);
|
.unwrap_or_else(|| match self.map_or_attrs {
|
||||||
|
MapOrElse::Map(ref map) => matches!(map, Cow::Owned(_)),
|
||||||
|
MapOrElse::Else(ref attrs) => attrs.is_convert,
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut calculator = TaikoStars::new(map).mods(self.mods).is_convert(is_convert);
|
||||||
|
|
||||||
if let Some(passed_objects) = self.passed_objects {
|
if let Some(passed_objects) = self.passed_objects {
|
||||||
calculator = calculator.passed_objects(passed_objects);
|
calculator = calculator.passed_objects(passed_objects);
|
||||||
@@ -351,8 +356,8 @@ impl<'map> TaikoPP<'map> {
|
|||||||
let map = map.into_inner().convert_mode(GameMode::Taiko);
|
let map = map.into_inner().convert_mode(GameMode::Taiko);
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
is_convert: matches!(map, Cow::Owned(_)),
|
|
||||||
map_or_attrs: MapOrElse::Map(map),
|
map_or_attrs: MapOrElse::Map(map),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods,
|
mods,
|
||||||
combo,
|
combo,
|
||||||
acc,
|
acc,
|
||||||
@@ -375,13 +380,10 @@ impl<'map> TaikoPP<'map> {
|
|||||||
/// Returns `None` only if the [`TaikoAttributeProvider`] did not contain
|
/// Returns `None` only if the [`TaikoAttributeProvider`] did not contain
|
||||||
/// attributes for catch e.g. if it's [`DifficultyAttributes::Mania`].
|
/// attributes for catch e.g. if it's [`DifficultyAttributes::Mania`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn try_from_attributes(
|
pub fn try_from_attributes(attributes: impl TaikoAttributeProvider) -> Option<Self> {
|
||||||
attributes: impl TaikoAttributeProvider,
|
|
||||||
is_convert: bool,
|
|
||||||
) -> Option<Self> {
|
|
||||||
attributes.attributes().map(|attrs| Self {
|
attributes.attributes().map(|attrs| Self {
|
||||||
is_convert,
|
|
||||||
map_or_attrs: MapOrElse::Else(attrs),
|
map_or_attrs: MapOrElse::Else(attrs),
|
||||||
|
is_convert_overwrite: None,
|
||||||
mods: 0,
|
mods: 0,
|
||||||
combo: None,
|
combo: None,
|
||||||
acc: None,
|
acc: None,
|
||||||
|
|||||||
Reference in New Issue
Block a user