various minor adjustments

This commit is contained in:
MaxOhn
2022-10-21 12:40:45 +02:00
parent 335f0a7dde
commit 5a129437eb
27 changed files with 268 additions and 202 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ impl HitObject {
#[inline]
pub fn end_time(&self) -> f64 {
match &self.kind {
HitObjectKind::Circle { .. } => self.start_time,
HitObjectKind::Circle => self.start_time,
// incorrect, only called in mania which has no sliders though
HitObjectKind::Slider { .. } => self.start_time,
HitObjectKind::Spinner { end_time } => *end_time,
@@ -30,7 +30,7 @@ impl HitObject {
/// If the object is a circle.
#[inline]
pub fn is_circle(&self) -> bool {
matches!(self.kind, HitObjectKind::Circle { .. })
matches!(self.kind, HitObjectKind::Circle)
}
/// If the object is a slider.
+4
View File
@@ -12,18 +12,22 @@ pub trait HitSound {
}
impl HitSound for u8 {
#[inline]
fn normal(self) -> bool {
self == 0
}
#[inline]
fn whistle(self) -> bool {
self & Self::HITSOUND_WHISTLE > 0
}
#[inline]
fn finish(self) -> bool {
self & Self::HITSOUND_FINISH > 0
}
#[inline]
fn clap(self) -> bool {
self & Self::HITSOUND_CLAP > 0
}
+11 -89
View File
@@ -689,7 +689,6 @@ macro_rules! parse_hitobjects_body {
sorter.toggle_marks();
sorter.sort(&mut $self.sounds);
}
// No need to sort hitsounds for the rest
GameMode::Mania => {
// First a _stable_ sort by time
$self
@@ -975,6 +974,7 @@ impl Beatmap {
) -> ParseResult<bool> {
parse_timingpoints_body!(self, reader, section)
}
/// Pass the path to a `.osu` file.
///
/// Useful when you don't want to create the [`File`](std::fs::File) manually.
@@ -983,6 +983,11 @@ impl Beatmap {
pub fn from_path<P: AsRef<Path>>(path: P) -> ParseResult<Self> {
Self::parse(File::open(path)?)
}
/// Parse the content of a `.osu` file in form of a slice of bytes into a beatmap.
pub fn from_bytes(bytes: &[u8]) -> ParseResult<Self> {
Self::parse(bytes)
}
}
#[cfg(any(feature = "async_tokio", feature = "async_std"))]
@@ -1043,6 +1048,11 @@ impl Beatmap {
pub async fn from_path<P: AsRef<Path>>(path: P) -> ParseResult<Self> {
Self::parse(File::open(path).await?).await
}
/// Parse the content of a `.osu` file in form of a slice of bytes into a beatmap.
pub async fn from_bytes(bytes: &[u8]) -> ParseResult<Self> {
Self::parse(bytes).await
}
}
#[derive(Copy, Clone, Debug)]
@@ -1067,91 +1077,3 @@ impl Section {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))]
#[test]
fn parsing_sync() {
for map_id in map_ids() {
println!("map_id: {}", map_id);
let map = match Beatmap::from_path(format!("./maps/{}.osu", map_id)) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map: {}", why),
};
print_info(map);
println!("---");
}
}
#[cfg(feature = "async_tokio")]
#[test]
fn parsing_async_tokio() {
use tokio::runtime::Builder;
Builder::new_current_thread()
.build()
.expect("could not start runtime")
.block_on(async {
for map_id in map_ids() {
println!("map_id: {}", map_id);
let map = match Beatmap::from_path(format!("./maps/{}.osu", map_id)).await {
Ok(map) => map,
Err(why) => panic!("Error while parsing map: {}", why),
};
print_info(map);
println!("---");
}
});
}
#[cfg(feature = "async_std")]
#[test]
fn parsing_async_std() {
async_std::task::block_on(async {
for map_id in map_ids() {
println!("map_id: {}", map_id);
let map = match Beatmap::from_path(format!("./maps/{}.osu", map_id)).await {
Ok(map) => map,
Err(why) => panic!("Error while parsing map: {}", why),
};
print_info(map);
println!("---");
}
});
}
fn map_ids() -> Vec<i32> {
vec![
2785319, // osu
1974394, // mania
2118524, // catch
1028484, // taiko
]
}
fn print_info(map: Beatmap) {
println!("Mode: {}", map.mode as u8);
println!("n_circles: {}", map.n_circles);
println!("n_sliders: {}", map.n_sliders);
println!("n_spinners: {}", map.n_spinners);
println!("ar: {}", map.ar);
println!("od: {}", map.od);
println!("cs: {}", map.cs);
println!("hp: {}", map.hp);
println!("slider_mult: {}", map.slider_mult);
println!("tick_rate: {}", map.tick_rate);
println!("hit_objects: {}", map.hit_objects.len());
println!("stack_leniency: {}", map.stack_leniency);
println!("timing_points: {}", map.timing_points.len());
println!("difficulty_points: {}", map.difficulty_points.len());
}
}