示例#1
0
 private RemoveKeyframeRange(IAnimator animator, int start, int end)
 {
     this.animator = animator;
     this.start    = start;
     this.end      = end;
     this.owner    = animator.Owner;
 }
示例#2
0
 private SetKeyframe(IAnimationHost animationHost, string propertyPath, string animationId, IKeyframe keyframe)
 {
     AnimationHost = animationHost;
     PropertyPath  = propertyPath;
     Keyframe      = keyframe;
     AnimationId   = animationId;
 }
示例#3
0
 static bool IsAnimationEnabled(IAnimationHost animationHost)
 {
     foreach (var a in animationHost.Animators)
     {
         if (!a.Enabled)
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        public static (IAnimationHost, int) GetPropertyHost(IAnimationHost host, string propertyPath)
        {
            int prevIndex = 0;
            int index;

            while ((index = propertyPath.IndexOf('/', prevIndex)) >= 0)
            {
                var id = propertyPath.Substring(prevIndex, index - prevIndex);
                host = ((Node)host).TryFindNode(id);
                if (host == null)
                {
                    return(null, -1);
                }
                prevIndex = index + 1;
            }
            return(host, prevIndex);
        }
示例#5
0
 public AnimatorCollection(IAnimationHost owner)
 {
     this.owner = owner;
 }
示例#6
0
        public static (PropertyData, IAnimable, int) GetPropertyByPath(IAnimationHost host, string propertyPath)
        {
            PropertyData result    = PropertyData.Empty;
            object       o         = host;
            int          prevIndex = 0;

            if (propertyPath[0] == '[')
            {
                int index             = propertyPath.IndexOf(']');
                var componentTypeName = propertyPath.Substring(1, index - 1);
                var type = global::Yuzu.Metadata.Meta.GetTypeByReadAlias(componentTypeName, Serialization.YuzuCommonOptions)
                           ?? global::Yuzu.Util.TypeSerializer.Deserialize(componentTypeName);
                o = host.Components.Get(type);
                if (o == null)
                {
                    return(result, null, -1);
                }
                prevIndex = index + 2;
            }
            while (true)
            {
                int  periodIndex = propertyPath.IndexOf('.', prevIndex);
                bool last        = periodIndex == -1;
                int  length      = last
                                        ? propertyPath.Length - prevIndex
                                        : periodIndex - prevIndex;
                var p            = propertyPath.Substring(prevIndex, length);
                int bracketIndex = p.IndexOf('[');
                int indexInList  = -1;
                if (bracketIndex == -1)
                {
                    result = GetProperty(o.GetType(), p);
                }
                else
                {
                    indexInList = int.Parse(p.Substring(bracketIndex + 1, p.Length - bracketIndex - 2));
                    result      = GetProperty(o.GetType(), p.Substring(0, bracketIndex));
                }
                if (result.Info == null)
                {
                    return(result, null, -1);
                }
                if (last)
                {
                    return(result, (IAnimable)o, indexInList);
                }
                else
                {
                    if (indexInList == -1)
                    {
                        o = result.Info.GetValue(o);
                    }
                    else
                    {
                        o = result.Info.GetValue(o, new object[] { indexInList });
                    }
                    if (o == null)
                    {
                        return(result, null, -1);
                    }
                }
                prevIndex = periodIndex + 1;
            }
        }
示例#7
0
 static bool ArePropertyPathsCompatible(IAnimationHost object1, IAnimationHost object2, string property)
 {
     var(pd1, _, _) = AnimationUtils.GetPropertyByPath(object1, property);
     var(pd2, _, _) = AnimationUtils.GetPropertyByPath(object2, property);
     return(pd1.Info != null && pd1.Info.PropertyType == pd2.Info?.PropertyType);
 }
示例#8
0
        public static void Perform()
        {
            var keys = KeyframeClipboard.Keys;

            if (keys == null || !Document.Current.TopLevelSelectedRows().Any())
            {
                return;
            }
            int startRow = Document.Current.TopLevelSelectedRows().First().Index;
            var spans    = Document.Current.Rows[startRow].Components.Get <GridSpanListComponent>()?.Spans;

            if (spans == null || !spans.Any())
            {
                return;
            }
            int startCol = spans.First().A;

            Document.Current.History.DoTransaction(() => {
                var rows                     = Document.Current.Rows;
                int rowIndex                 = startRow;
                int animationHostIndex       = 0;
                IAnimationHost animationHost = null;
                Node node                    = null;

                foreach (var key in keys)
                {
                    int colIndex = startCol + key.Frame;
                    if (rowIndex >= Document.Current.Rows.Count || colIndex < 0)
                    {
                        continue;
                    }
                    while (rowIndex < rows.Count)
                    {
                        node          = rows[rowIndex].Components.Get <NodeRow>()?.Node;
                        animationHost = node;
                        if (animationHost != null)
                        {
                            if (animationHostIndex == key.AnimationHostOrderIndex)
                            {
                                break;
                            }
                            animationHostIndex++;
                        }
                        ++rowIndex;
                    }
                    if (rowIndex >= rows.Count)
                    {
                        break;
                    }
                    if (node.EditorState().Locked)
                    {
                        continue;
                    }
                    var(pd, _, _) = AnimationUtils.GetPropertyByPath(animationHost, key.Property);
                    if (pd.Info == null)
                    {
                        continue;
                    }
                    var keyframe   = key.Keyframe.Clone();
                    keyframe.Frame = colIndex;
                    SetKeyframe.Perform(animationHost, key.Property, Document.Current.AnimationId, keyframe);
                }
            });
        }
示例#9
0
 public static void Perform(IAnimationHost animationHost, string propertyName, string animationId, IKeyframe keyframe)
 {
     DocumentHistory.Current.Perform(new SetKeyframe(animationHost, propertyName, animationId, keyframe));
 }
示例#10
0
 private RemoveKeyframe(IAnimator animator, int frame)
 {
     Frame         = frame;
     Animator      = animator;
     AnimationHost = Animator.Owner;
 }
示例#11
0
        public static (PropertyData PropertyData, IAnimable Animable, int Index) GetPropertyByPath(IAnimationHost host, string propertyPath)
        {
            PropertyData result = PropertyData.Empty;
            int          prevIndex;

            (host, prevIndex) = GetPropertyHost(host, propertyPath);
            object o = host;

            if (propertyPath[prevIndex] == '[')
            {
                var index = IndexOfClosedBracket(prevIndex + 1, propertyPath);
                if (index < 0)
                {
                    return(result, null, -1);
                }
                var componentTypeName = propertyPath.Substring(prevIndex + 1, index - prevIndex - 1);
                var type = global::Yuzu.Metadata.Meta.GetTypeByReadAlias(componentTypeName, InternalPersistence.Instance.YuzuCommonOptions)
                           ?? global::Yuzu.Util.TypeSerializer.Deserialize(componentTypeName);
                o = host.GetComponent(type);
                if (o == null)
                {
                    return(result, null, -1);
                }
                prevIndex = index + 2;
            }
            while (true)
            {
                int  periodIndex = propertyPath.IndexOf('.', prevIndex);
                bool last        = periodIndex == -1;
                int  length      = last
                                        ? propertyPath.Length - prevIndex
                                        : periodIndex - prevIndex;
                var p            = propertyPath.Substring(prevIndex, length);
                int bracketIndex = p.IndexOf('[');
                int indexInList  = -1;
                if (bracketIndex == -1)
                {
                    result = GetProperty(o.GetType(), p);
                }
                else
                {
                    indexInList = int.Parse(p.Substring(bracketIndex + 1, p.Length - bracketIndex - 2));
                    result      = GetProperty(o.GetType(), p.Substring(0, bracketIndex));
                }
                if (result.Info == null)
                {
                    return(result, null, -1);
                }
                if (last)
                {
                    return(result, (IAnimable)o, indexInList);
                }
                else
                {
                    if (indexInList == -1)
                    {
                        o = result.Info.GetValue(o);
                    }
                    else if (o is IList list && indexInList >= list.Count)
                    {
                        return(result, null, -1);
                    }