use uuid::Uuid;
use crate::PropertySnapshot;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AnimationTargetId(Uuid);
#[derive(Debug, Clone, PartialEq)]
pub struct TargetedPropertySnapshot {
targets: Vec<(AnimationTargetId, PropertySnapshot)>,
}
impl AnimationTargetId {
#[must_use]
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for AnimationTargetId {
fn default() -> Self {
Self::new()
}
}
impl TargetedPropertySnapshot {
#[must_use]
pub fn new() -> Self {
Self {
targets: Vec::new(),
}
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.targets.is_empty()
}
#[must_use]
pub fn get(&self, target_id: AnimationTargetId) -> Option<&PropertySnapshot> {
self.targets
.iter()
.find(|(id, _)| *id == target_id)
.map(|(_, snapshot)| snapshot)
}
pub(crate) fn merge(&mut self, target: AnimationTargetId, snapshot: PropertySnapshot) {
if let Some(index) = self.targets.iter().position(|(id, _)| *id == target) {
self.targets[index].1.merge(snapshot);
} else {
self.targets.push((target, snapshot));
}
}
#[must_use]
pub fn targets(&self) -> &[(AnimationTargetId, PropertySnapshot)] {
&self.targets
}
}
impl Default for TargetedPropertySnapshot {
fn default() -> Self {
Self::new()
}
}