Exemple #1
0
        /// <summary>
        /// Duplicates the given Animation on this bundle. The duplicated animation has its name sulfix
        /// changed to avoid name conflicts
        /// </summary>
        /// <param name="anim">The animation to duplicate</param>
        /// <param name="sheet">The AnimationSheet to add the duplicated animation to</param>
        /// <param name="rearrange">Whether to re-arrange the index of the animation on the container</param>
        /// <returns>The new animation that was duplicated</returns>
        public Animation DuplicateAnimation(Animation anim, AnimationSheet sheet, bool rearrange = true)
        {
            var dup = anim.Clone();

            dup.ID = GetNextValidAnimationID();

            sheet = (sheet ?? GetOwningAnimationSheet(anim));

            AddAnimation(dup, sheet);

            if (rearrange)
            {
                int index = GetAnimationIndex(anim);

                RearrangeAnimationsPosition(dup, index + 1);
            }

            // Find a new name for the animation
            int n = 2;

            while (true)
            {
                if (GetAnimationByName(anim.Name + "_" + n) == null)
                {
                    break;
                }

                n++;
            }

            dup.Name = anim.Name + "_" + n;

            return(dup);
        }
Exemple #2
0
        /// <summary>
        /// Duplicates the given animation sheet on this bundle. The duplicated sheet has its name sulfix
        /// changed to avoid name conflicts. The animations on the sheet are also copied over
        /// </summary>
        /// <param name="sheet">The animation sheet to duplicate</param>
        /// <returns>The new animation sheet that was duplicated</returns>
        public AnimationSheet DuplicateAnimationSheet(AnimationSheet sheet)
        {
            // Find a new name for the animation
            int n = 2;

            while (true)
            {
                if (GetAnimationSheetByName(sheet.Name + "_" + n) == null)
                {
                    break;
                }

                n++;
            }

            string dupName = sheet.Name + "_" + n;

            // Create the duplicated animation sheet
            var dup = new AnimationSheet(dupName)
            {
                ID             = GetNextValidAnimationSheetID(),
                ExportSettings = sheet.ExportSettings
            };

            AddAnimationSheet(dup);

            // Duplicate the animations
            foreach (Animation anim in sheet.Animations)
            {
                DuplicateAnimation(anim, dup, false);
            }

            return(dup);
        }
