use super::animation::{AnimationConfig, AnimationDriver, AnimationId};
pub struct AnimationGroup {
name: String,
parallel: Vec<AnimationId>,
sequential: Vec<AnimationConfig>,
current_seq_index: usize,
}
impl AnimationGroup {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
parallel: Vec::new(),
sequential: Vec::new(),
current_seq_index: 0,
}
}
pub fn add_parallel(&mut self, id: AnimationId) {
self.parallel.push(id);
}
pub fn add_sequential(&mut self, config: AnimationConfig) {
self.sequential.push(config);
}
pub fn name(&self) -> &str {
&self.name
}
pub fn is_completed(&self, driver: &AnimationDriver) -> bool {
let parallel_done = self
.parallel
.iter()
.all(|id| driver.get_progress(*id).map(|p| p >= 1.0).unwrap_or(true));
parallel_done && self.current_seq_index >= self.sequential.len()
}
pub fn len_parallel(&self) -> usize {
self.parallel.len()
}
pub fn len_sequential(&self) -> usize {
self.sequential.len()
}
pub fn current_seq_index(&self) -> usize {
self.current_seq_index
}
pub fn reset(&mut self) {
self.current_seq_index = 0;
}
}