Skip to content

Commit df36be2

Browse files
authored
feat: use legacy mod order on stable data (#1041)
* refactor: remove redundant type * feat: use legacy mod order on stable data
1 parent d581fa4 commit df36be2

16 files changed

Lines changed: 70 additions & 55 deletions

File tree

bathbot-util/src/mods_fmt.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ use rosu_v2::model::mods::{
1111

1212
pub struct ModsFormatter<'a> {
1313
mods: &'a GameMods,
14+
legacy_order: bool,
1415
}
1516

1617
impl<'a> ModsFormatter<'a> {
17-
pub fn new(mods: &'a GameMods) -> Self {
18-
Self { mods }
18+
pub fn new(mods: &'a GameMods, legacy_order: bool) -> Self {
19+
Self { mods, legacy_order }
1920
}
20-
}
21-
22-
impl Display for ModsFormatter<'_> {
23-
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
24-
if self.mods.is_empty() {
25-
return f.write_str("NM");
26-
}
2721

22+
fn format_mods(&self, f: &mut Formatter<'_>) -> FmtResult {
2823
for gamemod in self.mods.iter() {
2924
f.write_str(gamemod.acronym().as_str())?;
3025

@@ -49,16 +44,35 @@ impl Display for ModsFormatter<'_> {
4944
write!(f, "({}x)", (*speed_change * 100.0).round() / 100.0)?
5045
}
5146
}
52-
53-
GameMod::DifficultyAdjustOsu(_)
54-
| GameMod::DifficultyAdjustTaiko(_)
55-
| GameMod::DifficultyAdjustCatch(_)
56-
| GameMod::DifficultyAdjustMania(_) => {} // TODO: print something?
57-
5847
_ => {}
5948
}
6049
}
6150

6251
Ok(())
6352
}
53+
54+
fn legacacy_format_mods(&self, f: &mut Formatter<'_>) -> FmtResult {
55+
let mut mods: Vec<_> = self.mods.iter().collect();
56+
mods.sort_unstable_by_key(|m| m.bits());
57+
58+
for m in mods {
59+
f.write_str(m.acronym().as_str())?
60+
}
61+
62+
Ok(())
63+
}
64+
}
65+
66+
impl Display for ModsFormatter<'_> {
67+
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
68+
if self.mods.is_empty() {
69+
return f.write_str("NM");
70+
}
71+
72+
if self.legacy_order {
73+
self.legacacy_format_mods(f)
74+
} else {
75+
self.format_mods(f)
76+
}
77+
}
6478
}

bathbot/src/active/impls/compare/scores.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn write_compact_entry(
189189
Some(entry.score.score_id),
190190
entry.score.is_legacy()
191191
),
192-
mods = ModsFormatter::new(&entry.score.mods),
192+
mods = ModsFormatter::new(&entry.score.mods, entry.score.is_legacy),
193193
stars = entry.stars,
194194
pp_format = if pp_idx == Some(i) { "**" } else { "~~" },
195195
pp = entry.score.pp,

