replace GameMode pystruct with simple number

This commit is contained in:
MaxOhn
2022-07-06 14:56:48 +02:00
parent 996af9443b
commit 3975be4fb2
4 changed files with 25 additions and 40 deletions
+3
View File
@@ -1,3 +1,6 @@
## Upcoming
- Removed the `GameMode` class again; use simple numbers instead (0/1/2/3)
# v0.6.0 (2022-07-05)
- Updated to [PyO3 v0.16](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md#0165---2022-05-15) from v0.15
- Updated to [rosu-pp v0.6](https://github.com/MaxOhn/rosu-pp/blob/main/CHANGELOG.md#v060-2022-07-05)
+2 -2
View File
@@ -22,9 +22,9 @@ calculator.set_od(9.2)
```
2) Next, you need to create `ScoreParams`. It has the following fields:
```
mode: Optional[GameMode],
mode: Optional[int],
specify for scores on convert maps, default to the map's native mode
available enum variants are GameMode.Osu, GameMode.Taiko, GameMode.Catch, and GameMode.Mania
available values are 0 for standard, 1 for taiko, 2 for catch, and 3 for mania
mods: Optional[int],
bit value for mods, defaults to 0 (NM) see https://github.com/ppy/osu-api/wiki#mods
acc: Optional[float],
+3 -10
View File
@@ -1,11 +1,4 @@
from typing import Iterable, List, Union
from enum import Enum
class GameMode(Enum):
Osu = 0
Taiko = 1
Catch = 2
Mania = 3
class ScoreParams:
"""
@@ -14,9 +7,9 @@ class ScoreParams:
## Attributes
`mode`: Optional[GameMode]
Mode to convert the map. Only does something if the original map is osu!standard and
the specified mode is taiko, catch, or mania. Defaults to the map's native mode.
`mode`: Optional[int]
Mode to convert the map. Only does something if the original map is osu!standard (0) and
the specified mode is taiko (1), catch (2), or mania (3). Defaults to the map's native mode.
`mods`: Optional[int]
Bit value for mods, defaults to 0 (NM) see [https://github.com/ppy/osu-api/wiki#mods](https://github.com/ppy/osu-api/wiki#mods)
`acc`: Optional[float]
+17 -28
View File
@@ -14,8 +14,7 @@ use pyo3::{
use rosu_pp::{
beatmap::BeatmapAttributes, catch::CatchPerformanceAttributes,
mania::ManiaPerformanceAttributes, osu::OsuPerformanceAttributes,
taiko::TaikoPerformanceAttributes, AnyPP, Beatmap, BeatmapExt, GameMode as RosuGameMode,
PerformanceAttributes,
taiko::TaikoPerformanceAttributes, AnyPP, Beatmap, BeatmapExt, GameMode, PerformanceAttributes,
};
#[pyclass]
@@ -148,33 +147,11 @@ impl Calculator {
}
}
#[pyclass]
#[derive(Copy, Clone, PartialEq)]
#[repr(u8)]
enum GameMode {
Osu,
Taiko,
Catch,
Mania,
}
impl From<GameMode> for RosuGameMode {
#[inline]
fn from(mode: GameMode) -> Self {
match mode {
GameMode::Osu => RosuGameMode::STD,
GameMode::Taiko => RosuGameMode::TKO,
GameMode::Catch => RosuGameMode::CTB,
GameMode::Mania => RosuGameMode::MNA,
}
}
}
#[pyclass]
#[derive(Clone, Default, PartialEq)]
struct ScoreParams {
#[pyo3(get, set)]
mode: Option<GameMode>,
mode: Option<u8>,
#[pyo3(get, set)]
mods: u32,
#[pyo3(get, set)]
@@ -425,8 +402,16 @@ impl ScoreParams {
clock_rate,
} = self;
if let Some(mode) = mode {
calculator = calculator.mode(mode.into());
if let Some(mode @ 0..=3) = mode {
let mode = match mode {
0 => GameMode::STD,
1 => GameMode::TKO,
2 => GameMode::CTB,
3 => GameMode::MNA,
_ => unreachable!(),
};
calculator = calculator.mode(mode);
}
if let Some(n300) = n300 {
@@ -652,6 +637,7 @@ impl Display for ScoreParams {
write!(
f,
"ScoreParams {{ \
mode: {}, \
mods: {}, \
n300: {}, \
n100: {}, \
@@ -664,6 +650,10 @@ impl Display for ScoreParams {
passedObjects: {}, \
clockRate: {} \
}}",
match self.mode {
Some(ref mode) => mode as &dyn Display,
None => &"None" as &dyn Display,
},
self.mods,
match self.n300 {
Some(ref n300) => n300 as &dyn Display,
@@ -711,7 +701,6 @@ impl Display for ScoreParams {
#[pymodule]
fn rosu_pp_py(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<GameMode>()?;
m.add_class::<ScoreParams>()?;
m.add_class::<Calculator>()?;
m.add_class::<CalculateResult>()?;