rosu_pp/any/performance/
into.rs1use rosu_map::section::general::GameMode;
2
3use crate::{
4 any::{DifficultyAttributes, PerformanceAttributes},
5 model::mode::IGameMode,
6 Beatmap, Performance,
7};
8
9pub trait IntoModePerformance<'map, M: IGameMode> {
11 fn into_performance(self) -> M::Performance<'map>;
12}
13
14pub trait IntoPerformance<'a> {
16 fn into_performance(self) -> Performance<'a>;
17}
18
19macro_rules! impl_from_mode {
20 (
21 $(
22 $module:ident {
23 $mode:ident, $diff:ident, $perf:ident
24 }
25 ,)*
26 ) => {
27 $(
28 macro_rules! mode {
29 () => { crate::$module::$mode };
30 }
31
32 impl<'map> IntoModePerformance<'map, mode!()> for crate::$module::$diff {
33 fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
34 <mode!() as IGameMode>::Performance::from_map_or_attrs(self.into())
35 }
36 }
37
38 impl<'map> IntoModePerformance<'map, mode!()> for crate::$module::$perf {
39 fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
40 <mode!() as IGameMode>::Performance::from_map_or_attrs(self.difficulty.into())
41 }
42 }
43
44 impl<'a> IntoPerformance<'a> for crate::$module::$diff {
45 fn into_performance(self) -> Performance<'a> {
46 Performance::$mode(
47 <Self as IntoModePerformance<'a, mode!()>>::into_performance(self)
48 )
49 }
50 }
51
52 impl<'a> IntoPerformance<'a> for crate::$module::$perf {
53 fn into_performance(self) -> Performance<'a> {
54 Performance::$mode(
55 <Self as IntoModePerformance<'a, mode!()>>::into_performance(self)
56 )
57 }
58 }
59
60 impl<'map> IntoModePerformance<'map, mode!()> for &'map Beatmap {
61 fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
62 <mode!() as IGameMode>::Performance::from_map_or_attrs(self.into())
63 }
64 }
65
66 impl<'a> IntoModePerformance<'a, mode!()> for Beatmap {
67 fn into_performance(self) -> <mode!() as IGameMode>::Performance<'a> {
68 <mode!() as IGameMode>::Performance::from_map_or_attrs(self.into())
69 }
70 }
71 )*
72 };
73}
74
75impl_from_mode!(
76 osu {
77 Osu,
78 OsuDifficultyAttributes,
79 OsuPerformanceAttributes
80 },
81 taiko {
82 Taiko,
83 TaikoDifficultyAttributes,
84 TaikoPerformanceAttributes
85 },
86 catch {
87 Catch,
88 CatchDifficultyAttributes,
89 CatchPerformanceAttributes
90 },
91 mania {
92 Mania,
93 ManiaDifficultyAttributes,
94 ManiaPerformanceAttributes
95 },
96);
97
98impl<'a> IntoPerformance<'a> for Beatmap {
99 fn into_performance(self) -> Performance<'a> {
100 match self.mode {
101 GameMode::Osu => Performance::Osu(self.into()),
102 GameMode::Taiko => Performance::Taiko(self.into()),
103 GameMode::Catch => Performance::Catch(self.into()),
104 GameMode::Mania => Performance::Mania(self.into()),
105 }
106 }
107}
108
109impl<'map> IntoPerformance<'map> for &'map Beatmap {
110 fn into_performance(self) -> Performance<'map> {
111 match self.mode {
112 GameMode::Osu => Performance::Osu(self.into()),
113 GameMode::Taiko => Performance::Taiko(self.into()),
114 GameMode::Catch => Performance::Catch(self.into()),
115 GameMode::Mania => Performance::Mania(self.into()),
116 }
117 }
118}
119
120impl<'a> IntoPerformance<'a> for DifficultyAttributes {
121 fn into_performance(self) -> Performance<'a> {
122 match self {
123 Self::Osu(attrs) => Performance::Osu(attrs.into()),
124 Self::Taiko(attrs) => Performance::Taiko(attrs.into()),
125 Self::Catch(attrs) => Performance::Catch(attrs.into()),
126 Self::Mania(attrs) => Performance::Mania(attrs.into()),
127 }
128 }
129}
130
131impl<'a> IntoPerformance<'a> for PerformanceAttributes {
132 fn into_performance(self) -> Performance<'a> {
133 match self {
134 Self::Osu(attrs) => Performance::Osu(attrs.difficulty.into()),
135 Self::Taiko(attrs) => Performance::Taiko(attrs.difficulty.into()),
136 Self::Catch(attrs) => Performance::Catch(attrs.difficulty.into()),
137 Self::Mania(attrs) => Performance::Mania(attrs.difficulty.into()),
138 }
139 }
140}