From fde913ebc43593cd500eee8ab00c4c2bf01bc33e Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 18 Jun 2020 14:19:43 -0400 Subject: [PATCH] Add bpm to beatmap quick information --- youmubot-osu/src/discord/embeds.rs | 14 ++++++++++++-- youmubot-osu/src/models/mod.rs | 3 ++- youmubot-osu/src/models/parse.rs | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index d349e30..536cc51 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -81,7 +81,7 @@ pub fn beatmap_embed<'a>( .field("Approach Rate", format!("{:.1}", diff.ar), true) .field("Overall Difficulty", format!("{:.1}", diff.od), true) .field("HP Drain", format!("{:.1}", diff.hp), true) - .field("BPM", b.bpm.round(), true) + .field("BPM", diff.bpm.round(), true) .fields(b.difficulty.max_combo.map(|v| ("Max combo", v, true))) .field("Mode", format_mode(m, b.mode), true) .fields(b.source.as_ref().map(|v| ("Source", v, true))) @@ -185,7 +185,7 @@ pub fn beatmapset_embed<'a>( .build(), true, ) - .field("BPM", b.bpm.round(), true) + .field("BPM", b.difficulty.bpm.round(), true) .fields(b.source.as_ref().map(|v| ("Source", v, false))) .field( "Tags", @@ -277,6 +277,14 @@ pub(crate) fn score_embed<'a>( }) .map(|pp| format!("{:.2}pp [?]", pp)) }); + let pp = mode + .to_oppai_mode() + .and_then(|op| { + content + .get_pp_from(oppai_rs::Combo::FC(0), accuracy as f32, Some(op), s.mods) + .ok() + }) + .and_then(|value| pp.map(|original| format!("{} ({:.2}pp if FC?)", original, value))); let score_line = pp .map(|pp| format!("{} | {}", &score_line, pp)) .unwrap_or(score_line); @@ -343,6 +351,8 @@ pub(crate) fn score_embed<'a>( .push_bold(format!("{:.1}", diff.od)) .push(", HP") .push_bold(format!("{:.1}", diff.hp)) + .push(", BPM ") + .push_bold(format!("{}", diff.bpm.round())) .push(", ⌛ ") .push_bold(format!("{}", Duration(diff.drain_length))) .build(), diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index d8d2b72..a721408 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -46,6 +46,7 @@ pub struct Difficulty { pub count_spinner: u64, pub max_combo: Option, + pub bpm: f64, pub drain_length: Duration, pub total_length: Duration, } @@ -85,6 +86,7 @@ impl Difficulty { self.od = (79.0 - (hit_timing - 0.5)) / 6.0; } fn apply_length_by_ratio(&mut self, mul: u32, div: u32) { + self.bpm = self.bpm / (mul as f64) * (div as f64); // Inverse since bpm increases while time decreases self.drain_length = self.drain_length * mul / div; self.total_length = self.total_length * mul / div; } @@ -234,7 +236,6 @@ pub struct Beatmap { pub artist: String, pub title: String, pub beatmapset_id: u64, - pub bpm: f64, pub creator: String, pub creator_id: u64, pub source: Option, diff --git a/youmubot-osu/src/models/parse.rs b/youmubot-osu/src/models/parse.rs index a653c16..a270bec 100644 --- a/youmubot-osu/src/models/parse.rs +++ b/youmubot-osu/src/models/parse.rs @@ -119,7 +119,6 @@ impl TryFrom for Beatmap { beatmap_id: parse_from_str(&raw.beatmap_id)?, beatmapset_id: parse_from_str(&raw.beatmapset_id)?, title: raw.title, - bpm: parse_from_str(&raw.bpm)?, creator: raw.creator, creator_id: parse_from_str(&raw.creator_id)?, source: raw.source.filter(|v| !v.is_empty()), @@ -139,6 +138,7 @@ impl TryFrom for Beatmap { count_slider: parse_from_str(&raw.count_slider)?, count_spinner: parse_from_str(&raw.count_spinner)?, max_combo: raw.max_combo.map(parse_from_str).transpose()?, + bpm: parse_from_str(&raw.bpm)?, drain_length: parse_duration(&raw.hit_length)?, total_length: parse_duration(&raw.total_length)?, },