api adjustments

This commit is contained in:
MaxOhn
2024-03-25 14:10:32 +01:00
parent 2a37169ca8
commit c0e1977a54
5 changed files with 239 additions and 142 deletions
+42 -34
View File
@@ -183,6 +183,11 @@ class Difficulty:
Suitable to plot the difficulty over time.
"""
def performance(self) -> Performance:
"""
Use the current difficulty settings to create a performance calculator
"""
def gradual_difficulty(self, map: Beatmap) -> GradualDifficulty:
"""
Returns a gradual difficulty calculator for the current difficulty settings
@@ -193,11 +198,11 @@ class Difficulty:
Returns a gradual performance calculator for the current difficulty settings
"""
def set_mods(self, mods: int) -> None: ...
def set_mods(self, mods: Optional[int]) -> None: ...
def set_clock_rate(self, clock_rate: float) -> None: ...
def set_clock_rate(self, clock_rate: Optional[float]) -> None: ...
def set_ar(self, ar: float, with_mods: bool) -> None:
def set_ar(self, ar: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set AR.
@@ -210,7 +215,7 @@ class Difficulty:
used as is and on `false` it will be modified based on the mods.
"""
def set_cs(self, cs: float, with_mods: bool) -> None:
def set_cs(self, cs: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set CS.
@@ -223,7 +228,7 @@ class Difficulty:
used as is and on `false` it will be modified based on the mods.
"""
def set_hp(self, hp: float, with_mods: bool) -> None:
def set_hp(self, hp: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set HP.
@@ -234,7 +239,7 @@ class Difficulty:
used as is and on `false` it will be modified based on the mods.
"""
def set_od(self, od: float, with_mods: bool) -> None:
def set_od(self, od: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set OD.
@@ -245,9 +250,9 @@ class Difficulty:
used as is and on `false` it will be modified based on the mods.
"""
def set_passed_objects(self, passed_objects: int) -> None: ...
def set_passed_objects(self, passed_objects: Optional[int]) -> None: ...
def set_hardrock_offsets(self, hardrock_offsets: bool) -> None: ...
def set_hardrock_offsets(self, hardrock_offsets: Optional[bool]) -> None: ...
class Performance:
"""
@@ -358,11 +363,16 @@ class Performance:
custom ar, ... otherwise the final attributes will be incorrect.
"""
def set_mods(self, mods: int) -> None: ...
def difficulty(self) -> Difficulty:
"""
Use the current difficulty settings to create a difficulty calculator
"""
def set_clock_rate(self, clock_rate: float) -> None: ...
def set_mods(self, mods: Optional[int]) -> None: ...
def set_ar(self, ar: float, with_mods: bool) -> None:
def set_clock_rate(self, clock_rate: Optional[float]) -> None: ...
def set_ar(self, ar: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set AR.
@@ -375,7 +385,7 @@ class Performance:
used as is and on `false` it will be modified based on the mods.
"""
def set_cs(self, cs: float, with_mods: bool) -> None:
def set_cs(self, cs: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set CS.
@@ -388,7 +398,7 @@ class Performance:
used as is and on `false` it will be modified based on the mods.
"""
def set_hp(self, hp: float, with_mods: bool) -> None:
def set_hp(self, hp: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set HP.
@@ -399,7 +409,7 @@ class Performance:
used as is and on `false` it will be modified based on the mods.
"""
def set_od(self, od: float, with_mods: bool) -> None:
def set_od(self, od: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set OD.
@@ -410,27 +420,27 @@ class Performance:
used as is and on `false` it will be modified based on the mods.
"""
def set_passed_objects(self, passed_objects: int) -> None: ...
def set_passed_objects(self, passed_objects: Optional[int]) -> None: ...
def set_hardrock_offsets(self, hardrock_offsets: bool) -> None: ...
def set_hardrock_offsets(self, hardrock_offsets: Optional[bool]) -> None: ...
def set_accuracy(self, accuracy: float) -> None: ...
def set_accuracy(self, accuracy: Optional[float]) -> None: ...
def set_combo(self, combo: int) -> None: ...
def set_combo(self, combo: Optional[int]) -> None: ...
def set_n_geki(self, n_geki: int) -> None: ...
def set_n_geki(self, n_geki: Optional[int]) -> None: ...
def set_n_katu(self, n_katu: int) -> None: ...
def set_n_katu(self, n_katu: Optional[int]) -> None: ...
def set_n300(self, n300: int) -> None: ...
def set_n300(self, n300: Optional[int]) -> None: ...
def set_n100(self, n100: int) -> None: ...
def set_n100(self, n100: Optional[int]) -> None: ...
def set_n50(self, n50: int) -> None: ...
def set_n50(self, n50: Optional[int]) -> None: ...
def set_misses(self, misses: int) -> None: ...
def set_misses(self, misses: Optional[int]) -> None: ...
def set_hitresult_priority(self, hitresult_priority: HitResultPriority) -> None: ...
def set_hitresult_priority(self, hitresult_priority: Optional[HitResultPriority]) -> None: ...
class GradualDifficulty(Iterator):
"""
@@ -556,15 +566,13 @@ class BeatmapAttributesBuilder:
Consider the map's attributes, mode, and convert status
"""
def set_mode(self, mode: GameMode) -> None: ...
def set_mode(self, mode: Optional[GameMode], is_convert: bool) -> None: ...
def set_is_convert(self, is_convert: bool) -> None: ...
def set_mods(self, mods: Optional[int]) -> None: ...
def set_mods(self, mods: int) -> None: ...
def set_clock_rate(self, clock_rate: Optional[float]) -> None: ...
def set_clock_rate(self, clock_rate: float) -> None: ...
def set_ar(self, ar: float, with_mods: bool) -> None:
def set_ar(self, ar: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set AR.
@@ -577,7 +585,7 @@ class BeatmapAttributesBuilder:
used as is and on `false` it will be modified based on the mods.
"""
def set_cs(self, cs: float, with_mods: bool) -> None:
def set_cs(self, cs: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set CS.
@@ -590,7 +598,7 @@ class BeatmapAttributesBuilder:
used as is and on `false` it will be modified based on the mods.
"""
def set_hp(self, hp: float, with_mods: bool) -> None:
def set_hp(self, hp: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set HP.
@@ -601,7 +609,7 @@ class BeatmapAttributesBuilder:
used as is and on `false` it will be modified based on the mods.
"""
def set_od(self, od: float, with_mods: bool) -> None:
def set_od(self, od: Optional[float], with_mods: bool) -> None:
"""
Override a beatmap's set OD.
+19 -17
View File
@@ -167,39 +167,41 @@ impl PyBeatmapAttributesBuilder {
self.is_convert = map.is_convert;
}
fn set_mode(&mut self, mode: PyGameMode) {
self.mode = Some(mode);
}
fn set_is_convert(&mut self, is_convert: bool) {
#[pyo3(signature = (mode, is_convert))]
fn set_mode(&mut self, mode: Option<PyGameMode>, is_convert: bool) {
self.mode = mode;
self.is_convert = is_convert;
}
fn set_mods(&mut self, mods: u32) {
self.mods = mods;
fn set_mods(&mut self, mods: Option<u32>) {
self.mods = mods.unwrap_or(0);
}
fn set_clock_rate(&mut self, clock_rate: f64) {
self.clock_rate = Some(clock_rate);
fn set_clock_rate(&mut self, clock_rate: Option<f64>) {
self.clock_rate = clock_rate;
}
fn set_ar(&mut self, ar: f32, ar_with_mods: bool) {
self.ar = Some(ar);
#[pyo3(signature = (ar, ar_with_mods))]
fn set_ar(&mut self, ar: Option<f32>, ar_with_mods: bool) {
self.ar = ar;
self.ar_with_mods = ar_with_mods;
}
fn set_cs(&mut self, cs: f32, cs_with_mods: bool) {
self.cs = Some(cs);
#[pyo3(signature = (cs, cs_with_mods))]
fn set_cs(&mut self, cs: Option<f32>, cs_with_mods: bool) {
self.cs = cs;
self.cs_with_mods = cs_with_mods;
}
fn set_hp(&mut self, hp: f32, hp_with_mods: bool) {
self.hp = Some(hp);
#[pyo3(signature = (hp, hp_with_mods))]
fn set_hp(&mut self, hp: Option<f32>, hp_with_mods: bool) {
self.hp = hp;
self.hp_with_mods = hp_with_mods;
}
fn set_od(&mut self, od: f32, od_with_mods: bool) {
self.od = Some(od);
#[pyo3(signature = (od, od_with_mods))]
fn set_od(&mut self, od: Option<f32>, od_with_mods: bool) {
self.od = od;
self.od_with_mods = od_with_mods;
}
}
+66 -28
View File
@@ -6,24 +6,25 @@ use crate::{
beatmap::PyBeatmap,
error::ArgsError,
gradual::{difficulty::PyGradualDifficulty, performance::PyGradualPerformance},
performance::PyPerformance,
strains::PyStrains,
};
#[pyclass(name = "Difficulty")]
#[derive(Default)]
pub struct PyDifficulty {
mods: u32,
clock_rate: Option<f64>,
ar: Option<f32>,
ar_with_mods: bool,
cs: Option<f32>,
cs_with_mods: bool,
hp: Option<f32>,
hp_with_mods: bool,
od: Option<f32>,
od_with_mods: bool,
passed_objects: Option<u32>,
hardrock_offsets: Option<bool>,
pub(crate) mods: u32,
pub(crate) clock_rate: Option<f64>,
pub(crate) ar: Option<f32>,
pub(crate) ar_with_mods: bool,
pub(crate) cs: Option<f32>,
pub(crate) cs_with_mods: bool,
pub(crate) hp: Option<f32>,
pub(crate) hp_with_mods: bool,
pub(crate) od: Option<f32>,
pub(crate) od_with_mods: bool,
pub(crate) passed_objects: Option<u32>,
pub(crate) hardrock_offsets: Option<bool>,
}
#[pymethods]
@@ -132,6 +133,39 @@ impl PyDifficulty {
self.as_difficulty().strains(&map.inner).into()
}
fn performance(&self) -> PyPerformance {
let Self {
mods,
clock_rate,
ar,
ar_with_mods,
cs,
cs_with_mods,
hp,
hp_with_mods,
od,
od_with_mods,
passed_objects,
hardrock_offsets,
} = self;
PyPerformance {
mods: *mods,
clock_rate: *clock_rate,
ar: *ar,
ar_with_mods: *ar_with_mods,
cs: *cs,
cs_with_mods: *cs_with_mods,
hp: *hp,
hp_with_mods: *hp_with_mods,
od: *od,
od_with_mods: *od_with_mods,
passed_objects: *passed_objects,
hardrock_offsets: *hardrock_offsets,
..PyPerformance::default()
}
}
fn gradual_difficulty(&self, map: &PyBeatmap) -> PyGradualDifficulty {
PyGradualDifficulty::new(self, map)
}
@@ -140,40 +174,44 @@ impl PyDifficulty {
PyGradualPerformance::new(self, map)
}
fn set_mods(&mut self, mods: u32) {
self.mods = mods;
fn set_mods(&mut self, mods: Option<u32>) {
self.mods = mods.unwrap_or(0);
}
fn set_clock_rate(&mut self, clock_rate: f64) {
self.clock_rate = Some(clock_rate);
fn set_clock_rate(&mut self, clock_rate: Option<f64>) {
self.clock_rate = clock_rate;
}
fn set_ar(&mut self, ar: f32, ar_with_mods: bool) {
self.ar = Some(ar);
#[pyo3(signature = (ar, ar_with_mods))]
fn set_ar(&mut self, ar: Option<f32>, ar_with_mods: bool) {
self.ar = ar;
self.ar_with_mods = ar_with_mods;
}
fn set_cs(&mut self, cs: f32, cs_with_mods: bool) {
self.cs = Some(cs);
#[pyo3(signature = (cs, cs_with_mods))]
fn set_cs(&mut self, cs: Option<f32>, cs_with_mods: bool) {
self.cs = cs;
self.cs_with_mods = cs_with_mods;
}
fn set_hp(&mut self, hp: f32, hp_with_mods: bool) {
self.hp = Some(hp);
#[pyo3(signature = (hp, hp_with_mods))]
fn set_hp(&mut self, hp: Option<f32>, hp_with_mods: bool) {
self.hp = hp;
self.hp_with_mods = hp_with_mods;
}
fn set_od(&mut self, od: f32, od_with_mods: bool) {
self.od = Some(od);
#[pyo3(signature = (od, od_with_mods))]
fn set_od(&mut self, od: Option<f32>, od_with_mods: bool) {
self.od = od;
self.od_with_mods = od_with_mods;
}
fn set_passed_objects(&mut self, passed_objects: u32) {
self.passed_objects = Some(passed_objects);
fn set_passed_objects(&mut self, passed_objects: Option<u32>) {
self.passed_objects = passed_objects;
}
fn set_hardrock_offsets(&mut self, hardrock_offsets: bool) {
self.hardrock_offsets = Some(hardrock_offsets);
fn set_hardrock_offsets(&mut self, hardrock_offsets: Option<bool>) {
self.hardrock_offsets = hardrock_offsets;
}
}
+95 -56
View File
@@ -7,33 +7,34 @@ use rosu_pp::{
use crate::{
attributes::{difficulty::PyDifficultyAttributes, performance::PyPerformanceAttributes},
beatmap::PyBeatmap,
difficulty::PyDifficulty,
error::ArgsError,
};
#[pyclass(name = "Performance")]
#[derive(Default)]
pub struct PyPerformance {
mods: u32,
clock_rate: Option<f64>,
ar: Option<f32>,
ar_with_mods: bool,
cs: Option<f32>,
cs_with_mods: bool,
hp: Option<f32>,
hp_with_mods: bool,
od: Option<f32>,
od_with_mods: bool,
passed_objects: Option<u32>,
hardrock_offsets: Option<bool>,
accuracy: Option<f64>,
combo: Option<u32>,
n_geki: Option<u32>,
n_katu: Option<u32>,
n300: Option<u32>,
n100: Option<u32>,
n50: Option<u32>,
misses: Option<u32>,
hitresult_priority: PyHitResultPriority,
pub(crate) mods: u32,
pub(crate) clock_rate: Option<f64>,
pub(crate) ar: Option<f32>,
pub(crate) ar_with_mods: bool,
pub(crate) cs: Option<f32>,
pub(crate) cs_with_mods: bool,
pub(crate) hp: Option<f32>,
pub(crate) hp_with_mods: bool,
pub(crate) od: Option<f32>,
pub(crate) od_with_mods: bool,
pub(crate) passed_objects: Option<u32>,
pub(crate) hardrock_offsets: Option<bool>,
pub(crate) accuracy: Option<f64>,
pub(crate) combo: Option<u32>,
pub(crate) n_geki: Option<u32>,
pub(crate) n_katu: Option<u32>,
pub(crate) n300: Option<u32>,
pub(crate) n100: Option<u32>,
pub(crate) n50: Option<u32>,
pub(crate) misses: Option<u32>,
pub(crate) hitresult_priority: PyHitResultPriority,
}
#[pymethods]
@@ -219,82 +220,120 @@ impl PyPerformance {
perf = self.apply(perf);
let state = perf.generate_state();
let mut attrs = PyPerformanceAttributes::from(perf.calculate());
let x = perf.calculate();
let mut attrs = PyPerformanceAttributes::from(x);
attrs.state = Some(state.into());
Ok(attrs)
}
fn set_mods(&mut self, mods: u32) {
self.mods = mods;
fn difficulty(&self) -> PyDifficulty {
let Self {
mods,
clock_rate,
ar,
ar_with_mods,
cs,
cs_with_mods,
hp,
hp_with_mods,
od,
od_with_mods,
passed_objects,
hardrock_offsets,
..
} = self;
PyDifficulty {
mods: *mods,
clock_rate: *clock_rate,
ar: *ar,
ar_with_mods: *ar_with_mods,
cs: *cs,
cs_with_mods: *cs_with_mods,
hp: *hp,
hp_with_mods: *hp_with_mods,
od: *od,
od_with_mods: *od_with_mods,
passed_objects: *passed_objects,
hardrock_offsets: *hardrock_offsets,
}
}
fn set_clock_rate(&mut self, clock_rate: f64) {
self.clock_rate = Some(clock_rate);
fn set_mods(&mut self, mods: Option<u32>) {
self.mods = mods.unwrap_or(0);
}
fn set_ar(&mut self, ar: f32, ar_with_mods: bool) {
self.ar = Some(ar);
fn set_clock_rate(&mut self, clock_rate: Option<f64>) {
self.clock_rate = clock_rate;
}
#[pyo3(signature = (ar, ar_with_mods))]
fn set_ar(&mut self, ar: Option<f32>, ar_with_mods: bool) {
self.ar = ar;
self.ar_with_mods = ar_with_mods;
}
fn set_cs(&mut self, cs: f32, cs_with_mods: bool) {
self.cs = Some(cs);
#[pyo3(signature = (cs, cs_with_mods))]
fn set_cs(&mut self, cs: Option<f32>, cs_with_mods: bool) {
self.cs = cs;
self.cs_with_mods = cs_with_mods;
}
fn set_hp(&mut self, hp: f32, hp_with_mods: bool) {
self.hp = Some(hp);
#[pyo3(signature = (hp, hp_with_mods))]
fn set_hp(&mut self, hp: Option<f32>, hp_with_mods: bool) {
self.hp = hp;
self.hp_with_mods = hp_with_mods;
}
fn set_od(&mut self, od: f32, od_with_mods: bool) {
self.od = Some(od);
#[pyo3(signature = (od, od_with_mods))]
fn set_od(&mut self, od: Option<f32>, od_with_mods: bool) {
self.od = od;
self.od_with_mods = od_with_mods;
}
fn set_passed_objects(&mut self, passed_objects: u32) {
self.passed_objects = Some(passed_objects);
fn set_passed_objects(&mut self, passed_objects: Option<u32>) {
self.passed_objects = passed_objects;
}
fn set_hardrock_offsets(&mut self, hardrock_offsets: bool) {
self.hardrock_offsets = Some(hardrock_offsets);
fn set_hardrock_offsets(&mut self, hardrock_offsets: Option<bool>) {
self.hardrock_offsets = hardrock_offsets;
}
fn set_accuracy(&mut self, accuracy: f64) {
self.accuracy = Some(accuracy);
fn set_accuracy(&mut self, accuracy: Option<f64>) {
self.accuracy = accuracy;
}
fn set_combo(&mut self, combo: u32) {
self.combo = Some(combo);
fn set_combo(&mut self, combo: Option<u32>) {
self.combo = combo;
}
fn set_n_geki(&mut self, n_geki: u32) {
self.n_geki = Some(n_geki);
fn set_n_geki(&mut self, n_geki: Option<u32>) {
self.n_geki = n_geki;
}
fn set_n_katu(&mut self, n_katu: u32) {
self.n_katu = Some(n_katu);
fn set_n_katu(&mut self, n_katu: Option<u32>) {
self.n_katu = n_katu;
}
fn set_n300(&mut self, n300: u32) {
self.n300 = Some(n300);
fn set_n300(&mut self, n300: Option<u32>) {
self.n300 = n300;
}
fn set_n100(&mut self, n100: u32) {
self.n100 = Some(n100);
fn set_n100(&mut self, n100: Option<u32>) {
self.n100 = n100;
}
fn set_n50(&mut self, n50: u32) {
self.n50 = Some(n50);
fn set_n50(&mut self, n50: Option<u32>) {
self.n50 = n50;
}
fn set_misses(&mut self, misses: u32) {
self.misses = Some(misses);
fn set_misses(&mut self, misses: Option<u32>) {
self.misses = misses;
}
fn set_hitresult_priority(&mut self, hitresult_priority: PyHitResultPriority) {
self.hitresult_priority = hitresult_priority;
fn set_hitresult_priority(&mut self, hitresult_priority: Option<PyHitResultPriority>) {
self.hitresult_priority = hitresult_priority.unwrap_or_default();
}
}
+17 -7
View File
@@ -93,14 +93,24 @@ impl PyScoreState {
impl Debug for PyScoreState {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let Self {
max_combo,
n_geki,
n_katu,
n300,
n100,
n50,
misses,
} = self;
f.debug_struct("ScoreState")
.field("max_combo", &self.max_combo)
.field("n_geki", &self.n_geki)
.field("n_katu", &self.n_katu)
.field("n300", &self.n300)
.field("n100", &self.n100)
.field("n50", &self.n50)
.field("misses", &self.misses)
.field("max_combo", max_combo)
.field("n_geki", n_geki)
.field("n_katu", n_katu)
.field("n300", n300)
.field("n100", n100)
.field("n50", n50)
.field("misses", misses)
.finish()
}
}