1use crate::{AnimationFrame, WanError};
2use std::io::{Read, Write};
3
4#[derive(Debug, PartialEq, Eq, Default)]
7pub struct Animation {
8 pub frames: Vec<AnimationFrame>,
9}
10
11impl Animation {
12 pub fn new<F: Read>(file: &mut F) -> Result<Animation, WanError> {
13 let mut frames = Vec::new();
14 loop {
15 let current_frame = AnimationFrame::new(file)?;
16 if current_frame.is_null() {
17 break;
18 }
19 frames.push(current_frame);
20 }
21 Ok(Animation { frames })
22 }
23
24 pub fn len(&self) -> usize {
25 self.frames.len()
26 }
27
28 pub fn is_empty(&self) -> bool {
29 self.len() == 0
30 }
31
32 pub fn write<F: Write>(file: &mut F, animation: &Animation) -> Result<(), WanError> {
33 for frame in &animation.frames {
34 AnimationFrame::write(file, frame)?;
35 }
36 AnimationFrame::write_null(file)?;
37 Ok(())
38 }
39}