@@ -11,20 +11,15 @@ use rosu_v2::model::mods::{
1111
1212pub struct ModsFormatter < ' a > {
1313 mods : & ' a GameMods ,
14+ legacy_order : bool ,
1415}
1516
1617impl < ' 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}
0 commit comments