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 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-06 02:03:20 -04:00
1 parent a440af3c95
commit ef5796d667
4 files changed
+39 -6

No files matched your search

+9
View File
@@ -387,6 +387,8 @@ namespace anm2ed::edit
{ {
auto& merged = *model.animation_edit(target); auto& merged = *model.animation_edit(target);
if (!merged.name.ends_with(ANIMATION_MERGED_SUFFIX)) merged.name += std::string(ANIMATION_MERGED_SUFFIX); 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) for (auto index : sources)
{ {
if (index == target) continue; if (index == target) continue;
@@ -394,6 +396,13 @@ namespace anm2ed::edit
if (!source) continue; if (!source) continue;
auto sourceCopy = *source; auto sourceCopy = *source;
auto& destination = *model.animation_edit(target); 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_merge(destination.root, sourceCopy.root, type);
track_entries_merge(destination.layers, sourceCopy.layers, type); track_entries_merge(destination.layers, sourceCopy.layers, type);
track_entries_merge(destination.nulls, sourceCopy.nulls, type); track_entries_merge(destination.nulls, sourceCopy.nulls, type);
+3 -3
View File
@@ -45,14 +45,14 @@
<NullAnimation NullId="1" Visible="true"/> <NullAnimation NullId="1" Visible="true"/>
</NullAnimations> </NullAnimations>
<Triggers> <Triggers>
<Trigger EventId="0" AtFrame="0"> <Trigger EventId="0" AtFrame="1">
<Sound Id="0"/> <Sound Id="0"/>
</Trigger> </Trigger>
<Trigger EventId="1" AtFrame="4"> <Trigger EventId="1" AtFrame="5">
<Sound Id="0"/> <Sound Id="0"/>
<Sound Id="1"/> <Sound Id="1"/>
</Trigger> </Trigger>
<Trigger AtFrame="6"> <Trigger AtFrame="7">
<Sound Id="1"/> <Sound Id="1"/>
</Trigger> </Trigger>
</Triggers> </Triggers>
@@ -16,7 +16,7 @@
</Events> </Events>
</Content> </Content>
<Animations DefaultAnimation="Missing"> <Animations DefaultAnimation="Missing">
<Animation Name="A (Merged)" FrameNum="9" Loop="true"> <Animation Name="A (Merged)" FrameNum="10" Loop="true">
<RootAnimation> <RootAnimation>
<Frame XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" ShearX="0" ShearY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/> <Frame XPosition="0" YPosition="0" Delay="4" Visible="true" XScale="100" YScale="100" ShearX="0" ShearY="0" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
</RootAnimation> </RootAnimation>
@@ -30,8 +30,8 @@
<LayerAnimation LayerId="99" Visible="true"/> <LayerAnimation LayerId="99" Visible="true"/>
</LayerAnimations> </LayerAnimations>
<Triggers> <Triggers>
<Trigger EventId="5" AtFrame="2"/> <Trigger EventId="5" AtFrame="3"/>
<Trigger EventId="8" AtFrame="9"/> <Trigger EventId="8" AtFrame="10"/>
</Triggers> </Triggers>
</Animation> </Animation>
</Animations> </Animations>
+24
View File
@@ -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(layer)->depth == 1);
CHECK(model.frame_get(null)->depth == 0); 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<const model::Animation>(first),
std::make_shared<const model::Animation>(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);
}