bathbot/src/active/impls/higherlower/score_pp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl ScorePp {
187187
format!(
188188
"**{map} +{mods}**\n{grade} {score} • **{acc}%** • **{combo}x**{max_combo} {miss}• **{pp}pp**",
189189
map = self.map_string,
190-
mods = ModsFormatter::new(&self.mods),
190+
mods = ModsFormatter::new(&self.mods, false),
191191
// No `GradeFormatter` here because we don't want to hyperlink to
192192
// the score for obvious reasons.
193193
grade = grade_emote(self.grade),

bathbot/src/active/impls/leaderboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Display for ScoreFormatter<'_> {
247247
),
248248
score = WithComma::new(score),
249249
combo = self.combo,
250-
mods = ModsFormatter::new(&self.score.mods),
250+
mods = ModsFormatter::new(&self.score.mods, self.score_data.is_legacy()),
251251
pp = self.pp,
252252
acc = self.score.accuracy,
253253
miss = MissFormat(self.score.statistics.miss),

bathbot/src/active/impls/nochoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl IActiveMessage for NoChokePagination {
8282
title = map.title().cow_escape_markdown(),
8383
version = map.version().cow_escape_markdown(),
8484
id = map.map_id(),
85-
mods = ModsFormatter::new(&original_score.mods),
85+
mods = ModsFormatter::new(&original_score.mods, original_score.is_legacy),
8686
grade = GradeFormatter::new(
8787
entry.unchoked_grade(),
8888
Some(entry.original_score.score_id),

bathbot/src/active/impls/osustats/best.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl IActiveMessage for OsuStatsBestPagination {
9696
title = score.map.title,
9797
version = score.map.version,
9898
map_id = score.map.map_id,
99-
mods = ModsFormatter::new(&score.mods),
99+
mods = ModsFormatter::new(&score.mods, true),
100100
user = score.user.username,
101101
user_id = score.user.user_id,
102102
grade = config.grade(score.grade),

bathbot/src/active/impls/osustats/scores.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl IActiveMessage for OsuStatsScoresPagination {
176176
title = map.title().cow_escape_markdown(),
177177
version = map.version().cow_escape_markdown(),
178178
map_id = map.map_id(),
179-
mods = ModsFormatter::new(&score.mods),
179+
mods = ModsFormatter::new(&score.mods, true),
180180
pp = PpFormatter::new(Some(score.pp), Some(*max_pp)),
181181
acc = round(score.accuracy),
182182
score = WithComma::new(score.score),

bathbot/src/active/impls/relax/top.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl IActiveMessage for RelaxTopPagination {
122122
title = map.title().cow_escape_markdown(),
123123
version = map.version().cow_escape_markdown(),
124124
map_id = score.beatmap_id,
125-
mods = ModsFormatter::new(mods),
125+
mods = ModsFormatter::new(mods, false),
126126
pp = PpFormatter::new(score_pp, Some(max_pp)),
127127
acc = round(score.accuracy),
128128
score = WithComma::new(score.total_score),

bathbot/src/active/impls/simulate/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ impl IActiveMessage for SimulateComponents {
244244
n_objects,
245245
self.map.mode(),
246246
n_objects,
247+
// Could use `self.data.set_on_lazer` but using the legacy
248+
// formatting of mods does not show custom rates & co so it's
249+
// probably best to always use the new formatting
250+
false,
247251
);
248252

249253
fields![fields { "Grade", grade.to_string(), true; }];

bathbot/src/active/impls/single_score.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,11 @@ fn apply_settings(
635635
writer.push_str("__");
636636
}
637637

638-
let _ = write!(writer, "+{}", ModsFormatter::new(&data.score.mods));
638+
let _ = write!(
639+
writer,
640+
"+{}",
641+
ModsFormatter::new(&data.score.mods, data.score.is_legacy)
642+
);
639643

640644
if mark_idx == MarkIndex::Some(i) {
641645
writer.push_str("__");
@@ -864,7 +868,11 @@ fn apply_settings(
864868
writer.push_str("__");
865869
}
866870

867-
let _ = write!(writer, "+{}", ModsFormatter::new(&data.score.mods));
871+
let _ = write!(
872+
writer,
873+
"+{}",
874+
ModsFormatter::new(&data.score.mods, data.score.is_legacy)
875+
);
868876

869877
if mark_idx == MarkIndex::Some(last_idx) {
870878
writer.push_str("__");
@@ -1012,7 +1020,11 @@ fn write_value(
10121020
}
10131021
}
10141022
Value::Mods => {
1015-
let _ = write!(writer, "+{}", ModsFormatter::new(&data.score.mods));
1023+
let _ = write!(
1024+
writer,
1025+
"+{}",
1026+
ModsFormatter::new(&data.score.mods, data.score.is_legacy)
1027+
);
10161028
}
10171029
Value::Score => {
10181030
let _ = write!(writer, "{}", ScoreFormatter::new(&data.score, score_data));

0 commit comments

Comments
 (0)