Skip to content

Commit

Permalink
fix: consider clock rate in map info (MaxOhn#618)
Browse files Browse the repository at this point in the history
* fix: consider clock rate in map info

* fix: fixed feature-gated code
  • Loading branch information
MaxOhn authored Feb 2, 2024
1 parent 5dc1f91 commit 0e8b1a1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bathbot/src/active/impls/edit_on_timeout/recent_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl RecentScoreEdit {
}];
}

let map_info = MapInfo::new(map, stars).mods(score.mods.bits()).to_string();
let map_info = MapInfo::new(map, stars).mods(&score.mods).to_string();
fields![fields { "Map Info".to_owned(), map_info, false }];

#[cfg(feature = "twitch")]
Expand Down
2 changes: 1 addition & 1 deletion bathbot/src/active/impls/edit_on_timeout/top_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl TopScoreEdit {
}];
}

let map_info = MapInfo::new(map, stars).mods(score.mods.bits()).to_string();
let map_info = MapInfo::new(map, stars).mods(&score.mods).to_string();
fields![fields { "Map Info", map_info, false }];

EmbedBuilder::new()
Expand Down
18 changes: 7 additions & 11 deletions bathbot/src/active/impls/simulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
commands::osu::parsed_map::AttachedSimulateMap,
core::Context,
embeds::{ComboFormatter, HitResultFormatter, KeyFormatter, PpFormatter},
manager::OsuMap,
manager::{Mods, OsuMap},
util::{
interaction::{InteractionComponent, InteractionModal},
osu::{grade_completion_mods_raw, MapInfo},
Expand Down Expand Up @@ -224,7 +224,7 @@ impl IActiveMessage for SimulateComponents {
fields.push(hits);
}

let map_info = self.map.map_info(clock_rate, stars, mods.bits());
let map_info = self.map.map_info(stars, Mods::from(mods.as_ref()));
fields![fields { "Map Info", map_info, false; }];

let mut embed = EmbedBuilder::new()
Expand Down Expand Up @@ -649,27 +649,23 @@ impl SimulateMap {
}
}

pub fn map_info(&self, clock_rate: Option<f32>, stars: f32, mods: u32) -> String {
pub fn map_info(&self, stars: f32, mods: Mods) -> String {
match self {
Self::Full(map) => {
let mut map_info = MapInfo::new(map, stars);

if let Some(clock_rate) = clock_rate {
map_info.clock_rate(clock_rate);
}

map_info.mods(mods).to_string()
}
Self::Attached(map) => {
let map = &map.pp_map;

let mut builder = BeatmapAttributesBuilder::new(map);

if let Some(clock_rate) = clock_rate {
builder.clock_rate(clock_rate as f64);
if let Some(clock_rate) = mods.clock_rate {
builder.clock_rate(f64::from(clock_rate));
}

let attrs = builder.mode(map.mode).mods(mods).build();
let attrs = builder.mode(map.mode).mods(mods.bits).build();

let clock_rate = attrs.clock_rate;

Expand All @@ -695,7 +691,7 @@ impl SimulateMap {
}

let (cs_key, cs_value) = if map.mode == Mode::Mania {
("Keys", MapInfo::keys(mods, attrs.cs as f32))
("Keys", MapInfo::keys(mods.bits, attrs.cs as f32))
} else {
("CS", round(attrs.cs as f32))
};
Expand Down
2 changes: 1 addition & 1 deletion bathbot/src/commands/osu/leaderboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async fn leaderboard(

let mods_bits = specify_mods.as_ref().map_or(0, GameModsIntermode::bits);

let mut calc = ctx.pp(&map).mode(map.mode()).mods(mods_bits);
let mut calc = ctx.pp(&map).mode(map.mode()).mods(Mods::new(mods_bits));
let attrs_fut = calc.performance();

let scores_fut =
Expand Down
4 changes: 2 additions & 2 deletions bathbot/src/commands/osu/recent/leaderboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
GameModeOption,
},
core::commands::{prefix::Args, CommandOrigin},
manager::redis::osu::UserArgs,
manager::{redis::osu::UserArgs, Mods},
Context,
};

Expand Down Expand Up @@ -327,7 +327,7 @@ pub(super) async fn leaderboard(

let mods_bits = specify_mods.as_ref().map_or(0, GameModsIntermode::bits);

let mut calc = ctx.pp(&map).mode(map.mode()).mods(mods_bits);
let mut calc = ctx.pp(&map).mode(map.mode()).mods(Mods::new(mods_bits));
let attrs = calc.performance().await;

if let Some(ModSelection::Exclude(ref mods)) = mods {
Expand Down
2 changes: 1 addition & 1 deletion bathbot/src/embeds/tracking/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl TrackNotificationEmbed {
let attrs = ctx
.pp(map)
.mode(score.mode)
.mods(score.mods.bits())
.mods(&score.mods)
.performance()
.await;

Expand Down
6 changes: 4 additions & 2 deletions bathbot/src/manager/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,16 @@ impl<'s> From<&'s LeaderboardScore> for ScoreData {
}
}

/// Mods with an optional custom clock rate.
#[derive(Copy, Clone, Default, PartialEq)]
pub struct Mods {
pub bits: u32,
pub clock_rate: Option<f32>,
}

impl From<u32> for Mods {
fn from(bits: u32) -> Self {
impl Mods {
/// Create new [`Mods`] without a custom clock rate.
pub fn new(bits: u32) -> Self {
Self {
bits,
clock_rate: None,
Expand Down
24 changes: 8 additions & 16 deletions bathbot/src/util/osu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use time::OffsetDateTime;
use crate::{
core::{BotConfig, Context},
embeds::HitResultFormatter,
manager::{redis::RedisData, OsuMap},
manager::{redis::RedisData, Mods, OsuMap},
};

pub fn grade_emote(grade: Grade) -> &'static str {
Expand Down Expand Up @@ -575,28 +575,20 @@ pub async fn get_combined_thumbnail<'s>(
pub struct MapInfo<'map> {
map: &'map OsuMap,
stars: f32,
mods: Option<u32>,
clock_rate: Option<f32>,
mods: Mods,
}

impl<'map> MapInfo<'map> {
pub fn new(map: &'map OsuMap, stars: f32) -> Self {
Self {
map,
stars,
mods: None,
clock_rate: None,
mods: Mods::default(),
}
}

pub fn mods(&mut self, mods: u32) -> &mut Self {
self.mods = Some(mods);

self
}

pub fn clock_rate(&mut self, clock_rate: f32) -> &mut Self {
self.clock_rate = Some(clock_rate);
pub fn mods(&mut self, mods: impl Into<Mods>) -> &mut Self {
self.mods = mods.into();

self
}
Expand Down Expand Up @@ -635,12 +627,12 @@ impl Display for MapInfo<'_> {
GameMode::Mania => Mode::Mania,
};

let mods = self.mods.unwrap_or(0);
let mods = self.mods.bits;

let mut builder = BeatmapAttributesBuilder::new(&self.map.pp_map);

if let Some(clock_rate) = self.clock_rate {
builder.clock_rate(clock_rate as f64);
if let Some(clock_rate) = self.mods.clock_rate {
builder.clock_rate(f64::from(clock_rate));
}

let attrs = builder.mode(mode).mods(mods).build();
Expand Down

0 comments on commit 0e8b1a1

Please sign in to comment.