From ef5796d667978cafc84273656e1c657c69afccf5 Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 6 Oct 2026 02:03:20 -0400 Subject: [PATCH] Merging animations places triggers after the animation merged before them Appending moves the appended animation's triggers by the length merged so far; prepending moves the target's triggers by the prepended length. Replace and ignore keep trigger times. Goldens for prepend merges updated. Co-Authored-By: Claude Opus 5.5 --- src/edit/animations.cpp | 9 +++++++ tests/golden/02_items.merge_prepend.xml | 6 ++--- .../golden/09_legacy_quirks.merge_prepend.xml | 6 ++--- tests/operations.cpp | 24 +++++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/edit/animations.cpp b/src/edit/animations.cpp index fb68394..12b179c 100644 --- a/src/edit/animations.cpp +++ b/src/edit/animations.cpp @@ -387,6 +387,8 @@ namespace anm2ed::edit { auto& merged = *model.animation_edit(target); if (!merged.name.ends_with(ANIMATION_MERGED_SUFFIX)) merged.name += std::string(ANIMATION_MERGED_SUFFIX); + // Triggers are placed by time, so whichever animation ends up second has its triggers moved past the first. + auto length = merged.frameNum; for (auto index : sources) { if (index == target) continue; @@ -394,6 +396,13 @@ namespace anm2ed::edit if (!source) continue; auto sourceCopy = *source; auto& destination = *model.animation_edit(target); + if (type == types::merge::APPEND) + for (auto& trigger : sourceCopy.triggers.frames) + trigger.atFrame += length; + if (type == types::merge::PREPEND) + for (auto& trigger : destination.triggers.frames) + trigger.atFrame += sourceCopy.frameNum; + if (type == types::merge::APPEND || type == types::merge::PREPEND) length += sourceCopy.frameNum; track_merge(destination.root, sourceCopy.root, type); track_entries_merge(destination.layers, sourceCopy.layers, type); track_entries_merge(destination.nulls, sourceCopy.nulls, type); diff --git a/tests/golden/02_items.merge_prepend.xml b/tests/golden/02_items.merge_prepend.xml index 5275427..af00486 100644 --- a/tests/golden/02_items.merge_prepend.xml +++ b/tests/golden/02_items.merge_prepend.xml @@ -45,14 +45,14 @@ - + - + - + diff --git a/tests/golden/09_legacy_quirks.merge_prepend.xml b/tests/golden/09_legacy_quirks.merge_prepend.xml index 73c2e73..d71e3f6 100644 --- a/tests/golden/09_legacy_quirks.merge_prepend.xml +++ b/tests/golden/09_legacy_quirks.merge_prepend.xml @@ -16,7 +16,7 @@ - + @@ -30,8 +30,8 @@ - - + + diff --git a/tests/operations.cpp b/tests/operations.cpp index 565d50b..62c08ce 100644 --- a/tests/operations.cpp +++ b/tests/operations.cpp @@ -378,3 +378,27 @@ TEST_CASE("change all frame properties changes layer depth only") CHECK(model.frame_get(layer)->depth == 1); CHECK(model.frame_get(null)->depth == 0); } + +TEST_CASE("animations_merge moves triggers past the animation placed before them") +{ + auto model_make = []() + { + auto model = fixture_load("01_minimal.anm2"); + auto first = *model.animation_get(0); + first.frameNum = 10; + auto second = first; + second.uid = util::uid_next(); + second.triggers.frames = {model::Frame{.atFrame = 5}}; + model.animations.entries = {std::make_shared(first), + std::make_shared(second)}; + return model; + }; + + auto appended = model_make(); + edit::animations_merge(appended, 0, {0, 1}, types::merge::APPEND, false, {}); + CHECK(appended.animation_get(0)->triggers.frames.at(0).atFrame == 15); + + auto prepended = model_make(); + edit::animations_merge(prepended, 1, {0, 1}, types::merge::PREPEND, false, {}); + CHECK(prepended.animation_get(1)->triggers.frames.at(0).atFrame == 15); +}