wow_m2/chunks/
transparency_animation.rs

1use std::io::{Read, Seek, Write};
2
3use crate::chunks::animation::M2AnimationBlock;
4use crate::error::Result;
5use crate::version::M2Version;
6
7/// Transparency animation structure
8#[derive(Debug, Default, Clone)]
9pub struct M2TransparencyAnimation {
10    /// Alpha animation
11    pub alpha: M2AnimationBlock<f32>,
12}
13
14impl M2TransparencyAnimation {
15    /// Parse a transparency animation from a reader
16    pub fn parse<R: Read + Seek>(reader: &mut R) -> Result<Self> {
17        let alpha = M2AnimationBlock::parse(reader)?;
18
19        Ok(Self { alpha })
20    }
21
22    /// Write a transparency animation to a writer
23    pub fn write<W: Write>(&self, writer: &mut W) -> Result<()> {
24        self.alpha.write(writer)?;
25
26        Ok(())
27    }
28
29    /// Convert this transparency animation to a different version (no version differences yet)
30    pub fn convert(&self, _target_version: M2Version) -> Self {
31        self.clone()
32    }
33
34    /// Create a new transparency animation with default values
35    pub fn new() -> Self {
36        Self::default()
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43    use std::io::Cursor;
44
45    #[test]
46    fn test_transparency_animation_parse_write() {
47        let mut data = Vec::new();
48
49        // Alpha animation track
50        data.extend_from_slice(&1u16.to_le_bytes()); // Interpolation type (Linear)
51        data.extend_from_slice(&(-1i16).to_le_bytes()); // Global sequence
52        data.extend_from_slice(&0u32.to_le_bytes()); // Interpolation ranges count
53        data.extend_from_slice(&0u32.to_le_bytes()); // Interpolation ranges offset
54        data.extend_from_slice(&0u32.to_le_bytes()); // Timestamps count
55        data.extend_from_slice(&0u32.to_le_bytes()); // Timestamps offset
56        data.extend_from_slice(&0u32.to_le_bytes()); // Values count
57        data.extend_from_slice(&0u32.to_le_bytes()); // Values offset
58
59        let mut cursor = Cursor::new(data);
60        let trans_anim = M2TransparencyAnimation::parse(&mut cursor).unwrap();
61
62        // Test write
63        let mut output = Vec::new();
64        trans_anim.write(&mut output).unwrap();
65
66        // Check output size (should be the same as input)
67        assert_eq!(output.len(), cursor.get_ref().len());
68    }
69}