Deduplicate bitflags/bitarray_to_byte

This commit is contained in:
Simon Bruder 2020-07-08 23:55:04 +02:00
parent f66508eef7
commit 95f4a4c60c
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 2 additions and 13 deletions

View file

@ -14,15 +14,6 @@ pub type SampleIndex = u16;
pub type Time = u32; pub type Time = u32;
// Helper functions
fn bitflags(flags: [bool; 8]) -> u8 {
let mut value = 0u8;
for (i, flag) in flags.iter().enumerate() {
value += ((0b1 as u8) << i) * (*flag as u8) as u8;
}
value
}
fn assemble_hit_object_type(hit_object_type: u8, new_combo: bool, skip_combo_colours: U3) -> u8 { fn assemble_hit_object_type(hit_object_type: u8, new_combo: bool, skip_combo_colours: U3) -> u8 {
let hit_object_type = 1u8 << hit_object_type; let hit_object_type = 1u8 << hit_object_type;
let new_combo = if new_combo { 0b0000_0010_u8 } else { 0u8 }; let new_combo = if new_combo { 0b0000_0010_u8 } else { 0u8 };
@ -255,7 +246,7 @@ impl fmt::Display for TimingPointEffects {
write!( write!(
f, f,
"{}", "{}",
bitflags([ utils::bitarray_to_byte([
self.kiai_time, self.kiai_time,
false, false,
false, false,
@ -360,7 +351,7 @@ impl fmt::Display for HitSound {
write!( write!(
f, f,
"{}", "{}",
bitflags([ utils::bitarray_to_byte([
self.normal, self.normal,
self.whistle, self.whistle,
self.finish, self.finish,

View file

@ -12,8 +12,6 @@ pub fn byte_to_bitarray(byte: u8) -> [bool; 8] {
bitarray bitarray
} }
#[allow(dead_code)]
/// Used to test `byte_to_bitarray`
pub fn bitarray_to_byte(bitarray: [bool; 8]) -> u8 { pub fn bitarray_to_byte(bitarray: [bool; 8]) -> u8 {
bitarray bitarray
.iter() .iter()