From 54bb802b83206c599f13e9ac41490462169f00ab Mon Sep 17 00:00:00 2001 From: Acid Bubbles Date: Wed, 15 Jun 2022 15:43:00 -0400 Subject: [PATCH] Fix adding triggers track on layer with mismatched tracks overwriting some triggers --- .../Serialization/AtomAnimationSerializer.cs | 12 ++++++++++-- src/UI/Screens/AddRemoveTargetsScreen.cs | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs b/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs index d99bcd77..17d511a0 100644 --- a/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs +++ b/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs @@ -252,8 +252,16 @@ private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON, Animata var target = clip.Add(triggerTrackRef); if (target == null) { - SuperController.LogError($"The triggers track {triggerTrackName} exists more than once in clip {clip.animationNameQualified}. Only the first will be kept."); - continue; + target = clip.targetTriggers.FirstOrDefault(t => t.name == triggerTrackName); + if (target == null) + { + SuperController.LogError($"The triggers track {triggerTrackName} exists more than once in clip {clip.animationNameQualified}, but couldn't be linked in the clip. Only the first track will be kept."); + continue; + } + else + { + SuperController.LogError($"The triggers track {triggerTrackName} exists more than once in clip {clip.animationNameQualified}. Trigger keyframes may be overwritten."); + } } foreach (JSONClass entryJSON in triggerJSON["Triggers"].AsArray) { diff --git a/src/UI/Screens/AddRemoveTargetsScreen.cs b/src/UI/Screens/AddRemoveTargetsScreen.cs index 9b30050d..3d1624e4 100644 --- a/src/UI/Screens/AddRemoveTargetsScreen.cs +++ b/src/UI/Screens/AddRemoveTargetsScreen.cs @@ -112,6 +112,7 @@ private void AddTrack(TriggersTrackRef track) { foreach (var clip in currentLayer) { + if (clip.targetTriggers.Any(t => t.TargetsSameAs(track))) continue; var target = new TriggersTrackAnimationTarget(track, animation.logger); target.AddEdgeFramesIfMissing(clip.animationLength); clip.Add(target);