Display scores smartly based on classic/lazer

This commit is contained in:
Natsu Kagami 2024-02-14 01:02:31 +01:00
parent eb8e1e70fd
commit 7f6fe35a77
Signed by: nki
GPG key ID: 55A032EB38B49ADB
4 changed files with 10 additions and 5 deletions

View file

@ -400,7 +400,7 @@ impl<'a> ScoreEmbedBuilder<'a> {
"Score stats", "Score stats",
format!( format!(
"**{}** | {} | **{:.2}%**", "**{}** | {} | **{:.2}%**",
grouped_number(s.score), grouped_number(s.score.unwrap_or(s.normalized_score as u64)),
max_combo, max_combo,
accuracy accuracy
), ),

View file

@ -386,7 +386,9 @@ async fn show_leaderboard(
OrderBy::PP => scores.sort_by(|(a, _, _), (b, _, _)| { OrderBy::PP => scores.sort_by(|(a, _, _), (b, _, _)| {
b.partial_cmp(a).unwrap_or(std::cmp::Ordering::Equal) b.partial_cmp(a).unwrap_or(std::cmp::Ordering::Equal)
}), }),
OrderBy::Score => scores.sort_by(|(_, _, a), (_, _, b)| b.score.cmp(&a.score)), OrderBy::Score => {
scores.sort_by(|(_, _, a), (_, _, b)| b.normalized_score.cmp(&a.normalized_score))
}
}; };
scores scores
}; };
@ -411,6 +413,7 @@ async fn show_leaderboard(
.await?; .await?;
return Ok(()); return Ok(());
} }
let has_lazer_score = scores.iter().any(|(_, _, v)| v.score.is_none());
paginate_reply_fn( paginate_reply_fn(
move |page: u8, ctx: &Context, m: &mut Message| { move |page: u8, ctx: &Context, m: &mut Message| {
@ -454,7 +457,7 @@ async fn show_leaderboard(
.iter() .iter()
.map(|(pp, _, s)| match order { .map(|(pp, _, s)| match order {
OrderBy::PP => format!("{:.2}", pp), OrderBy::PP => format!("{:.2}", pp),
OrderBy::Score => crate::discord::embeds::grouped_number(s.score), OrderBy::Score => crate::discord::embeds::grouped_number(if has_lazer_score { s.normalized_score as u64 } else { s.score.unwrap() }),
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let pw = pp.iter().map(|v| v.len()).max().unwrap_or(pp_label.len()); let pw = pp.iter().map(|v| v.len()).max().unwrap_or(pp_label.len());

View file

@ -542,7 +542,8 @@ pub struct Score {
pub replay_available: bool, pub replay_available: bool,
pub beatmap_id: u64, pub beatmap_id: u64,
pub score: u64, pub score: Option<u64>,
pub normalized_score: u32,
pub pp: Option<f64>, pub pp: Option<f64>,
pub rank: Rank, pub rank: Rank,
pub mods: Mods, // Later pub mods: Mods, // Later

View file

@ -144,7 +144,8 @@ impl From<rosu::score::Score> for Score {
date: time_to_utc(s.ended_at), date: time_to_utc(s.ended_at),
replay_available: s.replay, replay_available: s.replay,
beatmap_id: s.map_id as u64, beatmap_id: s.map_id as u64,
score: s.score as u64, score: Some(s.legacy_score as u64).filter(|v| *v > 0),
normalized_score: s.score,
pp: s.pp.map(|v| v as f64), pp: s.pp.map(|v| v as f64),
rank: s.grade.into(), rank: s.grade.into(),
mods: s mods: s