private void GenerateAnimationEnumerables(ElementSave elementSave, ICodeBlock currentBlock) { currentBlock.Line("#region State Animations"); StateCodeGeneratorContext context = new StateCodeGeneratorContext(); context.Element = elementSave; ElementAnimationsSave animations = GetAnimationsFor(elementSave); if (animations != null) { foreach (var animation in animations.Animations) { GenerateGetEnumerableFor(context, currentBlock, animation, AbsoluteOrRelative.Absolute); GenerateGetEnumerableFor(context, currentBlock, animation, AbsoluteOrRelative.Relative); GenerateAnimationMember(context, currentBlock, animation, AbsoluteOrRelative.Absolute); GenerateAnimationMember(context, currentBlock, animation, AbsoluteOrRelative.Relative); } } currentBlock.Line("#endregion"); }
public static float GetLength(this AnimationSave animation, ElementSave elementSave, ElementAnimationsSave allAnimationSaves) { float lastState = animation.States.Max(item => item.Time); float endOfLastSubAnimation = 0; if (animation.Animations != null) { foreach (var subAnimation in animation.Animations) { AnimationSave subAnimationSave = null; ElementSave subAnimationElement = null; ElementAnimationsSave subAnimationSiblings = null; if (subAnimation.SourceObject == null) { subAnimationSave = allAnimationSaves.Animations.FirstOrDefault(item => item.Name == subAnimation.Name); subAnimationElement = elementSave; subAnimationSiblings = allAnimationSaves; } else { var instance = elementSave.Instances.FirstOrDefault(item => item.Name == subAnimation.SourceObject); if (instance != null) { ElementSave instanceElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance); if (instanceElement != null) { var instanceAnimations = AnimationCollectionViewModelManager.Self.GetElementAnimationsSave(instanceElement); subAnimationSave = instanceAnimations.Animations.FirstOrDefault(item => item.Name == subAnimation.RootName); subAnimationElement = instanceElement; subAnimationSiblings = instanceAnimations; } } } if (subAnimationSave != null) { endOfLastSubAnimation = System.Math.Max(endOfLastSubAnimation, subAnimation.Time + subAnimationSave.GetLength(subAnimationElement, subAnimationSiblings)); } } } return(System.Math.Max(lastState, endOfLastSubAnimation)); }
public static AnimationViewModel FromSave(AnimationSave save, ElementSave element, ElementAnimationsSave allAnimationSaves = null) { AnimationViewModel toReturn = new AnimationViewModel(); toReturn.Name = save.Name; toReturn.mLoops = save.Loops; foreach (var stateSave in save.States) { var foundState = element.AllStates.FirstOrDefault(item => item.Name == stateSave.StateName); var newAnimatedStateViewModel = AnimatedKeyframeViewModel.FromSave(stateSave); newAnimatedStateViewModel.HasValidState = foundState != null; toReturn.Keyframes.Add(newAnimatedStateViewModel); } foreach (var animationReference in save.Animations) { AnimationSave animationSave = null; ElementSave subAnimationElement = null; ElementAnimationsSave subAnimationSiblings = null; if (string.IsNullOrEmpty(animationReference.SourceObject)) { if (allAnimationSaves == null) { allAnimationSaves = AnimationCollectionViewModelManager.Self.GetElementAnimationsSave(element); } animationSave = allAnimationSaves.Animations.FirstOrDefault(item => item.Name == animationReference.RootName); subAnimationElement = element; subAnimationSiblings = allAnimationSaves; } else { var instance = element.Instances.FirstOrDefault(item => item.Name == animationReference.SourceObject); if (instance != null) { ElementSave instanceElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance); subAnimationElement = instanceElement; if (instanceElement != null) { var allAnimations = AnimationCollectionViewModelManager.Self.GetElementAnimationsSave(instanceElement); animationSave = allAnimations.Animations.FirstOrDefault(item => item.Name == animationReference.RootName); subAnimationElement = instanceElement; subAnimationSiblings = allAnimations; } } } var newVm = AnimatedKeyframeViewModel.FromSave(animationReference); if (animationSave != null) { newVm.SubAnimationViewModel = AnimationViewModel.FromSave(animationSave, subAnimationElement, subAnimationSiblings); } newVm.HasValidState = animationReference != null; toReturn.Keyframes.Add(newVm); } toReturn.SortList(); return(toReturn); }