From 9aafbdc975ff82f0f85e1c80b912f41edc30a676 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 26 Oct 2026 11:27:47 -0400 Subject: [PATCH] Split effect upgrade step out of upgrade_effects to cut cognitive complexity Moves the per-group body into upgrade_effect_group. Behavior is unchanged; the engine test suite passes (664 tests). --- crates/engine/src/lib.rs | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index c6c6c5733..44759126f 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1218,19 +1218,7 @@ pub fn upgrade_effects(p: &mut Project) { let Some(fx) = l.props.sub_mut("effects") else { continue }; for n in &mut fx.children { let effectcraft_project::Node::Group(g) = n else { continue }; - let effectcraft_project::GroupKind::Effect { effect } = &g.kind else { continue }; - if let Some(spec) = effectcraft_effects::find(effect) { - let composite = legacy_particles - && matches!(spec.id, "ec.sim.ccparticlesystems2" | "ec.sim.ccparticleworld") - && g.get("compositeWithOriginal").is_none(); - effectcraft_effects::migrate::upgrade_instance(spec, g, &mut effectcraft_project::build::Ids(&mut next), size); - if composite && let Some(pr) = g.get_mut("compositeWithOriginal") { - pr.value = effectcraft_keyframe::Value::Bool(true); - } - if to_effect_space { - effectcraft_effects::migrate::to_effect_space(spec, g, size, d, &clone_d); - } - } + upgrade_effect_group(g, legacy_particles, to_effect_space, size, d, &clone_d, &mut next); } } } @@ -1239,6 +1227,31 @@ pub fn upgrade_effects(p: &mut Project) { p.saved_by = effectcraft_project::APP_VERSION.to_string(); } +/// Upgrade one effect group of a layer: its instance, the legacy composite flag, and (when the +/// project predates effect space) its positions. +fn upgrade_effect_group( + g: &mut effectcraft_project::PropGroup, + legacy_particles: bool, + to_effect_space: bool, + size: [f64; 2], + d: [f64; 2], + clone_d: &dyn Fn(Option) -> [f64; 2], + next: &mut u64, +) { + let effectcraft_project::GroupKind::Effect { effect } = &g.kind else { return }; + let Some(spec) = effectcraft_effects::find(effect.as_str()) else { return }; + let composite = legacy_particles + && matches!(spec.id, "ec.sim.ccparticlesystems2" | "ec.sim.ccparticleworld") + && g.get("compositeWithOriginal").is_none(); + effectcraft_effects::migrate::upgrade_instance(spec, g, &mut effectcraft_project::build::Ids(next), size); + if composite && let Some(pr) = g.get_mut("compositeWithOriginal") { + pr.value = effectcraft_keyframe::Value::Bool(true); + } + if to_effect_space { + effectcraft_effects::migrate::to_effect_space(spec, g, size, d, clone_d); + } +} + #[cfg(test)] mod rq_tests; #[cfg(test)]