Add bpm to beatmap quick information

This commit is contained in:
Natsu Kagami 2020-06-18 14:19:43 -04:00
parent 3b260aa3e7
commit fde913ebc4
Signed by: nki
GPG key ID: 73376E117CD20735
3 changed files with 15 additions and 4 deletions

View file

@ -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(),

View file

@ -46,6 +46,7 @@ pub struct Difficulty {
pub count_spinner: u64,
pub max_combo: Option<u64>,
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<String>,

View file

@ -119,7 +119,6 @@ impl TryFrom<raw::Beatmap> 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<raw::Beatmap> 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)?,
},