diff options
| author | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
| commit | f5a82152394fde4d8f740f664ab7737b82861618 (patch) | |
| tree | 5a51b181abead1ce03d2dbfc12b77918d3be0e1b /rust/crates/animation/src/channel_data.rs | |
| parent | e837e7504379e100ff3b56282577ec67bb88bec9 (diff) | |
| download | opencut-f5a82152394fde4d8f740f664ab7737b82861618.tar.gz | |
feat: GPUI desktop port foundation
- scene crate: full project/scene/element model, serde round-trip
proven against the web SerializedProject shape
- transfer crate: .ocp zip container, cross-compat with web fflate
archives proven in both directions
- storage crate: filesystem project store replacing IndexedDB,
.ocp import/export
- media crate: ffmpeg-next 8 decoder (frames, audio, thumbnails,
waveform summaries)
- playback crate: wall-clock anchored, frame-rounded playback clock
- gpu crate: native texture readback; compositor renders headless
offscreen on Vulkan (spike test)
- flake devshell: rust toolchain, GPUI native deps, ffmpeg dev,
bindgen clang args; GPUI hello-world builds
- port plan in notes/gpui-port.md
Diffstat (limited to 'rust/crates/animation/src/channel_data.rs')
| -rw-r--r-- | rust/crates/animation/src/channel_data.rs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/rust/crates/animation/src/channel_data.rs b/rust/crates/animation/src/channel_data.rs new file mode 100644 index 00000000..a05396e5 --- /dev/null +++ b/rust/crates/animation/src/channel_data.rs @@ -0,0 +1,92 @@ +use scene::{AnimationChannel, ChannelData, CompositeChannelData}; + +const LEGACY_ANIMATION_STORAGE_KEYS: [&str; 2] = ["bindings", "channels"]; + +pub fn is_animation_storage_key(key: &str) -> bool { + !LEGACY_ANIMATION_STORAGE_KEYS.contains(&key) +} + +fn component_order(key: &str) -> usize { + match key { + "value" => 0, + "r" => 1, + "g" => 2, + "b" => 3, + "a" => 4, + _ => 5, + } +} + +pub fn ordered_composite_entries(data: &CompositeChannelData) -> Vec<(&String, &AnimationChannel)> { + let mut entries: Vec<(&String, &AnimationChannel)> = data.iter().collect(); + entries.sort_by_key(|(key, _)| component_order(key)); + entries +} + +pub fn get_channels_from_data(data: Option<&ChannelData>) -> Vec<&AnimationChannel> { + match data { + Some(ChannelData::Single(channel)) => vec![channel], + Some(ChannelData::Composite(components)) => ordered_composite_entries(components) + .into_iter() + .map(|(_, channel)| channel) + .collect(), + None => Vec::new(), + } +} + +pub fn get_channel_entries_from_data(data: Option<&ChannelData>) -> Vec<(String, &AnimationChannel)> { + match data { + Some(ChannelData::Single(channel)) => vec![("value".to_string(), channel)], + Some(ChannelData::Composite(components)) => ordered_composite_entries(components) + .into_iter() + .map(|(key, channel)| (key.clone(), channel)) + .collect(), + None => Vec::new(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use scene::{AnimationChannel, DiscreteChannel, ScalarChannel}; + use std::collections::BTreeMap; + + fn scalar_channel() -> AnimationChannel { + AnimationChannel::Scalar(ScalarChannel { + keys: Vec::new(), + extrapolation: None, + }) + } + + #[test] + fn leaf_data_yields_value_entry() { + let data = ChannelData::Single(scalar_channel()); + let entries = get_channel_entries_from_data(Some(&data)); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].0, "value"); + } + + #[test] + fn composite_entries_follow_canonical_component_order() { + let mut components = BTreeMap::new(); + components.insert("a".to_string(), scalar_channel()); + components.insert("b".to_string(), scalar_channel()); + components.insert("g".to_string(), scalar_channel()); + components.insert("r".to_string(), scalar_channel()); + components.insert( + "mode".to_string(), + AnimationChannel::Discrete(DiscreteChannel { keys: Vec::new() }), + ); + let data = ChannelData::Composite(components); + let entries = get_channel_entries_from_data(Some(&data)); + let keys: Vec<&str> = entries.iter().map(|(key, _)| key.as_str()).collect(); + assert_eq!(keys, ["r", "g", "b", "a", "mode"]); + } + + #[test] + fn legacy_storage_keys_are_rejected() { + assert!(!is_animation_storage_key("bindings")); + assert!(!is_animation_storage_key("channels")); + assert!(is_animation_storage_key("opacity")); + } +} |
