#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub enum BeatmapAttribute {
#[default]
None,
Value(f32),
Given(f32),
Fixed(f32),
}
impl BeatmapAttribute {
pub const DEFAULT: f32 = 5.0;
#[must_use]
pub const fn overwrite(self, other: Self) -> Self {
if let Self::None = other { self } else { other }
}
pub fn try_mutate(&mut self, f: impl Fn(&mut f32)) {
if let Self::None = self {
*self = Self::Value(Self::DEFAULT);
}
if let Self::Value(value) | Self::Given(value) = self {
f(value);
}
}
pub const fn try_set(&mut self, value: f32) {
match self {
Self::None => *self = Self::Value(value),
Self::Value(old) => *old = value,
_ => {}
}
}
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where
D: FnOnce(f32) -> U,
F: FnOnce(f32) -> U,
{
match self {
Self::None => f(Self::DEFAULT),
Self::Value(value) | Self::Given(value) => f(value),
Self::Fixed(fixed) => default(fixed),
}
}
pub const fn get_raw(self) -> f32 {
match self {
Self::None => Self::DEFAULT,
Self::Value(value) | Self::Given(value) | Self::Fixed(value) => value,
}
}
}