1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
mod ext;
mod format;
#[cfg(feature = "experimental-diff-calc")]
#[cfg_attr(docsrs, doc(cfg(feature = "experimental-diff-calc")))]
pub mod diff_calc;
#[cfg(feature = "experimental-diff-calc")]
#[cfg_attr(docsrs, doc(cfg(feature = "experimental-diff-calc")))]
pub mod pp_calc;
use crate::color::Color;
use crate::data::{GridSize, Mode};
use crate::events::Event;
use crate::hitobject::{HitObject, HitObjectKind};
use crate::hitsounds::SampleSet;
use crate::timing::{Millis, TimingPoint};
pub use self::ext::DoubleIter;
pub use self::format::*;
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Difficulty {
pub hp_drain_rate: f32,
pub circle_size: f32,
pub overall_difficulty: f32,
pub approach_rate: f32,
pub slider_multiplier: f64,
pub slider_tick_rate: f64,
}
impl Difficulty {
pub fn circle_size_osupx(&self) -> f32 {
54.4 - 4.48 * self.circle_size
}
pub fn approach_preempt(&self) -> Millis {
Millis(if self.approach_rate < 5.0 {
1200 + (600.0 * (5.0 - self.approach_rate)) as i32 / 5
} else if self.approach_rate > 5.0 {
1200 - (750.0 * (self.approach_rate - 5.0)) as i32 / 5
} else {
1200
})
}
pub fn approach_fade_time(&self) -> Millis {
Millis(if self.approach_rate < 5.0 {
800 + (400.0 * (5.0 - self.approach_rate)) as i32 / 5
} else if self.approach_rate > 5.0 {
800 - (500.0 * (self.approach_rate - 5.0)) as i32 / 5
} else {
800
})
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Beatmap {
pub version: u32,
pub audio_filename: String,
pub audio_leadin: Millis,
pub preview_time: Millis,
pub countdown: bool,
pub sample_set: SampleSet,
pub stack_leniency: f64,
pub mode: Mode,
pub letterbox_in_breaks: bool,
pub widescreen_storyboard: bool,
pub difficulty: Difficulty,
pub bookmarks: Vec<i32>,
pub distance_spacing: f64,
pub beat_divisor: u8,
pub grid_size: GridSize,
pub timeline_zoom: f64,
pub title: String,
pub title_unicode: String,
pub artist: String,
pub artist_unicode: String,
pub creator: String,
pub difficulty_name: String,
pub source: String,
pub tags: Vec<String>,
pub beatmap_id: i32,
pub beatmap_set_id: i32,
pub events: Vec<Event>,
pub colors: Vec<Color>,
pub hit_objects: Vec<HitObject>,
pub timing_points: Vec<TimingPoint>,
}
impl Default for Beatmap {
fn default() -> Self {
Beatmap {
version: 0,
audio_filename: String::new(),
audio_leadin: Millis(0),
preview_time: Millis(0),
countdown: false,
sample_set: SampleSet::Default,
stack_leniency: 0.7,
mode: Mode::Osu,
letterbox_in_breaks: false,
widescreen_storyboard: false,
difficulty: Difficulty::default(),
bookmarks: Vec::new(),
distance_spacing: 0.0,
beat_divisor: 1,
grid_size: GridSize::Tiny,
timeline_zoom: 0.0,
title: String::new(),
title_unicode: String::new(),
artist: String::new(),
artist_unicode: String::new(),
creator: String::new(),
difficulty_name: String::new(),
source: String::new(),
tags: Vec::new(),
beatmap_id: 0,
beatmap_set_id: -1,
events: Vec::new(),
colors: Vec::new(),
hit_objects: Vec::new(),
timing_points: Vec::new(),
}
}
}
impl Beatmap {
pub fn locate_timing_point(&self, time: impl Into<Millis>) -> Option<TimingPoint> {
let mut tp = None;
let time = time.into();
for timing_point in self.timing_points.iter() {
if timing_point.time < time {
tp = Some(timing_point.clone());
}
}
tp
}
pub fn locate_hitobject(&self, time: impl Into<Millis>) -> Option<HitObject> {
let time = time.into();
for hit_object in self.hit_objects.iter() {
if hit_object.start_time == time {
return Some(hit_object.clone());
}
if let HitObjectKind::Slider { .. } = hit_object.kind {}
}
None
}
}