Beatsaber Rust Utilities: A Beatsaber V3 parsing library.
beatsaber beatmap
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Started on enums using `loose_enum` macro.

+98 -2
+47 -2
src/difficulty/playfield.rs
··· 1 - use serde::{Deserialize, Serialize}; 1 + use crate::loose_enum; 2 + use serde::{Deserialize, Deserializer, Serialize}; 2 3 3 4 #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] 4 5 #[serde(rename_all = "camelCase")] ··· 10 11 #[serde(rename = "y")] 11 12 pub col: i32, 12 13 #[serde(rename = "c")] 13 - pub color: i32, 14 + pub color: NoteColor, 14 15 #[serde(rename = "d")] 15 16 pub direction: i32, 16 17 #[serde(rename = "a")] 17 18 pub angle_offset: i32, 19 + } 20 + 21 + loose_enum! { 22 + #[derive(Default)] 23 + NoteColor, { 24 + #[default] 25 + Left = 0, 26 + Right = 1, 27 + } 28 + } 29 + 30 + loose_enum! { 31 + #[derive(Default)] 32 + CutDirection, { 33 + #[default] 34 + Up = 0, 35 + Down = 1, 36 + Left = 2, 37 + Right = 3, 38 + UpLeft = 4, 39 + UpRight = 5, 40 + DownLeft = 6, 41 + DownRight = 7, 42 + Any = 8, 43 + } 44 + } 45 + 46 + impl CutDirection { 47 + /// Returns the number of degrees a note is rotated, with zero degrees being downward note. 48 + /// Returns `None` if the cut direction is unknown. 49 + pub fn get_degrees(&self) -> Option<f32> { 50 + match self { 51 + CutDirection::Up => Some(180.0), 52 + CutDirection::Down => Some(0.0), 53 + CutDirection::Left => Some(-90.0), 54 + CutDirection::Right => Some(90.0), 55 + CutDirection::UpLeft => Some(-135.0), 56 + CutDirection::UpRight => Some(135.0), 57 + CutDirection::DownLeft => Some(-45.0), 58 + CutDirection::DownRight => Some(45.0), 59 + CutDirection::Any => Some(0.0), 60 + CutDirection::Unknown(_) => None, 61 + } 62 + } 18 63 } 19 64 20 65 #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
+1
src/lib.rs
··· 1 1 pub mod difficulty; 2 2 pub mod info; 3 + mod macros; 3 4 4 5 pub fn add(left: u64, right: u64) -> u64 { 5 6 left + right
+50
src/macros.rs
··· 1 + #[macro_export] 2 + macro_rules! loose_enum { 3 + ( 4 + $(#[$outer:meta])* 5 + $name:ident, 6 + { 7 + $( 8 + $(#[$meta:meta])* 9 + $variant:ident = $value:expr 10 + ),+ $(,)? 11 + } 12 + ) => { 13 + #[derive(Debug, Clone, Copy, Eq, PartialEq)] 14 + $(#[$outer])* 15 + pub enum $name { 16 + $( 17 + $(#[$meta])* 18 + $variant 19 + ),+, 20 + Unknown(i32), 21 + } 22 + 23 + impl<'de> Deserialize<'de> for $name { 24 + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 25 + where 26 + D: Deserializer<'de>, 27 + { 28 + let val = i32::deserialize(deserializer)?; 29 + Ok(match val { 30 + $( $value => $name::$variant, )+ 31 + other => $name::Unknown(other), 32 + }) 33 + } 34 + } 35 + 36 + impl Serialize for $name { 37 + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 38 + where 39 + S: serde::Serializer, 40 + { 41 + match self { 42 + $( 43 + $name::$variant => serializer.serialize_i32($value), 44 + )+ 45 + $name::Unknown(val) => serializer.serialize_i32(*val), 46 + } 47 + } 48 + } 49 + }; 50 + }