1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{BasicAnimation, ContainedAnimation, EditableState, Resetable};
use quicksilver::geom::{Rectangle, Vector};

/// The struct used to turn a BasicAnimation into a ContainedAnimation
pub struct BasicAnimationContainer<Animation>
where
    Animation: BasicAnimation,
{
    pub(crate) animation: Animation,
    pub(crate) location: Rectangle,
}

impl<Animation> ContainedAnimation for BasicAnimationContainer<Animation>
where
    Animation: BasicAnimation,
{
    fn draw(&mut self, gfx: &mut quicksilver::graphics::Graphics) -> quicksilver::Result<()> {
        self.animation.draw(gfx, self.location)
    }
    fn set_location(&mut self, location: quicksilver::geom::Vector) {
        self.location.pos = location;
    }
    fn set_size(&mut self, size: quicksilver::geom::Vector) {
        self.location.size = size;
    }
    fn get_draw_pos(&self) -> Rectangle {
        self.location
    }
    fn get_position(&self) -> Vector {
        self.location.pos
    }
    fn get_size(&self) -> Vector {
        self.location.size
    }
}

impl<Animation> Resetable for BasicAnimationContainer<Animation>
where
    Animation: BasicAnimation + Resetable,
{
    fn reset(&mut self) {
        self.animation.reset()
    }
}

impl<Animation> BasicAnimationContainer<Animation>
where
    Animation: BasicAnimation,
{
    ///Turns the ContainedAnimation back into the SimpleAnimation
    pub fn unpack(self) -> (Animation, Rectangle) {
        (self.animation, self.location)
    }
}

impl<Animation, T> EditableState<T> for BasicAnimationContainer<Animation>
where
    Animation: BasicAnimation + EditableState<T>,
{
    fn set_state(&mut self, new_state: T) {
        self.animation.set_state(new_state)
    }
    fn get_state(&self) -> &T {
        self.animation.get_state()
    }
}