Beatsaber Rust Utilities: A Beatsaber V3 parsing library.
beatsaber
beatmap
1//! Describes the colors of objects and lights for an environment/map.
2
3pub mod presets;
4
5#[allow(unused_imports)]
6#[doc(hidden)]
7pub use presets::*;
8
9use serde::{Deserialize, Serialize};
10use std::string::ToString;
11
12#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[cfg_attr(
14 feature = "bevy_reflect",
15 derive(bevy_reflect::Reflect),
16 reflect(Debug, Clone, PartialEq)
17)]
18#[serde(rename_all = "camelCase")]
19pub struct ColorSchemeOverride {
20 pub use_override: bool,
21 pub color_scheme: ColorScheme,
22}
23
24/// The colors of objects and lights for an environment/map.
25///
26/// This does *not* currently support while light color overrides.
27#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
28#[cfg_attr(
29 feature = "bevy_reflect",
30 derive(bevy_reflect::Reflect),
31 reflect(Debug, Clone, PartialEq)
32)]
33#[serde(rename_all = "camelCase")]
34pub struct ColorScheme {
35 /// The name of the color scheme.
36 #[serde(rename = "colorSchemeId")]
37 pub id: String,
38 /// The color for the left saber/notes. Default is red.
39 #[doc(alias = "saber_left")]
40 #[serde(rename = "saberAColor")]
41 pub note_left: Color,
42 /// The color for the right saber/notes. Default is blue.
43 #[doc(alias = "saber_right")]
44 #[serde(rename = "saberBColor")]
45 pub note_right: Color,
46
47 /// The color of walls/obstacles.
48 #[doc(alias = "obstacle")]
49 #[serde(rename = "obstaclesColor")]
50 pub wall: Color,
51
52 /// The primary light color, often matching the [left note color](Self::note_left).
53 #[doc(alias = "environment0")]
54 #[serde(rename = "environmentColor0")]
55 pub light_primary: Color,
56 /// The secondary light color, often matching the [right note color](Self::note_right).
57 #[doc(alias = "environment1")]
58 #[serde(rename = "environmentColor1")]
59 pub light_secondary: Color,
60
61 /// The primary light color when [boost colors](crate::ColorBoostEvent) are enabled.
62 #[doc(alias = "environment_boost_0")]
63 #[serde(rename = "environmentColor0Boost")]
64 pub boost_light_primary: Color,
65 /// The secondary light color when [boost colors](crate::ColorBoostEvent) are enabled.
66 #[doc(alias = "environment_boost_1")]
67 #[serde(rename = "environmentColor1Boost")]
68 pub boost_light_secondary: Color,
69}
70
71impl Default for ColorScheme {
72 fn default() -> Self {
73 ColorScheme {
74 id: "Default".to_string(),
75 note_left: Color {
76 red: 0.7843137,
77 green: 0.07843138,
78 blue: 0.07843138,
79 alpha: 1.0,
80 },
81 note_right: Color {
82 red: 0.1568627,
83 green: 0.5568627,
84 blue: 0.8235294,
85 alpha: 1.0,
86 },
87 wall: Color {
88 red: 1.0,
89 green: 0.1882353,
90 blue: 0.1882353,
91 alpha: 1.0,
92 },
93 light_primary: Color {
94 red: 0.85,
95 green: 0.08499997,
96 blue: 0.08499997,
97 alpha: 1.0,
98 },
99 light_secondary: Color {
100 red: 0.1882353,
101 green: 0.675294,
102 blue: 1.0,
103 alpha: 1.0,
104 },
105 boost_light_primary: Default::default(),
106 boost_light_secondary: Default::default(),
107 }
108 }
109}
110
111/// The color of an object/light.
112#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
113#[cfg_attr(
114 feature = "bevy_reflect",
115 derive(bevy_reflect::Reflect),
116 reflect(Debug, Clone, PartialEq)
117)]
118pub struct Color {
119 #[serde(rename = "r")]
120 red: f32,
121 #[serde(rename = "g")]
122 green: f32,
123 #[serde(rename = "b")]
124 blue: f32,
125 #[serde(rename = "a")]
126 alpha: f32,
127}
128
129impl Default for Color {
130 fn default() -> Self {
131 Self {
132 red: 1.0,
133 green: 1.0,
134 blue: 1.0,
135 alpha: 1.0,
136 }
137 }
138}
139
140#[cfg(feature = "bevy_color")]
141mod color_conversions {
142 use crate::info::color_scheme::Color;
143 use bevy_color::Srgba;
144
145 impl From<Srgba> for Color {
146 fn from(value: Srgba) -> Self {
147 Self {
148 red: value.red,
149 green: value.green,
150 blue: value.blue,
151 alpha: value.alpha,
152 }
153 }
154 }
155
156 impl From<Color> for Srgba {
157 fn from(value: Color) -> Self {
158 Self {
159 red: value.red,
160 green: value.green,
161 blue: value.blue,
162 alpha: value.alpha,
163 }
164 }
165 }
166
167 impl From<bevy_color::Color> for Color {
168 fn from(value: bevy_color::Color) -> Self {
169 Srgba::from(value).into()
170 }
171 }
172
173 impl From<Color> for bevy_color::Color {
174 fn from(value: Color) -> Self {
175 Self::Srgba(value.into())
176 }
177 }
178}