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.

Merge pull request #25 from AlephCubed/get-duration

Added `get_duration` method to `EventGroup`.

authored by

AlephCubed and committed by
GitHub
289fcce7 642910e1

+167 -4
+1 -1
Cargo.lock
··· 160 160 161 161 [[package]] 162 162 name = "bsru" 163 - version = "0.5.0" 163 + version = "0.6.0-rc.1" 164 164 dependencies = [ 165 165 "bevy_color", 166 166 "bevy_reflect",
+1 -1
Cargo.toml
··· 1 1 [package] 2 2 name = "bsru" 3 - version = "0.5.0" 3 + version = "0.6.0-rc.1" 4 4 edition = "2024" 5 5 description = "Beatsaber Rust Utilities: A Beatsaber V3 parsing library." 6 6 categories = ["game-development", "data-structures", "parser-implementations"]
+1 -1
README.md
··· 25 25 26 26 | Bevy | BSRU | 27 27 |--------|---------------| 28 - | `0.17` | `0.4` | 28 + | `0.17` | `0.4`+ | 29 29 | `0.16` | `0.1` - `0.3` |
+16 -1
src/difficulty/lightshow/filter.rs
··· 159 159 pub fn count_filtered(&self, group_size: i32) -> i32 { 160 160 let filtered = self.count_filtered_without_limit(group_size); 161 161 162 - if let Some(limit) = self.limit_percent { 162 + if let Some(limit) = self.limit_percent 163 + && limit > 0.0 164 + { 163 165 (filtered as f32 * limit) as i32 164 166 } else { 165 167 filtered ··· 555 557 assert_eq!(filter.count_filtered(8), 7); 556 558 assert_eq!(filter.count_filtered_without_limit(8), 8); 557 559 assert!((0..7).all(|i| filter.get_relative_index(i, 8) == i)); 560 + } 561 + 562 + #[test] 563 + fn limit_zero() { 564 + let filter = Filter { 565 + limit_percent: Some(0.0), 566 + ..Default::default() 567 + }; 568 + 569 + assert!((0..12).all(|i| filter.is_in_filter(i, 12))); 570 + assert_eq!(filter.count_filtered(12), 12); 571 + assert_eq!(filter.count_filtered_without_limit(12), 12); 572 + assert!((0..12).all(|i| filter.get_relative_index(i, 12) == i)); 558 573 } 559 574 }
+148
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 + #[deprecated(note = "Experimental. Does not consider random in filter calculations.")] 64 + fn get_duration(&self, group_size: i32) -> f32; 61 65 } 62 66 63 67 #[macro_export] ··· 91 95 fn get_value_offset(&self, light_id: i32, group_size: i32) -> f32 { 92 96 self.$value_offset(light_id, group_size) 93 97 } 98 + 99 + #[allow(deprecated)] 100 + fn get_duration(&self, group_size: i32) -> f32 { 101 + let filtered_size = self.filter.count_filtered(group_size); 102 + 103 + if filtered_size == 0 { 104 + return 0.0; 105 + } 106 + 107 + let Some(data) = self.get_data().last() else { 108 + return 0.0; 109 + }; 110 + 111 + match self.beat_dist_type { 112 + DistributionType::Wave => { 113 + if let Some(limit_behaviour) = self.filter.limit_behaviour 114 + && !limit_behaviour.beat_enabled() 115 + && let Some(limit_percent) = self.filter.limit_percent 116 + && limit_percent > 0.0 117 + { 118 + (self.beat_dist_value * limit_percent).max(data.beat_offset) 119 + } else { 120 + self.beat_dist_value.max(data.beat_offset) 121 + } 122 + } 123 + DistributionType::Step => { 124 + data.beat_offset + self.beat_dist_value * filtered_size as f32 125 + } 126 + DistributionType::Undefined(_) => data.beat_offset, 127 + } 128 + } 94 129 } 95 130 }; 96 131 } ··· 112 147 } 113 148 }; 114 149 } 150 + 151 + #[allow(deprecated)] 152 + #[cfg(test)] 153 + mod tests { 154 + use super::*; 155 + use crate::{DistributionType, LimitBehaviour}; 156 + 157 + #[test] 158 + fn get_duration_no_distribution() { 159 + assert_eq!(ColorEventGroup::default().get_duration(12), 0.0); 160 + } 161 + 162 + #[test] 163 + fn get_duration_wave() { 164 + let group = ColorEventGroup { 165 + beat_dist_type: DistributionType::Wave, 166 + beat_dist_value: 12.0, 167 + ..Default::default() 168 + }; 169 + 170 + assert_eq!(group.get_duration(12), 12.0); 171 + } 172 + 173 + #[test] 174 + fn get_duration_step() { 175 + let group = ColorEventGroup { 176 + beat_dist_type: DistributionType::Step, 177 + beat_dist_value: 1.0, 178 + ..Default::default() 179 + }; 180 + 181 + assert_eq!(group.get_duration(12), 12.0); 182 + } 183 + 184 + #[test] 185 + fn get_duration_wave_with_limit() { 186 + let group = ColorEventGroup { 187 + filter: Filter { 188 + limit_behaviour: Some(LimitBehaviour::None), 189 + limit_percent: Some(0.5), 190 + ..Default::default() 191 + }, 192 + beat_dist_type: DistributionType::Wave, 193 + beat_dist_value: 12.0, 194 + ..Default::default() 195 + }; 196 + 197 + assert_eq!(group.get_duration(12), 6.0); 198 + } 199 + 200 + #[test] 201 + fn get_duration_step_with_limit() { 202 + let group = ColorEventGroup { 203 + filter: Filter { 204 + limit_behaviour: Some(LimitBehaviour::None), 205 + limit_percent: Some(0.5), 206 + ..Default::default() 207 + }, 208 + beat_dist_type: DistributionType::Step, 209 + beat_dist_value: 1.0, 210 + ..Default::default() 211 + }; 212 + 213 + assert_eq!(group.get_duration(12), 6.0); 214 + } 215 + 216 + #[test] 217 + fn get_duration_wave_with_limit_adjusted() { 218 + let group = ColorEventGroup { 219 + filter: Filter { 220 + limit_behaviour: Some(LimitBehaviour::Beat), 221 + limit_percent: Some(0.5), 222 + ..Default::default() 223 + }, 224 + beat_dist_type: DistributionType::Wave, 225 + beat_dist_value: 12.0, 226 + ..Default::default() 227 + }; 228 + 229 + assert_eq!(group.get_duration(12), 12.0); 230 + } 231 + 232 + #[test] 233 + fn get_duration_step_with_limit_adjusted() { 234 + let group = ColorEventGroup { 235 + filter: Filter { 236 + limit_behaviour: Some(LimitBehaviour::Beat), 237 + limit_percent: Some(0.5), 238 + ..Default::default() 239 + }, 240 + beat_dist_type: DistributionType::Step, 241 + beat_dist_value: 1.0, 242 + ..Default::default() 243 + }; 244 + 245 + assert_eq!(group.get_duration(12), 6.0); 246 + } 247 + 248 + #[test] 249 + fn get_duration_step_with_limit_zero() { 250 + let group = ColorEventGroup { 251 + filter: Filter { 252 + limit_percent: Some(0.0), 253 + ..Default::default() 254 + }, 255 + beat_dist_type: DistributionType::Step, 256 + beat_dist_value: 1.0, 257 + ..Default::default() 258 + }; 259 + 260 + assert_eq!(group.get_duration(12), 12.0); 261 + } 262 + }