Exemple #3
0
        /// <summary>
        /// Adds the given animation sheet to this bundle
        /// </summary>
        /// <param name="sheet">The animation sheet to add to this bundle</param>
        public void AddAnimationSheet(AnimationSheet sheet)
        {
            if (sheet.ID == -1)
            {
                sheet.ID = GetNextValidAnimationSheetID();
            }

            if (GetAnimationSheetByID(sheet.ID) != null)
            {
                throw new ArgumentException("Trying to add an animation sheet that has a conflict of IDs with an animation sheet already on this bundle.");
            }

            _animationSheets.Add(sheet);

            foreach (var animation in sheet.Animations)
            {
                if (!_animations.Contains(animation))
                {
                    _animations.Add(animation);
                }
            }

            foreach (var animation in sheet.Animations)
            {
                if (animation.ID == -1)
                {
                    animation.ID = GetNextValidAnimationID();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Adds an existing animation into this bundle, and couples it inside
        /// the given animation sheet.
        /// The animation sheet must be a part of this bundle before this method call, or else
        /// the animation will not be added to the sheet. The method still adds the animation
        /// to this bundle even if it's not added to the animation sheet.
        /// </summary>
        /// <param name="anim">The animation to add to this bundle</param>
        /// <param name="parentAnimationSheet">The animation sheet to add the animation to</param>
        public void AddAnimation(Animation anim, AnimationSheet parentAnimationSheet)
        {
            AddAnimation(anim);

            if (_animationSheets.Contains(parentAnimationSheet))
            {
                parentAnimationSheet.AddAnimation(anim);
            }
        }
Exemple #5
0
        /// <summary>
        /// Adds the given Animation object into the given AnimationSheet object.
        /// If null is provided as animation sheet, the animation is removed from it's current animation sheet, if it's inside one
        /// </summary>
        /// <param name="anim">The animation to add to the animation sheet</param>
        /// <param name="sheet">The AnimationSheet to add the animation to</param>
        public void AddAnimationToAnimationSheet(Animation anim, AnimationSheet sheet)
        {
            // Get the current AnimationSheet owning the given anim
            AnimationSheet curSheet = GetOwningAnimationSheet(anim);

            if (curSheet != null)
            {
                RemoveAnimationFromAnimationSheet(anim, curSheet);
            }

            sheet?.AddAnimation(anim);
        }
Exemple #6
0
        /// <summary>
        /// Gets the index of the given Animation object in its current parent container
        /// </summary>
        /// <param name="anim">The animation to get the index of</param>
        /// <returns>The index of the animation in its current parent container</returns>
        public int GetAnimationIndex(Animation anim)
        {
            AnimationSheet sheet = GetOwningAnimationSheet(anim);

            if (sheet == null)
            {
                return(_animations.IndexOf(anim));
            }
            else
            {
                return(sheet.IndexOfAnimation(anim));
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates an exact copy of this AnimationSheet object, with all animations and their respective frames cloned as well
        /// </summary>
        public AnimationSheet Clone()
        {
            AnimationSheet sheetClone = new AnimationSheet(Name)
            {
                ExportSettings = ExportSettings
            };

            foreach (var animation in _animations)
            {
                sheetClone.AddAnimation(animation.Clone());
            }

            return(sheetClone);
        }
Exemple #8
0
        /// <summary>
        /// Rearranges the index of an animation in the animation's current storing container
        /// </summary>
        /// <param name="anim">The animation to rearrange</param>
        /// <param name="newIndex">The new index to place the animation at</param>
        public void RearrangeAnimationsPosition(Animation anim, int newIndex)
        {
            AnimationSheet sheet = GetOwningAnimationSheet(anim);

            if (sheet == null)
            {
                _animations.Remove(anim);
                _animations.Insert(newIndex, anim);
            }
            else
            {
                sheet.RemoveAnimation(anim);
                sheet.InsertAnimation(anim, newIndex);
            }
        }
Exemple #9
0
        /// <summary>
        /// Removes the given animation sheet from this bundle.
        /// Removing an animation sheet decouples all animations from it automatically
        /// </summary>
        /// <param name="sheet">The animation sheet to remove</param>
        /// <param name="deleteAnimations">Whether to delete the nested animations as well. If set to false, the animations will be moved to the bundle's root</param>
        public void RemoveAnimationSheet(AnimationSheet sheet, bool deleteAnimations)
        {
            // Remove/relocate the animations
            foreach (Animation anim in sheet.Animations)
            {
                sheet.RemoveAnimation(anim);

                if (deleteAnimations)
                {
                    RemoveAnimation(anim);
                }
            }

            // Decouple all animatins from the sheet
            sheet.ClearAnimationList();

            _animationSheets.Remove(sheet);
        }
Exemple #10
0
        /// <summary>
        /// Clones this bundle into a new bundle object that has all of this bundle's properties deep cloned
        /// </summary>
        public Bundle Clone()
        {
            Bundle newBundle = new Bundle(Name)
            {
                ExportPath = ExportPath, SaveFile = SaveFile
            };

            // Copy animations over
            foreach (var animation in _animations)
            {
                Animation anim = animation.Clone();
                anim.ID = animation.ID;

                newBundle.AddAnimation(animation.Clone());

                // Maintain frame IDs
                for (int i = 0; i < anim.FrameCount; i++)
                {
                    anim[i].ID = animation[i].ID;
                }
            }

            // Copy Animation Sheets over
            foreach (var animationSheet in _animationSheets)
            {
                AnimationSheet newSheet = new AnimationSheet(animationSheet.Name);
                newBundle.AddAnimationSheet(newSheet);

                foreach (Animation anim in animationSheet.Animations)
                {
                    newBundle.AddAnimationToAnimationSheet(newBundle.GetAnimationByID(anim.ID), newSheet);
                }
            }

            // Copy frame ID indexing for consistency
            newBundle._nextFrameId = _nextFrameId;

            return(newBundle);
        }
Exemple #11
0
        // Override object.Equals
        public override bool Equals(object obj)
        {
            //
            // See the full list of guidelines at
            //   http://go.microsoft.com/fwlink/?LinkID=85237
            // and also the guidance for operator== at
            //   http://go.microsoft.com/fwlink/?LinkId=85238
            //

            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            AnimationSheet other = (AnimationSheet)obj;

            if (_animations == null || other._animations == null || _animations.Count != other._animations.Count || Name != other.Name || !ExportSettings.Equals(other.ExportSettings))
            {
                return(false);
            }

            // Iterate through each fo the animations and check for an inequality
            // Disable LINQ suggestion because it'd actually be considerably slower
            // ReSharper disable once LoopCanBeConvertedToQuery
            for (int i = 0; i < _animations.Count; i++)
            {
                if (!_animations[i].Equals(other._animations[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
0
 /// <summary>
 /// Removes the given Animation object from the given AnimationSheet object
 /// </summary>
 /// <param name="anim">The animation to remove from the animation sheet</param>
 /// <param name="sheet">The AnimationSheet to remove the animation from</param>
 public void RemoveAnimationFromAnimationSheet(Animation anim, AnimationSheet sheet)
 {
     sheet.RemoveAnimation(anim);
 }
Exemple #13
0
 /// <summary>
 /// Rearranges the index of an AnimationSheets in the sheets's current storing container
 /// </summary>
 /// <param name="sheet">The sheet to rearrange</param>
 /// <param name="newIndex">The new index to place the sheet at</param>
 public void RearrangeAnimationSheetsPosition(AnimationSheet sheet, int newIndex)
 {
     _animationSheets.Remove(sheet);
     _animationSheets.Insert(newIndex, sheet);
 }
Exemple #14
0
 /// <summary>
 /// Gets the index of the given AnimationSheet object inside its current parent container
 /// </summary>
 /// <param name="sheet">The sheet to get the index of</param>
 /// <returns>The index of the sheet in its current parent container</returns>
 public int GetAnimationSheetIndex(AnimationSheet sheet)
 {
     return(_animationSheets.IndexOf(sheet));
 }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the AnimationSheetProjectTreeNode class
 /// </summary>
 /// <param name="animationSheet">An animation sheet to bind to this AnimationSheetProjectTreeNode</param>
 public AnimationSheetProjectTreeNode(AnimationSheet animationSheet)
 {
     AnimationSheet = animationSheet;
 }