use crate::{
Difficulty,
model::{beatmap::BeatmapAttribute, mods::GameMods},
};
#[derive(Clone, Debug, Default, PartialEq)]
pub struct InspectDifficulty {
pub mods: GameMods,
pub passed_objects: Option<u32>,
pub clock_rate: Option<f64>,
pub ar: BeatmapAttribute,
pub cs: BeatmapAttribute,
pub hp: BeatmapAttribute,
pub od: BeatmapAttribute,
pub hardrock_offsets: Option<bool>,
pub lazer: Option<bool>,
}
impl InspectDifficulty {
pub fn into_difficulty(self) -> Difficulty {
let Self {
mods,
passed_objects,
clock_rate,
ar,
cs,
hp,
od,
hardrock_offsets,
lazer,
} = self;
let mut difficulty = Difficulty::new().mods(mods);
if let Some(passed_objects) = passed_objects {
difficulty = difficulty.passed_objects(passed_objects);
}
if let Some(clock_rate) = clock_rate {
difficulty = difficulty.clock_rate(clock_rate);
}
macro_rules! set_attr {
( $attr:ident ) => {
match $attr {
BeatmapAttribute::None | BeatmapAttribute::Value(_) => {}
BeatmapAttribute::Given(value) => difficulty = difficulty.$attr(value, false),
BeatmapAttribute::Fixed(value) => difficulty = difficulty.$attr(value, true),
};
};
}
set_attr!(ar);
set_attr!(cs);
set_attr!(hp);
set_attr!(od);
if let Some(hardrock_offsets) = hardrock_offsets {
difficulty = difficulty.hardrock_offsets(hardrock_offsets);
}
if let Some(lazer) = lazer {
difficulty = difficulty.lazer(lazer);
}
difficulty
}
}
impl From<InspectDifficulty> for Difficulty {
fn from(difficulty: InspectDifficulty) -> Self {
difficulty.into_difficulty()
}
}
impl From<Difficulty> for InspectDifficulty {
fn from(difficulty: Difficulty) -> Self {
difficulty.inspect()
}
}