added convert support with rosu-pp update

This commit is contained in:
MaxOhn
2022-07-05 22:53:09 +02:00
parent 8fc141e9d8
commit e65888d7b9
7 changed files with 80 additions and 33 deletions
+3
View File
@@ -1,5 +1,8 @@
## Upcoming ## Upcoming
- Updated to [PyO3 v0.16](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md#0165---2022-05-15) from v0.15 - 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)
- Added the class `GameMode` to serve as enum e.g. `GameMode.Taiko`
- `ScoreParams` now have an additional field `mode: Optional[GameMode]` which can be used to convert to other modes
# v0.5.2 (2022-06-14) # v0.5.2 (2022-06-14)
- Bumped patch version of dependencies, including a [rosu-pp](https://github.com/MaxOhn/rosu-pp/blob/main/CHANGELOG.md#v052-2022-06-14) update - Bumped patch version of dependencies, including a [rosu-pp](https://github.com/MaxOhn/rosu-pp/blob/main/CHANGELOG.md#v052-2022-06-14) update
Generated
+3 -3
View File
@@ -170,13 +170,13 @@ dependencies = [
[[package]] [[package]]
name = "rosu-pp" name = "rosu-pp"
version = "0.5.2" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5c816e053b2305929c9416953b2a0c42e01a98072a2e06334ab4209826b6c62" checksum = "92439367271f2657f29f9e2bd1dc08d413a7d820139840001fe57a1b21500bfb"
[[package]] [[package]]
name = "rosu-pp-py" name = "rosu-pp-py"
version = "0.4.0" version = "0.6.0"
dependencies = [ dependencies = [
"pyo3", "pyo3",
"rosu-pp", "rosu-pp",
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "rosu-pp-py" name = "rosu-pp-py"
version = "0.4.0" version = "0.6.0"
description = "osu! difficulty and pp calculation for all modes" description = "osu! difficulty and pp calculation for all modes"
authors = ["Max Ohn <ohn.m@hotmail.de>"] authors = ["Max Ohn <ohn.m@hotmail.de>"]
license = "MIT" license = "MIT"
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
pyo3 = { version = "0.16", features = ["macros", "extension-module"] } pyo3 = { version = "0.16", features = ["macros", "extension-module"] }
rosu-pp = { version = "0.5" } rosu-pp = { version = "0.6" }
[profile.release] [profile.release]
lto = "fat" lto = "fat"
+3
View File
@@ -22,6 +22,8 @@ calculator.set_od(9.2)
``` ```
2) Next, you need to create `ScoreParams`. It has the following fields: 2) Next, you need to create `ScoreParams`. It has the following fields:
``` ```
mode: Optional[GameMode],
specify for scores on convert maps, default to the map's native mode
mods: Optional[int], mods: Optional[int],
bit value for mods, defaults to 0 (NM) see https://github.com/ppy/osu-api/wiki#mods bit value for mods, defaults to 0 (NM) see https://github.com/ppy/osu-api/wiki#mods
acc: Optional[float], acc: Optional[float],
@@ -66,6 +68,7 @@ calculator = Calculator('./maps/1980365.osu')
params1 = ScoreParams( params1 = ScoreParams(
mods = 8 + 16, # HDHR mods = 8 + 16, # HDHR
mode = GameMode.Catch,
acc = 97.89, acc = 97.89,
nMisses = 13, nMisses = 13,
combo = 1388, combo = 1388,
+1 -1
View File
@@ -5,7 +5,7 @@ build-backend = "maturin"
[project] [project]
name = "rosu-pp-py" name = "rosu-pp-py"
version = "0.5.2" version = "0.5.2"
requires-python = ">=3.6" requires-python = ">=3.7"
description = "osu! difficulty and pp calculation for all modes" description = "osu! difficulty and pp calculation for all modes"
classifiers = [ classifiers = [
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
+10
View File
@@ -1,4 +1,11 @@
from typing import Iterable, List, Union from typing import Iterable, List, Union
from enum import Enum
class GameMode(Enum):
Osu = 0
Taiko = 1
Catch = 2
Mania = 3
class ScoreParams: class ScoreParams:
""" """
@@ -7,6 +14,9 @@ class ScoreParams:
## Attributes ## 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.
`mods`: Optional[int] `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) 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] `acc`: Optional[float]
+35 -4
View File
@@ -12,9 +12,10 @@ use pyo3::{
types::{PyDict, PyIterator}, types::{PyDict, PyIterator},
}; };
use rosu_pp::{ use rosu_pp::{
catch::CatchPerformanceAttributes, mania::ManiaPerformanceAttributes, beatmap::BeatmapAttributes, catch::CatchPerformanceAttributes,
osu::OsuPerformanceAttributes, taiko::TaikoPerformanceAttributes, AnyPP, Beatmap, mania::ManiaPerformanceAttributes, osu::OsuPerformanceAttributes,
BeatmapAttributes, BeatmapExt, PerformanceAttributes, taiko::TaikoPerformanceAttributes, AnyPP, Beatmap, BeatmapExt, GameMode as RosuGameMode,
PerformanceAttributes,
}; };
#[pyclass] #[pyclass]
@@ -147,9 +148,32 @@ impl Calculator {
} }
} }
#[pyclass]
#[derive(Copy, Clone, PartialEq)]
#[repr(u8)]
enum GameMode {
Osu,
Taiko,
Catch,
Mania,
}
impl From<GameMode> for RosuGameMode {
fn from(mode: GameMode) -> Self {
match mode {
GameMode::Osu => RosuGameMode::STD,
GameMode::Taiko => RosuGameMode::TKO,
GameMode::Catch => RosuGameMode::CTB,
GameMode::Mania => RosuGameMode::MNA,
}
}
}
#[pyclass] #[pyclass]
#[derive(Clone, Default, PartialEq)] #[derive(Clone, Default, PartialEq)]
struct ScoreParams { struct ScoreParams {
#[pyo3(get, set)]
mode: Option<GameMode>,
#[pyo3(get, set)] #[pyo3(get, set)]
mods: u32, mods: u32,
#[pyo3(get, set)] #[pyo3(get, set)]
@@ -386,6 +410,7 @@ impl ScoreParams {
fn apply(self, mut calculator: AnyPP) -> AnyPP { fn apply(self, mut calculator: AnyPP) -> AnyPP {
let ScoreParams { let ScoreParams {
mode,
mods, mods,
n300, n300,
n100, n100,
@@ -399,6 +424,10 @@ impl ScoreParams {
clock_rate, clock_rate,
} = self; } = self;
if let Some(mode) = mode {
calculator = calculator.mode(mode.into());
}
if let Some(n300) = n300 { if let Some(n300) = n300 {
calculator = calculator.n300(n300); calculator = calculator.n300(n300);
} }
@@ -454,6 +483,7 @@ impl ScoreParams {
for (key, value) in dict.iter() { for (key, value) in dict.iter() {
if let Ok(key) = key.extract() { if let Ok(key) = key.extract() {
match key { match key {
"mode" => params.mode = Some(value.extract()?),
"mods" => params.mods = value.extract()?, "mods" => params.mods = value.extract()?,
"n300" => params.n300 = value.extract()?, "n300" => params.n300 = value.extract()?,
"n100" => params.n100 = value.extract()?, "n100" => params.n100 = value.extract()?,
@@ -467,7 +497,7 @@ impl ScoreParams {
"clockRate" => params.clock_rate = value.extract()?, "clockRate" => params.clock_rate = value.extract()?,
_ => { _ => {
return Err(PyTypeError::new_err(format!( return Err(PyTypeError::new_err(format!(
"got an unexpected keyword argument '{}'; expected 'mods', 'n300', 'n100', \ "got an unexpected keyword argument '{}'; expected 'mode', 'mods', 'n300', 'n100', \
'n50', 'nMisses', 'nKatu', 'acc', 'combo', 'score', 'passedObjects', 'clockRate'", 'n50', 'nMisses', 'nKatu', 'acc', 'combo', 'score', 'passedObjects', 'clockRate'",
key, key,
))) )))
@@ -680,6 +710,7 @@ impl Display for ScoreParams {
#[pymodule] #[pymodule]
fn rosu_pp_py(_py: Python, m: &PyModule) -> PyResult<()> { fn rosu_pp_py(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<GameMode>()?;
m.add_class::<ScoreParams>()?; m.add_class::<ScoreParams>()?;
m.add_class::<Calculator>()?; m.add_class::<Calculator>()?;
m.add_class::<CalculateResult>()?; m.add_class::<CalculateResult>()?;