diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 10:40:01 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 10:40:01 +0300 |
| commit | 20161fbf4fab9080a2d0d6ceedbf1344435cfda0 (patch) | |
| tree | 174be0827089abc4407af7289142d66d9f995ae7 /crates/fparkan-assets/src/explosion_profile.rs | |
| parent | 5f0b8c076b40f8eca67e2745367c731f803914f4 (diff) | |
| download | fparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.tar.xz fparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.zip | |
feat(ui): show live Control stats in the warbot card
Diffstat (limited to 'crates/fparkan-assets/src/explosion_profile.rs')
| -rw-r--r-- | crates/fparkan-assets/src/explosion_profile.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/fparkan-assets/src/explosion_profile.rs b/crates/fparkan-assets/src/explosion_profile.rs index af9c5a3e..d9f15229 100644 --- a/crates/fparkan-assets/src/explosion_profile.rs +++ b/crates/fparkan-assets/src/explosion_profile.rs @@ -1,5 +1,13 @@ //! Effect references carried by the version-1 explosion descriptor. +/// The contribution of an EXPL descriptor to Control's projectile capacity. +pub fn decode_explosion_capacity(bytes: &[u8]) -> Option<f32> { + if bytes.len() != 792 || !matches!(u32::from_le_bytes(bytes[..4].try_into().ok()?), 1..=3) { + return None; + } + Some(f32::from_le_bytes(bytes[4..8].try_into().ok()?)) +} + /// Reads the initial effect archive and name from a version-1 EXPL payload. /// Other versions and malformed references require separate interpretation. pub fn decode_explosion_effect(bytes: &[u8]) -> Option<(&str, &str)> { @@ -34,4 +42,16 @@ mod tests { bytes[0] = 2; assert_eq!(decode_explosion_effect(&bytes), None); } + + #[test] + fn reads_capacity_in_each_observed_explosion_layout() { + let mut bytes = [0; 792]; + bytes[4..8].copy_from_slice(&300.0_f32.to_le_bytes()); + for version in 1..=3_u32 { + bytes[..4].copy_from_slice(&version.to_le_bytes()); + assert_eq!(decode_explosion_capacity(&bytes), Some(300.0)); + } + bytes[0] = 4; + assert_eq!(decode_explosion_capacity(&bytes), None); + } } |
