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.

Added `get_duration` method to `EventGroup`.

+135
+135
src/difficulty/lightshow/group.rs
··· 58 58 /// Will panic if the light ID is greater than or equal to the group size. 59 59 #[deprecated(note = "Experimental. Does not consider random in filter calculations.")] 60 60 fn get_value_offset(&self, light_id: i32, group_size: i32) -> f32; 61 + 62 + /// Returns the duration of the group in beats. 63 + /// # Unknown 64 + /// If the [`FilterType`] is `Unknown` then the result will be zero. 65 + #[deprecated(note = "Experimental. Does not consider random in filter calculations.")] 66 + fn get_duration(&self, group_size: i32) -> f32; 61 67 } 62 68 63 69 #[macro_export] ··· 91 97 fn get_value_offset(&self, light_id: i32, group_size: i32) -> f32 { 92 98 self.$value_offset(light_id, group_size) 93 99 } 100 + 101 + #[allow(deprecated)] 102 + fn get_duration(&self, group_size: i32) -> f32 { 103 + let filtered_size = self.filter.count_filtered_without_limit(group_size); 104 + 105 + if filtered_size == 0 { 106 + return 0.0; 107 + } 108 + 109 + let Some(data) = self.get_data().last() else { 110 + return 0.0; 111 + }; 112 + 113 + data.beat_offset 114 + + match self.beat_dist_type { 115 + DistributionType::Wave => { 116 + let base = self.beat_dist_value / filtered_size as f32; 117 + 118 + if let Some(limit_behaviour) = self.filter.limit_behaviour 119 + && let Some(limit_percent) = self.filter.limit_percent 120 + && !limit_behaviour.beat_enabled() 121 + { 122 + base * limit_percent 123 + } else { 124 + base 125 + } 126 + } 127 + DistributionType::Step => self.beat_dist_value * filtered_size as f32, 128 + DistributionType::Unknown(_) => 0.0, 129 + } 130 + } 94 131 } 95 132 }; 96 133 } ··· 112 149 } 113 150 }; 114 151 } 152 + 153 + #[allow(deprecated)] 154 + #[cfg(test)] 155 + mod tests { 156 + use super::*; 157 + use crate::{DistributionType, LimitBehaviour}; 158 + 159 + #[test] 160 + fn get_duration_no_distribution() { 161 + assert_eq!(ColorEventGroup::default().get_duration(12), 0.0); 162 + } 163 + 164 + #[test] 165 + fn get_duration_wave() { 166 + let group = ColorEventGroup { 167 + beat_dist_type: DistributionType::Wave, 168 + beat_dist_value: 12.0, 169 + ..Default::default() 170 + }; 171 + 172 + assert_eq!(group.get_duration(12), 1.0); 173 + } 174 + 175 + #[test] 176 + fn get_duration_step() { 177 + let group = ColorEventGroup { 178 + beat_dist_type: DistributionType::Step, 179 + beat_dist_value: 1.0, 180 + ..Default::default() 181 + }; 182 + 183 + assert_eq!(group.get_duration(12), 12.0); 184 + } 185 + 186 + #[test] 187 + fn get_duration_wave_with_limit() { 188 + let group = ColorEventGroup { 189 + filter: Filter { 190 + limit_behaviour: Some(LimitBehaviour::None), 191 + limit_percent: Some(0.5), 192 + ..Default::default() 193 + }, 194 + beat_dist_type: DistributionType::Wave, 195 + beat_dist_value: 12.0, 196 + ..Default::default() 197 + }; 198 + 199 + assert_eq!(group.get_duration(12), 0.5); 200 + } 201 + 202 + #[test] 203 + fn get_duration_step_with_limit() { 204 + let group = ColorEventGroup { 205 + filter: Filter { 206 + limit_behaviour: Some(LimitBehaviour::None), 207 + limit_percent: Some(0.5), 208 + ..Default::default() 209 + }, 210 + beat_dist_type: DistributionType::Step, 211 + beat_dist_value: 1.0, 212 + ..Default::default() 213 + }; 214 + 215 + assert_eq!(group.get_duration(12), 12.0); 216 + } 217 + 218 + #[test] 219 + fn get_duration_wave_with_limit_adjusted() { 220 + let group = ColorEventGroup { 221 + filter: Filter { 222 + limit_behaviour: Some(LimitBehaviour::Beat), 223 + limit_percent: Some(0.5), 224 + ..Default::default() 225 + }, 226 + beat_dist_type: DistributionType::Wave, 227 + beat_dist_value: 12.0, 228 + ..Default::default() 229 + }; 230 + 231 + assert_eq!(group.get_duration(12), 1.0); 232 + } 233 + 234 + #[test] 235 + fn get_duration_step_with_limit_adjusted() { 236 + let group = ColorEventGroup { 237 + filter: Filter { 238 + limit_behaviour: Some(LimitBehaviour::Beat), 239 + limit_percent: Some(0.5), 240 + ..Default::default() 241 + }, 242 + beat_dist_type: DistributionType::Step, 243 + beat_dist_value: 1.0, 244 + ..Default::default() 245 + }; 246 + 247 + assert_eq!(group.get_duration(12), 12.0); 248 + } 249 + }