made bunch of functions const
This commit is contained in:
@@ -36,8 +36,8 @@ impl ManiaDifficultyAttributes {
|
||||
}
|
||||
|
||||
/// Returns a builder for performance calculation.
|
||||
pub fn performance<'a>(self) -> ManiaPerformance<'a> {
|
||||
self.into()
|
||||
pub const fn performance<'a>(self) -> ManiaPerformance<'a> {
|
||||
ManiaPerformance::from_mania_attributes(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub type ManiaBeatmap<'a> = Converted<'a, Mania>;
|
||||
|
||||
const MAX_NOTES_FOR_DENSITY: usize = 7;
|
||||
|
||||
pub fn check_convert(map: &Beatmap) -> ConvertStatus {
|
||||
pub const fn check_convert(map: &Beatmap) -> ConvertStatus {
|
||||
match map.mode {
|
||||
GameMode::Osu => ConvertStatus::Conversion,
|
||||
GameMode::Mania => ConvertStatus::Noop,
|
||||
|
||||
@@ -34,8 +34,34 @@ pub struct ManiaPerformance<'map> {
|
||||
|
||||
impl<'map> ManiaPerformance<'map> {
|
||||
/// Create a new performance calculator for osu!mania maps.
|
||||
pub fn new(map: ManiaBeatmap<'map>) -> Self {
|
||||
map.into()
|
||||
pub const fn new(map: ManiaBeatmap<'map>) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Map(map),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
n320: None,
|
||||
n300: None,
|
||||
n200: None,
|
||||
n100: None,
|
||||
n50: None,
|
||||
misses: None,
|
||||
acc: None,
|
||||
hitresult_priority: HitResultPriority::DEFAULT,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn from_mania_attributes(attrs: ManiaDifficultyAttributes) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Attrs(attrs),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
n320: None,
|
||||
n300: None,
|
||||
n200: None,
|
||||
n100: None,
|
||||
n50: None,
|
||||
misses: None,
|
||||
acc: None,
|
||||
hitresult_priority: HitResultPriority::DEFAULT,
|
||||
}
|
||||
}
|
||||
|
||||
/// Provide the result of a previous difficulty or performance calculation.
|
||||
@@ -796,41 +822,19 @@ impl<'map> TryFrom<OsuPerformance<'map>> for ManiaPerformance<'map> {
|
||||
|
||||
impl<'map> From<ManiaBeatmap<'map>> for ManiaPerformance<'map> {
|
||||
fn from(map: ManiaBeatmap<'map>) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Map(map),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
n320: None,
|
||||
n300: None,
|
||||
n200: None,
|
||||
n100: None,
|
||||
n50: None,
|
||||
misses: None,
|
||||
acc: None,
|
||||
hitresult_priority: HitResultPriority::default(),
|
||||
}
|
||||
Self::new(map)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ManiaDifficultyAttributes> for ManiaPerformance<'_> {
|
||||
fn from(attrs: ManiaDifficultyAttributes) -> Self {
|
||||
Self {
|
||||
map_or_attrs: MapOrAttrs::Attrs(attrs),
|
||||
difficulty: ModeDifficulty::new(),
|
||||
n320: None,
|
||||
n300: None,
|
||||
n200: None,
|
||||
n100: None,
|
||||
n50: None,
|
||||
misses: None,
|
||||
acc: None,
|
||||
hitresult_priority: HitResultPriority::default(),
|
||||
}
|
||||
Self::from_mania_attributes(attrs)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ManiaPerformanceAttributes> for ManiaPerformance<'_> {
|
||||
fn from(attrs: ManiaPerformanceAttributes) -> Self {
|
||||
attrs.difficulty.into()
|
||||
Self::from_mania_attributes(attrs.difficulty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/// Aggregation for a score's current state.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ManiaScoreState {
|
||||
/// Amount of current 320s.
|
||||
pub n320: u32,
|
||||
@@ -17,8 +17,15 @@ pub struct ManiaScoreState {
|
||||
|
||||
impl ManiaScoreState {
|
||||
/// Create a new empty score state.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
n320: 0,
|
||||
n300: 0,
|
||||
n200: 0,
|
||||
n100: 0,
|
||||
n50: 0,
|
||||
misses: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the total amount of hits by adding everything up.
|
||||
@@ -40,3 +47,9 @@ impl ManiaScoreState {
|
||||
f64::from(numerator) / f64::from(denominator)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ManiaScoreState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user