rosu_map/section/events/
mod.rs1use std::str::FromStr;
2
3pub use self::decode::{Events, EventsState, ParseEventsError};
4
5pub(crate) mod decode; #[derive(Copy, Clone, Debug, Default, PartialEq)]
11pub struct BreakPeriod {
12 pub start_time: f64,
13 pub end_time: f64,
14}
15
16impl BreakPeriod {
17 pub const MIN_BREAK_DURATION: f64 = 650.0;
19
20 pub fn duration(&self) -> f64 {
22 self.end_time - self.start_time
23 }
24
25 pub fn has_effect(&self) -> bool {
27 self.duration() >= Self::MIN_BREAK_DURATION
28 }
29}
30
31#[derive(Copy, Clone, Debug, PartialEq, Eq)]
33pub enum EventType {
34 Background,
35 Video,
36 Break,
37 Color,
38 Sprite,
39 Sample,
40 Animation,
41}
42
43impl FromStr for EventType {
44 type Err = ParseEventTypeError;
45
46 fn from_str(s: &str) -> Result<Self, Self::Err> {
47 match s {
48 "0" | "Background" => Ok(Self::Background),
49 "1" | "Video" => Ok(Self::Video),
50 "2" | "Break" => Ok(Self::Break),
51 "3" | "Colour" => Ok(Self::Color),
52 "4" | "Sprite" => Ok(Self::Sprite),
53 "5" | "Sample" => Ok(Self::Sample),
54 "6" | "Animation" => Ok(Self::Animation),
55 _ => Err(ParseEventTypeError),
56 }
57 }
58}
59
60thiserror! {
61 #[error("invalid event type")]
62 #[derive(Debug)]
64 pub struct ParseEventTypeError;
65}