示例#1
0
 protected void ValueChanged(object sender, INodeChangeEventArgs e)
 {
     if (!notifyChangesOnly || !Equals(e.OldValue, e.NewValue))
     {
         propertyChanged?.Invoke(new[] { PropertyName });
     }
 }
示例#2
0
        private void ChildPartChanged(object sender, [NotNull] INodeChangeEventArgs e)
        {
            switch (e.ChangeType)
            {
            case ContentChangeType.CollectionUpdate:
            case ContentChangeType.ValueChange:
                if (e.OldValue != null)
                {
                    NotifyPartRemoved(GetIdFromChildPart(e.OldValue));
                }
                if (e.NewValue != null)
                {
                    NotifyPartAdded(GetIdFromChildPart(e.NewValue));
                }
                break;

            case ContentChangeType.CollectionAdd:
                NotifyPartAdded(GetIdFromChildPart(e.NewValue));
                break;

            case ContentChangeType.CollectionRemove:
                NotifyPartRemoved(GetIdFromChildPart(e.OldValue));
                break;
            }
        }
示例#3
0
        private void ContentPrepareChange(object sender, [NotNull] INodeChangeEventArgs e)
        {
            var node    = e.Node;
            var visitor = CreateVisitor();

            visitor.Visiting += (node1, path) => UnregisterNode(node1);
            switch (e.ChangeType)
            {
            case ContentChangeType.ValueChange:
            case ContentChangeType.CollectionUpdate:
                // The changed node itself is still valid, we don't want to unregister it
                visitor.SkipRootNode = true;
                visitor.Visit(node);
                // TODO: In case of CollectionUpdate we could probably visit only the target node of the corresponding index
                break;

            case ContentChangeType.CollectionRemove:
                if (node.IsReference && e.OldValue != null)
                {
                    var removedNode = (node as IObjectNode)?.ItemReferences[((ItemChangeEventArgs)e).Index].TargetNode;
                    if (removedNode != null)
                    {
                        // TODO: review this
                        visitor.Visit(removedNode, node as MemberNode);
                    }
                }
                break;
            }
        }
 private void GraphNodeListenerChanged(object sender, INodeChangeEventArgs e)
 {
     if (UpdateSlots())
     {
         UpdateOutgoingLinks();
     }
 }
示例#5
0
        private void RootPartsChanged(object sender, [NotNull] INodeChangeEventArgs e)
        {
            switch (e.ChangeType)
            {
            case ContentChangeType.CollectionAdd:
                NotifyPartAdded(((TAssetPart)e.NewValue).Id);
                break;

            case ContentChangeType.CollectionRemove:
                NotifyPartRemoved(((TAssetPart)e.OldValue).Id);
                break;
            }
        }
 private static void VerifyListenerEvent(INodeChangeEventArgs e, IGraphNode nodeOwner, ContentChangeType type, NodeIndex index, object oldValue, object newValue, bool changeApplied)
 {
     Assert.NotNull(e);
     Assert.NotNull(nodeOwner);
     Assert.Equal(type, e.ChangeType);
     Assert.Equal(nodeOwner, e.Node);
     Assert.Equal(index, (e as ItemChangeEventArgs)?.Index ?? NodeIndex.Empty);
     Assert.Equal(newValue, e.NewValue);
     Assert.Equal(oldValue, e.OldValue);
     if (type == ContentChangeType.ValueChange)
     {
         Assert.Equal(changeApplied ? newValue : oldValue, nodeOwner.Retrieve(index));
     }
 }
示例#7
0
        protected override void ComponentPropertyChanged(object sender, INodeChangeEventArgs e)
        {
            var memberNode = e.Node as IMemberNode;

            if (memberNode == null)
            {
                return;
            }

            if (memberNode.Name == nameof(ParticleMaterialSimple.AlphaCutoff) ||
                memberNode.Name == nameof(ParticleMaterialSimple.SoftEdgeDistance))
            {
                (memberNode.Parent.Retrieve() as ParticleMaterialSimple)?.ForceUpdate();
            }
        }
