Animation presets: effect keyframes in presets saved by earlier versions start at the playhead too (#1971)

This commit is contained in:
tylerjenningsw
2026-10-27 13:44:36 -04:00
parent 337a6c2053
commit b74b89feb5
+11 -1
View File
@@ -18,6 +18,8 @@ use crate::{EngineError, KeyRef, Result, Session, cmd};
pub const PRESET_TAG: &str = "effectcraftAnimationPreset";
/// The preset format version that `anim.savePreset` writes.
pub const PRESET_VERSION: u64 = 2;
/// The first preset version that stores effect keys relative to the earliest key (#1971).
const RELATIVE_EFFECT_KEYS: u64 = 2;
fn has_selected_props(s: &Session) -> std::result::Result<(), String> {
has_comp(s)?;
@@ -130,8 +132,16 @@ fn apply_preset(s: &mut Session, p: &Value) -> Result<Value> {
s.save_prefs();
s.prefs_revision += 1;
}
let effects: Vec<PropGroup> =
let mut effects: Vec<PropGroup> =
doc["effects"].as_array().map(|a| a.iter().filter_map(|v| serde_json::from_value(v.clone()).ok()).collect()).unwrap_or_default();
// Older presets stored effect keys at the source layer's times.
if doc[PRESET_TAG].as_u64().unwrap_or(1) < RELATIVE_EFFECT_KEYS
&& let Some(first) = earliest_key(&effects)
{
for g in &mut effects {
retime_effect(g, 1.0, "anim.applyPreset", |t| Ok(Tick(t.0.checked_sub(first.0).ok_or_else(|| effect_time_error("anim.applyPreset"))?)))?;
}
}
let props: Vec<(String, Property)> = doc["properties"]
.as_array()
.map(|a| {