Update rosu-pp and rosu-v2

This commit is contained in:
Natsu Kagami 2024-11-18 13:52:16 +01:00
parent 803d718c7a
commit a4fab5438b
Signed by: nki
GPG key ID: 55A032EB38B49ADB
5 changed files with 47 additions and 53 deletions

21
Cargo.lock generated
View file

@ -1807,10 +1807,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c55926c8f0fed1db12fbe96f7a6083a2c4186443dd32532ab34e6902467a4f3" checksum = "3c55926c8f0fed1db12fbe96f7a6083a2c4186443dd32532ab34e6902467a4f3"
[[package]] [[package]]
name = "rosu-mods" name = "rosu-map"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d69daf02885f7477085403a6eada6215f44333c7b54355ea1c4e276a02263bde" checksum = "21de4f8c5cd2738e1c9a2ed477aad2579dacd5acf3845d80738fcec160d0bd8a"
[[package]]
name = "rosu-mods"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0fb1475e860c987673e8abc1df5d23f22c4e1ae62e9459e656cff4d82f603b"
dependencies = [ dependencies = [
"paste", "paste",
"serde", "serde",
@ -1819,17 +1825,16 @@ dependencies = [
[[package]] [[package]]
name = "rosu-pp" name = "rosu-pp"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/MaxOhn/rosu-pp?branch=main#9f45d9594d08ba79d3c1c73ec43aef2fd7b54c0d"
checksum = "002a6b12cedcb185f4051f0b3d0466e0b61ff414a9ca8375f09be581c0e70f06"
dependencies = [ dependencies = [
"rosu-map", "rosu-map 0.2.0",
"rosu-mods", "rosu-mods",
] ]
[[package]] [[package]]
name = "rosu-v2" name = "rosu-v2"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/MaxOhn/rosu-v2?branch=lazer#04744c606962f21824d7398f1c15c34fe7fa9eef" source = "git+https://github.com/MaxOhn/rosu-v2?branch=lazer#4552ffa6e4e8d375c4a6f0a4cc2d21c4f61a129f"
dependencies = [ dependencies = [
"bytes", "bytes",
"dashmap 6.0.1", "dashmap 6.0.1",
@ -3310,7 +3315,7 @@ dependencies = [
"rand", "rand",
"regex", "regex",
"reqwest", "reqwest",
"rosu-map", "rosu-map 0.1.1",
"rosu-pp", "rosu-pp",
"rosu-v2", "rosu-v2",
"serde", "serde",

View file

@ -14,7 +14,7 @@ dashmap = "5.3.4"
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1.5.6" regex = "1.5.6"
reqwest = "0.11.10" reqwest = "0.11.10"
rosu-pp = "1.1" rosu-pp = { git = "https://github.com/MaxOhn/rosu-pp", branch = "main" }
rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" } rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" }
rosu-map = "0.1" rosu-map = "0.1"
time = "0.3" time = "0.3"

View file

@ -23,13 +23,13 @@ pub struct ToPrint<'a> {
lazy_static! { lazy_static! {
// Beatmap(set) hooks // Beatmap(set) hooks
static ref OLD_LINK_REGEX: Regex = Regex::new( static ref OLD_LINK_REGEX: Regex = Regex::new(
r"(?:https?://)?osu\.ppy\.sh/(?P<link_type>s|b|beatmaps)/(?P<id>\d+)(?:[\&\?]m=(?P<mode>[0123]))?(?:\+(?P<mods>[A-Z]+))?" r"(?:https?://)?osu\.ppy\.sh/(?P<link_type>s|b|beatmaps)/(?P<id>\d+)(?:[\&\?]m=(?P<mode>[0123]))?(?:\+(?P<mods>\S+\b))?"
).unwrap(); ).unwrap();
static ref NEW_LINK_REGEX: Regex = Regex::new( static ref NEW_LINK_REGEX: Regex = Regex::new(
r"(?:https?://)?osu\.ppy\.sh/beatmapsets/(?P<set_id>\d+)/?(?:\#(?P<mode>osu|taiko|fruits|mania)(?:/(?P<beatmap_id>\d+)|/?))?(?:\+(?P<mods>[A-Z]+))?" r"(?:https?://)?osu\.ppy\.sh/beatmapsets/(?P<set_id>\d+)/?(?:\#(?P<mode>osu|taiko|fruits|mania)(?:/(?P<beatmap_id>\d+)|/?))?(?:\+(?P<mods>\S+\b))?"
).unwrap(); ).unwrap();
static ref SHORT_LINK_REGEX: Regex = Regex::new( static ref SHORT_LINK_REGEX: Regex = Regex::new(
r"(?:^|\s|\W)(?P<main>/b/(?P<id>\d+)(?:/(?P<mode>osu|taiko|fruits|mania))?(?:\+(?P<mods>[A-Z]+))?)" r"(?:^|\s|\W)(?P<main>/b/(?P<id>\d+)(?:/(?P<mode>osu|taiko|fruits|mania))?(?:\+(?P<mods>\S+\b))?)"
).unwrap(); ).unwrap();
// Score hook // Score hook

View file

@ -424,7 +424,7 @@ impl Beatmap {
Some(mode) if mode != self.mode => format!("/{}", mode.as_str_new_site()), Some(mode) if mode != self.mode => format!("/{}", mode.as_str_new_site()),
_ => "".to_owned(), _ => "".to_owned(),
}, },
mods.strip_lazer(override_mode.unwrap_or(Mode::Std)) mods
) )
} }

View file

@ -23,7 +23,7 @@ lazy_static::lazy_static! {
#[derive(Debug, Clone, PartialEq, Default)] #[derive(Debug, Clone, PartialEq, Default)]
pub struct UnparsedMods { pub struct UnparsedMods {
mods: Cow<'static, str>, mods: Cow<'static, str>,
clock: Option<f32>, clock: Option<f64>,
} }
impl FromStr for UnparsedMods { impl FromStr for UnparsedMods {
@ -47,7 +47,7 @@ impl FromStr for UnparsedMods {
mods: mods.map(|v| v.into()).unwrap_or("".into()), mods: mods.map(|v| v.into()).unwrap_or("".into()),
clock: ms clock: ms
.name("clock") .name("clock")
.map(|v| v.as_str().parse::<f32>().unwrap()) .map(|v| v.as_str().parse::<_>().unwrap())
.filter(|v| *v > 0.0), .filter(|v| *v > 0.0),
}) })
} }
@ -149,13 +149,8 @@ pub struct Stats {
} }
impl Stats { impl Stats {
pub fn from_f32(ar: Option<f32>, od: Option<f32>, hp: Option<f32>, cs: Option<f32>) -> Self { pub fn from_option(ar: Option<f64>, od: Option<f64>, hp: Option<f64>, cs: Option<f64>) -> Self {
Self { Self { ar, od, hp, cs }
ar: ar.map(|v| v as f64),
od: od.map(|v| v as f64),
hp: hp.map(|v| v as f64),
cs: cs.map(|v| v as f64),
}
} }
pub fn has_any(&self) -> bool { pub fn has_any(&self) -> bool {
@ -168,26 +163,20 @@ impl Mods {
inner: GameMods::new(), inner: GameMods::new(),
}; };
pub fn strip_lazer(&self, mode: Mode) -> Self { // fn classic_mod_of(mode: Mode) -> rosu::GameMod {
let mut m = self.clone(); // match mode {
m.inner.insert(Self::classic_mod_of(mode)); // Mode::Std => rosu::GameMod::ClassicOsu(rosu::generated_mods::ClassicOsu::default()),
m // Mode::Taiko => {
} // rosu::GameMod::ClassicTaiko(rosu::generated_mods::ClassicTaiko::default())
// }
fn classic_mod_of(mode: Mode) -> rosu::GameMod { // Mode::Catch => {
match mode { // rosu::GameMod::ClassicCatch(rosu::generated_mods::ClassicCatch::default())
Mode::Std => rosu::GameMod::ClassicOsu(rosu::generated_mods::ClassicOsu::default()), // }
Mode::Taiko => { // Mode::Mania => {
rosu::GameMod::ClassicTaiko(rosu::generated_mods::ClassicTaiko::default()) // rosu::GameMod::ClassicMania(rosu::generated_mods::ClassicMania::default())
} // }
Mode::Catch => { // }
rosu::GameMod::ClassicCatch(rosu::generated_mods::ClassicCatch::default()) // }
}
Mode::Mania => {
rosu::GameMod::ClassicMania(rosu::generated_mods::ClassicMania::default())
}
}
}
pub fn overrides(&self) -> Stats { pub fn overrides(&self) -> Stats {
use rosu_v2::prelude::GameMod::*; use rosu_v2::prelude::GameMod::*;
@ -195,23 +184,23 @@ impl Mods {
.iter() .iter()
.find_map(|m| { .find_map(|m| {
Some(match m { Some(match m {
DifficultyAdjustOsu(da) => Stats::from_f32( DifficultyAdjustOsu(da) => Stats::from_option(
da.approach_rate, da.approach_rate,
da.overall_difficulty, da.overall_difficulty,
da.drain_rate, da.drain_rate,
da.circle_size, da.circle_size,
), ),
DifficultyAdjustTaiko(da) => { DifficultyAdjustTaiko(da) => {
Stats::from_f32(None, da.overall_difficulty, da.drain_rate, None) Stats::from_option(None, da.overall_difficulty, da.drain_rate, None)
} }
DifficultyAdjustCatch(da) => Stats::from_f32( DifficultyAdjustCatch(da) => Stats::from_option(
da.approach_rate, da.approach_rate,
da.overall_difficulty, da.overall_difficulty,
da.drain_rate, da.drain_rate,
da.circle_size, da.circle_size,
), ),
DifficultyAdjustMania(da) => { DifficultyAdjustMania(da) => {
Stats::from_f32(None, da.overall_difficulty, da.drain_rate, None) Stats::from_option(None, da.overall_difficulty, da.drain_rate, None)
} }
_ => return None, _ => return None,
}) })
@ -329,7 +318,7 @@ impl Mods {
use rosu::GameMod::*; use rosu::GameMod::*;
fn fmt_speed_change( fn fmt_speed_change(
mod_name: &str, mod_name: &str,
speed_change: &Option<f32>, speed_change: &Option<f64>,
adjust_pitch: &Option<bool>, adjust_pitch: &Option<bool>,
) -> Option<String> { ) -> Option<String> {
if speed_change.is_none() && adjust_pitch.is_none() { if speed_change.is_none() && adjust_pitch.is_none() {
@ -350,10 +339,10 @@ impl Mods {
Some(s) Some(s)
} }
fn fmt_diff_adj( fn fmt_diff_adj(
ar: Option<f32>, ar: Option<f64>,
od: Option<f32>, od: Option<f64>,
hp: Option<f32>, hp: Option<f64>,
cs: Option<f32>, cs: Option<f64>,
) -> Option<String> { ) -> Option<String> {
let stats = [("AR", ar), ("OD", od), ("HP", hp), ("CS", cs)]; let stats = [("AR", ar), ("OD", od), ("HP", hp), ("CS", cs)];
let mut output = String::with_capacity(4 * (2 + 3 + 4) + 3 * 2); let mut output = String::with_capacity(4 * (2 + 3 + 4) + 3 * 2);
@ -423,11 +412,11 @@ impl Mods {
} }
let intermode = let intermode =
GameModsIntermode::try_from_acronyms(s).ok_or_else(|| error!("Invalid mods: {}", s))?; GameModsIntermode::try_from_acronyms(s).ok_or_else(|| error!("Invalid mods: {}", s))?;
let mut inner = intermode let inner = intermode
.try_with_mode(mode.into()) .try_with_mode(mode.into())
.ok_or_else(|| error!("Invalid mods for `{}`: {}", mode, intermode))?; .ok_or_else(|| error!("Invalid mods for `{}`: {}", mode, intermode))?;
// Always add classic mod to `inner` // Always add classic mod to `inner`
inner.insert(Self::classic_mod_of(mode)); // inner.insert(Self::classic_mod_of(mode));
if !inner.is_valid() { if !inner.is_valid() {
return Err(error!("Incompatible mods found: {}", inner)); return Err(error!("Incompatible mods found: {}", inner));
} }