From 3a43608c28ff5c7baa8cc56a8d4464149b627bed Mon Sep 17 00:00:00 2001 From: Acid Bubbles Date: Mon, 28 Aug 2023 13:31:18 -0400 Subject: [PATCH] Fix copy paste controls crashing with stackoverflow --- .../Animations/AtomAnimationClip.cs | 34 ++--- .../Editing/AtomAnimationEditContext.cs | 2 +- .../Operations/AddAnimationOperations.cs | 14 +- .../Operations/LayersOperations.cs | 2 +- .../Operations/RecordOperations.cs | 3 +- .../Operations/TargetsOperations.cs | 2 +- .../Serialization/AtomAnimationSerializer.cs | 6 +- src/UI/Screens/AddRemoveTargetsScreen.cs | 6 +- src/UI/Screens/AddSegmentScreen.cs | 4 +- .../Screens/ControllerTargetSettingsScreen.cs | 2 +- tests/Specs/ImportOperationTests.cs | 144 +++++++++--------- tests/Specs/ResizeAnimationOperationTests.cs | 6 +- 12 files changed, 112 insertions(+), 113 deletions(-) diff --git a/src/AtomAnimations/Animations/AtomAnimationClip.cs b/src/AtomAnimations/Animations/AtomAnimationClip.cs index e62cb14e..dbaf06f2 100644 --- a/src/AtomAnimations/Animations/AtomAnimationClip.cs +++ b/src/AtomAnimations/Animations/AtomAnimationClip.cs @@ -754,62 +754,62 @@ public void Leave() #region Add/Remove Targets - public IAtomAnimationTarget Add(IAtomAnimationTarget target) + public IAtomAnimationTarget AddAny(IAtomAnimationTarget target) { if (target is FreeControllerV3AnimationTarget) - return Add((FreeControllerV3AnimationTarget)target); + return AddController((FreeControllerV3AnimationTarget)target); if (target is JSONStorableFloatAnimationTarget) - return Add((JSONStorableFloatAnimationTarget)target); + return AddFloatParam((JSONStorableFloatAnimationTarget)target); if (target is TriggersTrackAnimationTarget) - return Add((TriggersTrackAnimationTarget)target); + return AddTriggers((TriggersTrackAnimationTarget)target); throw new NotSupportedException($"Cannot add unknown target type {target}"); } - public FreeControllerV3AnimationTarget Add(FreeControllerV3Ref controllerRef, bool targetsPosition, bool targetsRotation) + public FreeControllerV3AnimationTarget AddController(FreeControllerV3Ref controllerRef, bool targetsPosition, bool targetsRotation) { if (targetControllers.Any(c => c.TargetsSameAs(controllerRef, targetsPosition, targetsRotation))) return null; - return Add(new FreeControllerV3AnimationTarget(controllerRef, targetsPosition, targetsRotation)); + return AddController(new FreeControllerV3AnimationTarget(controllerRef, targetsPosition, targetsRotation)); } - public JSONStorableFloatAnimationTarget Add(JSONStorableFloatRef floatRef) + public JSONStorableFloatAnimationTarget AddFloatParam(JSONStorableFloatRef floatRef) { if (targetFloatParams.Any(t => t.animatableRef == floatRef)) return null; floatRef.EnsureAvailable(); - return Add(new JSONStorableFloatAnimationTarget(floatRef)); + return AddFloatParam(new JSONStorableFloatAnimationTarget(floatRef)); } - public TriggersTrackAnimationTarget Add(TriggersTrackRef triggersRef) + public TriggersTrackAnimationTarget AddTriggers(TriggersTrackRef triggersRef) { if (targetTriggers.Any(t => t.animatableRef == triggersRef)) return null; if (triggersRef.animationLayerQualifiedId != animationLayerQualifiedId) throw new InvalidOperationException("Triggers track is not owned by the current layer"); - return Add(new TriggersTrackAnimationTarget(triggersRef, _logger)); + return AddTriggers(new TriggersTrackAnimationTarget(triggersRef, _logger)); } - public IAtomAnimationTarget Add(AnimatableRefBase animatableRef) + public IAtomAnimationTarget AddAny(AnimatableRefBase animatableRef) { if (animatableRef is FreeControllerV3Ref) - return Add((FreeControllerV3Ref)animatableRef); + return AddController((FreeControllerV3Ref)animatableRef, true, true); if (animatableRef is JSONStorableFloatRef) - return Add((JSONStorableFloatRef)animatableRef); + return AddFloatParam((JSONStorableFloatRef)animatableRef); if (animatableRef is TriggersTrackRef) - return Add((TriggersTrackRef)animatableRef); + return AddTriggers((TriggersTrackRef)animatableRef); throw new NotSupportedException($"Cannot add unknown animatableRef type {animatableRef}"); } - public FreeControllerV3AnimationTarget Add(FreeControllerV3AnimationTarget target) + public FreeControllerV3AnimationTarget AddController(FreeControllerV3AnimationTarget target) { if (targetControllers.Any(target.TargetsSameAs)) return null; foreach (var curve in target.curves) { curve.loop = _loop; } return Add(targetControllers, new FreeControllerV3AnimationTarget.Comparer(), target); } - public JSONStorableFloatAnimationTarget Add(JSONStorableFloatAnimationTarget target) + public JSONStorableFloatAnimationTarget AddFloatParam(JSONStorableFloatAnimationTarget target) { target.value.loop = _loop; return Add(targetFloatParams, new JSONStorableFloatAnimationTarget.Comparer(), target); } - public TriggersTrackAnimationTarget Add(TriggersTrackAnimationTarget target) + public TriggersTrackAnimationTarget AddTriggers(TriggersTrackAnimationTarget target) { return Add(targetTriggers, new TriggersTrackAnimationTarget.Comparer(), target); } diff --git a/src/AtomAnimations/Editing/AtomAnimationEditContext.cs b/src/AtomAnimations/Editing/AtomAnimationEditContext.cs index 7148efd2..78c1dadc 100644 --- a/src/AtomAnimations/Editing/AtomAnimationEditContext.cs +++ b/src/AtomAnimations/Editing/AtomAnimationEditContext.cs @@ -610,7 +610,7 @@ private void AddTargetIfMissing(List entries, F { continue; } - var added = clip.Add(animatableRefToAdd); + var added = clip.AddAny(animatableRefToAdd); if (added == null) { SuperController.LogError($"Timeline: Cannot paste {animatableRef.GetFullName()}, invalid add state."); diff --git a/src/AtomAnimations/Operations/AddAnimationOperations.cs b/src/AtomAnimations/Operations/AddAnimationOperations.cs index b75f55d5..b7d9c272 100644 --- a/src/AtomAnimations/Operations/AddAnimationOperations.cs +++ b/src/AtomAnimations/Operations/AddAnimationOperations.cs @@ -68,7 +68,7 @@ public CreatedAnimation AddAnimation(AtomAnimationClip source, string animationN foreach (var origTarget in source.targetFloatParams) { if (!origTarget.animatableRef.EnsureAvailable(false)) continue; - var newTarget = clip.Add(new JSONStorableFloatAnimationTarget(origTarget)); + var newTarget = clip.AddFloatParam(new JSONStorableFloatAnimationTarget(origTarget)); newTarget.group = origTarget.group; newTarget.value.keys = new List(origTarget.value.keys); newTarget.dirty = true; @@ -76,7 +76,7 @@ public CreatedAnimation AddAnimation(AtomAnimationClip source, string animationN foreach (var origTarget in source.targetTriggers) { - var newTarget = clip.Add(new TriggersTrackAnimationTarget(origTarget.animatableRef, _animation.logger)); + var newTarget = clip.AddTriggers(new TriggersTrackAnimationTarget(origTarget.animatableRef, _animation.logger)); newTarget.group = origTarget.group; foreach (var origTrigger in origTarget.triggersMap) { @@ -101,7 +101,7 @@ public CreatedAnimation AddAnimation(AtomAnimationClip source, string animationN foreach (var origTarget in source.targetFloatParams) { if (!origTarget.animatableRef.EnsureAvailable(false)) continue; - var newTarget = clip.Add(origTarget.animatableRef); + var newTarget = clip.AddFloatParam(origTarget.animatableRef); newTarget.group = origTarget.group; newTarget.SetKeyframeToCurrent(0f); newTarget.SetKeyframeToCurrent(clip.animationLength); @@ -112,7 +112,7 @@ public CreatedAnimation AddAnimation(AtomAnimationClip source, string animationN var newTarget = new TriggersTrackAnimationTarget(origTarget.animatableRef, _animation.logger); newTarget.group = origTarget.group; newTarget.AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(newTarget); + clip.AddTriggers(newTarget); } } @@ -163,7 +163,7 @@ private CreatedAnimation AddTransitionAnimation(AtomAnimationClip source) foreach (var origTarget in source.targetFloatParams) { if (!origTarget.animatableRef.EnsureAvailable(false)) continue; - var newTarget = clip.Add(origTarget.animatableRef); + var newTarget = clip.AddFloatParam(origTarget.animatableRef); newTarget.SetCurveSnapshot(0f, origTarget.GetCurveSnapshot(source.animationLength)); newTarget.SetCurveSnapshot(clip.animationLength, next.targetFloatParams.First(t => t.TargetsSameAs(origTarget)).GetCurveSnapshot(0f)); } @@ -172,7 +172,7 @@ private CreatedAnimation AddTransitionAnimation(AtomAnimationClip source) { var newTarget = new TriggersTrackAnimationTarget(origTarget.animatableRef, _animation.logger); newTarget.AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(newTarget); + clip.AddTriggers(newTarget); } source.nextAnimationName = clip.animationName; @@ -181,7 +181,7 @@ private CreatedAnimation AddTransitionAnimation(AtomAnimationClip source) private static FreeControllerV3AnimationTarget CopyTarget(AtomAnimationClip clip, FreeControllerV3AnimationTarget origTarget) { - var newTarget = clip.Add(origTarget.animatableRef, origTarget.targetsPosition, origTarget.targetsRotation); + var newTarget = clip.AddController(origTarget.animatableRef, origTarget.targetsPosition, origTarget.targetsRotation); newTarget.SetParent(origTarget.parentAtomId, origTarget.parentRigidbodyId); newTarget.weight = origTarget.weight; newTarget.targetsPosition = origTarget.targetsPosition; diff --git a/src/AtomAnimations/Operations/LayersOperations.cs b/src/AtomAnimations/Operations/LayersOperations.cs index faae0677..8b6f5635 100644 --- a/src/AtomAnimations/Operations/LayersOperations.cs +++ b/src/AtomAnimations/Operations/LayersOperations.cs @@ -45,7 +45,7 @@ public List SplitLayer(List targets, st foreach (var t in sourceClip.GetAllTargets().Where(t => targets.Any(t.TargetsSameAs)).ToList()) { sourceClip.Remove(t); - newClip.Add(t); + newClip.AddAny(t); } created.Add(newClip); } diff --git a/src/AtomAnimations/Operations/RecordOperations.cs b/src/AtomAnimations/Operations/RecordOperations.cs index ae389ef0..8a9ee9ae 100644 --- a/src/AtomAnimations/Operations/RecordOperations.cs +++ b/src/AtomAnimations/Operations/RecordOperations.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; diff --git a/src/AtomAnimations/Operations/TargetsOperations.cs b/src/AtomAnimations/Operations/TargetsOperations.cs index 27494dee..8674328c 100644 --- a/src/AtomAnimations/Operations/TargetsOperations.cs +++ b/src/AtomAnimations/Operations/TargetsOperations.cs @@ -22,7 +22,7 @@ public FreeControllerV3AnimationTarget Add(FreeControllerV3 fc) if (target != null) return target; foreach (var clip in _animation.index.ByLayerQualified(_clip.animationLayerQualifiedId)) { - var t = clip.Add(_animation.animatables.GetOrCreateController(fc, fc.containingAtom == _containingAtom), true, true); + var t = clip.AddController(_animation.animatables.GetOrCreateController(fc, fc.containingAtom == _containingAtom), true, true); if (t == null) continue; t.SetKeyframeToCurrent(0f); t.SetKeyframeToCurrent(clip.animationLength); diff --git a/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs b/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs index 5b26a0a3..e7ea2092 100644 --- a/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs +++ b/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs @@ -199,7 +199,7 @@ private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON, Animata continue; } - var target = clip.Add(controllerRef, DeserializeBool(controllerJSON["TargetsPosition"], true), DeserializeBool(controllerJSON["TargetsRotation"], true)); + var target = clip.AddController(controllerRef, DeserializeBool(controllerJSON["TargetsPosition"], true), DeserializeBool(controllerJSON["TargetsRotation"], true)); if (target == null) { SuperController.LogError( @@ -262,7 +262,7 @@ private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON, Animata paramJSON.HasKey("Min") ? (float?)paramJSON["Min"].AsFloat : null, paramJSON.HasKey("Max") ? (float?)paramJSON["Max"].AsFloat : null ); - var target = clip.Add(floatParamRef); + var target = clip.AddFloatParam(floatParamRef); if (target == null) { SuperController.LogError( @@ -288,7 +288,7 @@ private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON, Animata var triggerTrackRef = targetsRegistry.GetOrCreateTriggerTrack(clip.animationLayerQualifiedId, triggerTrackName); //NOTE: We are cheating here, the saved setting is on each track but the animatable itself will have the setting triggerTrackRef.live = triggerLive; - var target = clip.Add(triggerTrackRef); + var target = clip.AddTriggers(triggerTrackRef); if (target == null) { target = clip.targetTriggers.FirstOrDefault(t => t.name == triggerTrackName); diff --git a/src/UI/Screens/AddRemoveTargetsScreen.cs b/src/UI/Screens/AddRemoveTargetsScreen.cs index da040dde..af2b5167 100644 --- a/src/UI/Screens/AddRemoveTargetsScreen.cs +++ b/src/UI/Screens/AddRemoveTargetsScreen.cs @@ -115,7 +115,7 @@ private void AddTrack(TriggersTrackRef track) if (clip.targetTriggers.Any(t => t.TargetsSameAs(track))) continue; var target = new TriggersTrackAnimationTarget(track, animation.logger); target.AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(target); + clip.AddTriggers(target); } } @@ -446,7 +446,7 @@ private void AddAnimatedController() foreach (var clip in currentLayer) { - var added = clip.Add(animation.animatables.GetOrCreateController(controller, atom == plugin.containingAtom), targetsPosition == null, targetsRotation == null); + var added = clip.AddController(animation.animatables.GetOrCreateController(controller, atom == plugin.containingAtom), targetsPosition == null, targetsRotation == null); if (added == null) continue; var controllerPose = clip.pose?.GetControllerPose(controller.name); @@ -520,7 +520,7 @@ private bool AddFloatParam(JSONStorable storable, JSONStorableFloat jsf) foreach (var clip in currentLayer) { var storableFloat = animation.animatables.GetOrCreateStorableFloat(storable, jsf, storable.containingAtom == plugin.containingAtom); - var added = clip.Add(storableFloat); + var added = clip.AddFloatParam(storableFloat); if (added == null) continue; added.SetKeyframe(0f, jsf.val); diff --git a/src/UI/Screens/AddSegmentScreen.cs b/src/UI/Screens/AddSegmentScreen.cs index 21489fc0..c725be9d 100644 --- a/src/UI/Screens/AddSegmentScreen.cs +++ b/src/UI/Screens/AddSegmentScreen.cs @@ -184,7 +184,7 @@ private void CreateTransitionSegment() { foreach (var target in layer.targetControllers) { - var added = clip.Add(target.animatableRef, target.targetsPosition, target.targetsRotation); + var added = clip.AddController(target.animatableRef, target.targetsPosition, target.targetsRotation); if (added != null) { var snapshot = target.GetCurveSnapshot(layer.animationLength); @@ -194,7 +194,7 @@ private void CreateTransitionSegment() } foreach (var target in layer.targetFloatParams) { - var added =clip.Add(target.animatableRef); + var added =clip.AddFloatParam(target.animatableRef); if (added != null) { var snapshot = target.GetCurveSnapshot(layer.animationLength); diff --git a/src/UI/Screens/ControllerTargetSettingsScreen.cs b/src/UI/Screens/ControllerTargetSettingsScreen.cs index c5374caa..6e9f999f 100644 --- a/src/UI/Screens/ControllerTargetSettingsScreen.cs +++ b/src/UI/Screens/ControllerTargetSettingsScreen.cs @@ -100,7 +100,7 @@ private void InitSplitPosRotUI() if (target == null) continue; var pos = target; pos.targetsRotation = false; - var rot = clip.Add(pos.animatableRef, false, true); + var rot = clip.AddController(pos.animatableRef, false, true); if (rot == null) throw new NullReferenceException("Could not add rotation controller"); rot.rotation.rotX.keys = new List(pos.rotation.rotX.keys); rot.rotation.rotY.keys = new List(pos.rotation.rotY.keys); diff --git a/tests/Specs/ImportOperationTests.cs b/tests/Specs/ImportOperationTests.cs index 2f0f9893..5aa06cb4 100644 --- a/tests/Specs/ImportOperationTests.cs +++ b/tests/Specs/ImportOperationTests.cs @@ -28,17 +28,17 @@ private IEnumerable CanImport_PerfectMatch_ExistingSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -74,17 +74,17 @@ private IEnumerable CanImport_PerfectMatch_NewSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -118,17 +118,17 @@ private IEnumerable CanImport_PartialMismatch_NewSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -162,17 +162,17 @@ private IEnumerable CanImport_FullMismatch_ExistingSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -216,17 +216,17 @@ private IEnumerable CanImport_FullMismatch_NewSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -260,17 +260,17 @@ private IEnumerable CanImport_Conflict_SegmentName(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment IMPORTED", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -291,17 +291,17 @@ private IEnumerable CanImport_Conflict_LayerName(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer IMPORTED", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -318,17 +318,17 @@ private IEnumerable CanImport_Conflict_AnimName(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim IMPORTED", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -347,18 +347,18 @@ private IEnumerable CanImport_Source_SharedSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", AtomAnimationClip.SharedAnimationSegment, context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); clip.animationSegment = AtomAnimationClip.SharedAnimationSegment; - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -392,18 +392,18 @@ private IEnumerable CanImport_Source_NewSharedSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); clip.animationSegment = AtomAnimationClip.SharedAnimationSegment; - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F2")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T2")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -437,17 +437,17 @@ private IEnumerable CanImport_Conflict_SharedSegment(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", AtomAnimationClip.SharedAnimationSegment, context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } @@ -463,18 +463,18 @@ private IEnumerable CanImport_LegacyClip(TestContext context) context.animation.RemoveClip(context.animation.clips[0]); { var clip = new AtomAnimationClip("Anim 1", "Layer 1", "Segment 1", context.logger); - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); context.animation.AddClip(clip); } ImportOperationClip ctx; { var clip = GivenImportedClip(context); clip.animationSegment = AtomAnimationClip.NoneAnimationSegment; - clip.Add(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); - clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddAny(helper.GivenFreeController("C1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddFloatParam(helper.GivenFloatParam("F1")).AddEdgeFramesIfMissing(clip.animationLength); + clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId, "T1")).AddEdgeFramesIfMissing(clip.animationLength); ctx = new ImportOperationClip(context.animation, clip); } diff --git a/tests/Specs/ResizeAnimationOperationTests.cs b/tests/Specs/ResizeAnimationOperationTests.cs index 4991f448..0765754b 100644 --- a/tests/Specs/ResizeAnimationOperationTests.cs +++ b/tests/Specs/ResizeAnimationOperationTests.cs @@ -246,7 +246,7 @@ public IEnumerable CropOrExtendBeginShorterTrigger(TestContext context) private static FreeControllerV3AnimationTarget GivenThreeKeyframesFreeController(TestContext context, AtomAnimationClip clip) { var helper = new TargetsHelper(context); - var target = clip.Add(helper.GivenFreeController(), true, true); + var target = clip.AddController(helper.GivenFreeController(), true, true); context.Assert(clip.animationLength, 2f, "Default animation length"); target.SetKeyframeByTime(0f, Vector3.zero, Quaternion.identity); target.SetKeyframeByTime(1f, Vector3.one, Quaternion.identity); @@ -259,7 +259,7 @@ private static FreeControllerV3AnimationTarget GivenThreeKeyframesFreeController private static JSONStorableFloatAnimationTarget GivenThreeKeyframesFloatParam(TestContext context, AtomAnimationClip clip) { var helper = new TargetsHelper(context); - var target = clip.Add(helper.GivenFloatParam()); + var target = clip.AddFloatParam(helper.GivenFloatParam()); context.Assert(clip.animationLength, 2f, "Default animation length"); target.SetKeyframe(0f, 0f); target.SetKeyframe(1f, 1f); @@ -272,7 +272,7 @@ private static JSONStorableFloatAnimationTarget GivenThreeKeyframesFloatParam(Te private static TriggersTrackAnimationTarget GivenThreeKeyframesTrigger(TestContext context, AtomAnimationClip clip) { var helper = new TargetsHelper(context); - var target = clip.Add(helper.GivenTriggers(clip.animationLayerQualifiedId)); + var target = clip.AddTriggers(helper.GivenTriggers(clip.animationLayerQualifiedId)); context.Assert(clip.animationLength, 2f, "Default animation length"); target.CreateKeyframe(0f.ToMilliseconds()); target.CreateKeyframe(1f.ToMilliseconds());