示例#8
0
        private void ContentFinalizeChange(object sender, [NotNull] INodeChangeEventArgs e)
        {
            var visitor = CreateVisitor();

            visitor.Visiting += (node, path) => RegisterNode(node);
            switch (e.ChangeType)
            {
            case ContentChangeType.ValueChange:
            case ContentChangeType.CollectionUpdate:
                // The changed node itself is still valid, we don't want to re-register it
                visitor.SkipRootNode = true;
                visitor.Visit(e.Node);
                // TODO: In case of CollectionUpdate we could probably visit only the target node of the corresponding index
                break;

            case ContentChangeType.CollectionAdd:
                if (e.Node.IsReference && e.NewValue != null)
                {
                    var        objectNode = (IObjectNode)e.Node;
                    IGraphNode addedNode;
                    NodeIndex  index;
                    var        arg = (ItemChangeEventArgs)e;
                    if (!arg.Index.IsEmpty)
                    {
                        index     = arg.Index;
                        addedNode = objectNode.ItemReferences[arg.Index].TargetNode;
                    }
                    else
                    {
                        // TODO: review this
                        var reference = objectNode.ItemReferences.First(x => x.TargetNode.Retrieve() == e.NewValue);
                        index     = reference.Index;
                        addedNode = reference.TargetNode;
                    }

                    if (addedNode != null && visitor.ShouldVisitTargetItem(objectNode, index))
                    {
                        var path = new GraphNodePath(e.Node);
                        path.PushIndex(index);
                        visitor.Visit(addedNode, e.Node as MemberNode, path);
                    }
                }
                break;
            }
        }
示例#9
0
        protected virtual async Task <bool> PropagatePartReference(IGraphNode gameSideNode, object value, INodeChangeEventArgs e)
        {
            // If the change is an addition or removal of a part in the asset, it shouldn't be handled by the propagator.
            var index = (e as ItemChangeEventArgs)?.Index ?? NodeIndex.Empty;

            if (((AssetCompositeHierarchyPropertyGraph <TAssetPartDesign, TAssetPart>)Owner.Asset.PropertyGraph).IsChildPartReference(e.Node, index))
            {
                // But we should still return that the change correspond to a part reference.
                return(true);
            }
            var assetPart = value as TAssetPart;

            if (assetPart != null)
            {
                var id = new AbsoluteId(Owner.Id.AssetId, assetPart.Id);
                await Editor.Controller.InvokeAsync(() =>
                {
                    var instance = Editor.Controller.FindGameSidePart(id);
                    UpdateGameSideContent(gameSideNode, instance, e.ChangeType, index);
                });

                return(true);
            }
            return(false);
        }
示例#10
0
 private void AssetSideNodeChanged(object sender, INodeChangeEventArgs e)
 {
     propagatorQueue.Post(e);
 }
示例#11
0
 private void AssociatedNodeChanged(object sender, [NotNull] INodeChangeEventArgs e)
 {
     RaiseNodeChanged(e.OldValue, e.ChangeType, (e as ItemChangeEventArgs)?.Index ?? NodeIndex.Empty);
 }
        protected override async Task <bool> PropagatePartReference(IGraphNode gameSideNode, object value, INodeChangeEventArgs e)
        {
            var component = value as EntityComponent;
            // Don't propagate if we're updating the EntityComponentCollection (not a reference),
            // or if we're updating TransformComponent.Children (handled as a part addition/removal)
            var nodeIndex = (e as ItemChangeEventArgs)?.Index ?? NodeIndex.Empty;

            if (component != null && e.Node.Type != typeof(EntityComponentCollection) && !((EntityHierarchyPropertyGraph)Owner.Asset.PropertyGraph).IsChildPartReference(e.Node, nodeIndex))
            {
                var index  = component.Entity.Components.IndexOf(component);
                var partId = new AbsoluteId(Owner.Id.AssetId, component.Entity.Id); // FIXME: what about cross-asset references?
                await Editor.Controller.InvokeAsync(() =>
                {
                    var gameSideEntity    = (Entity)Editor.Controller.FindGameSidePart(partId);
                    var gameSideComponent = gameSideEntity?.Components[index];
                    UpdateGameSideContent(gameSideNode, gameSideComponent, e.ChangeType, nodeIndex);
                });

                return(true);
            }
            return(await base.PropagatePartReference(gameSideNode, value, e));
        }
 protected virtual void ComponentPropertyChanged(object sender, INodeChangeEventArgs e)
 {
     // Do nothing by default.
 }