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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::Keyframe;
pub use self::sample::*;
use std::ops::Deref;
mod action_keyframes_serde;
mod sample;
#[derive(Debug, PartialEq, Default)]
#[cfg_attr(test, derive(Clone))]
pub struct ActionKeyframes {
keyframes: Vec<Keyframe>,
smallest_frame: u16,
largest_frame: u16,
}
impl ActionKeyframes {
pub fn new(keyframes: Vec<Keyframe>) -> Self {
let mut smallest_frame = u16::max_value();
let mut largest_frame = u16::min_value();
for frame in keyframes.iter() {
smallest_frame = smallest_frame.min(frame.frame);
largest_frame = largest_frame.max(frame.frame);
}
let mut keyframes = ActionKeyframes {
keyframes,
smallest_frame,
largest_frame,
};
keyframes.sort_keyframes_ascending();
keyframes
}
pub fn keyframes(&self) -> &Vec<Keyframe> {
&self.keyframes
}
pub fn smallest_frame(&self) -> u16 {
self.smallest_frame
}
pub fn largest_frame(&self) -> u16 {
self.largest_frame
}
pub fn insert_keyframe(&mut self, keyframe: Keyframe) {
self.keyframes.push(keyframe);
self.sort_keyframes_ascending();
}
fn sort_keyframes_ascending(&mut self) {
self.keyframes.sort_by(|a, b| a.frame.cmp(&b.frame));
}
}
impl ActionKeyframes {
pub(crate) fn keyframes_mut(&mut self) -> &mut Vec<Keyframe> {
&mut self.keyframes
}
}
impl Deref for ActionKeyframes {
type Target = Vec<Keyframe>;
fn deref(&self) -> &Self::Target {
&self.keyframes
}
}