Exemple #1
0
    private void TileClicked(NodeIndex nodeIndex)
    {
        if (playerMoving)
        {
            return;
        }

        if (player)
        {
            player.desiredEndNodeIndex = nodeIndex;
            NodeIndex playerPos = player.currentNodeIndex;

            NodeState ns = GetTile(player.currentNodeIndex).go.GetComponent <NodeState>();
            if (ns)
            {
                ns.state = NodeState.STATES.BLUE;
            }
            ns = null;

            Tile endTile = GetTile(nodeIndex);
            if (endTile)
            {
                playerWillStopToClean = endTile.type == TileType.SPILL;

                ns = endTile.go.GetComponent <NodeState>();
                if (ns)
                {
                    ns.state = NodeState.STATES.BLUE;
                }
            }
            ns = null;

            timeToFindPath = 0;
            FindPath();
        }
    }
Exemple #2
0
 public void Visit([NotNull] IAssetNode node, NodeIndex index)
 {
     if (index == NodeIndex.Empty)
     {
         // Normal case, no index
         Visit(node);
     }
     else if (node.IsReference)
     {
         // We have an index, and our collection is a collection of reference types, then start visit from the target item
         var target = ((IObjectNode)node).IndexedTarget(index);
         if (target != null)
         {
             Visit(target);
         }
     }
     else if (AssetRegistry.IsContentType(node.Descriptor.GetInnerCollectionType()))
     {
         // We have an index, and our collection is directly a collection of content type. Let's just collect the corresponding item.
         var gameContent = node.GetContent("Game");
         var id          = AttachedReferenceManager.GetAttachedReference(node.Retrieve(index))?.Id ?? AssetId.Empty;
         CollectContentReference(id, gameContent, index);
     }
 }
Exemple #3
0
        /// <inheritdoc/>
        protected override void ExecuteSync(INodePresenter nodePresenter, object parameter, object preExecuteResult)
        {
            var assetNodePresenter   = nodePresenter as IAssetNodePresenter;
            var dictionaryDescriptor = (DictionaryDescriptor)nodePresenter.Descriptor;
            var value = nodePresenter.Value;

            NodeIndex?newKey;

            if (parameter != null && TypeDescriptor.GetConverter(dictionaryDescriptor.KeyType).CanConvertFrom(parameter.GetType()))
            {
                newKey = GenerateGenericKey(value, dictionaryDescriptor, parameter);
            }
            else if (dictionaryDescriptor.KeyType.IsEnum)
            {
                newKey = new NodeIndex(parameter);
            }
            else
            {
                newKey = new NodeIndex(Activator.CreateInstance(dictionaryDescriptor.KeyType));
            }

            if (newKey != null)
            {
                if (!dictionaryDescriptor.ContainsKey(nodePresenter.Value, newKey.Value.Value))
                {
                    var newItem  = dictionaryDescriptor.ValueType.Default();
                    var instance = CreateInstance(dictionaryDescriptor.ValueType);
                    if (!AddNewItemCommand.IsReferenceType(dictionaryDescriptor.ValueType) && (assetNodePresenter == null || !assetNodePresenter.IsObjectReference(instance)))
                    {
                        newItem = instance;
                    }

                    nodePresenter.AddItem(newItem, newKey.Value);
                }
            }
        }
Exemple #4
0
 public void SetAddress(NodeIndex nodeIndex, Address nodeAddress)
 {
     Debug.Assert(m_nodeAddresses[(int)nodeIndex] == 0, "Calling SetAddress twice for node index " + nodeIndex);
     m_nodeAddresses[(int)nodeIndex] = nodeAddress;
 }
Exemple #5
0
 public MemoryNodeBuilder(MemoryGraph graph, string typeName, string moduleName = null, NodeIndex nodeIndex = NodeIndex.Invalid)
 {
     Debug.Assert(typeName != null);
     m_graph  = graph;
     TypeName = typeName;
     Index    = nodeIndex;
     if (Index == NodeIndex.Invalid)
     {
         Index = m_graph.CreateNode();
     }
     Debug.Assert(m_graph.m_nodes[(int)Index] == m_graph.m_undefinedObjDef, "SetNode cannot be called on the nodeIndex passed");
     ModuleName        = moduleName;
     m_mutableChildren = new List <MemoryNodeBuilder>();
     m_typeIndex       = NodeTypeIndex.Invalid;
 }
        protected override void OnAssetPropertyChanged(string propertyName, IGraphNode node, NodeIndex index, object oldValue, object newValue)
        {
            base.OnAssetPropertyChanged(propertyName, node, index, oldValue, newValue);

            var memberNode = node as IMemberNode;

            if (memberNode != null && !PropertyGraph.UpdatingPropertyFromBase && !UndoRedoService.UndoRedoInProgress)
            {
                // If Dither changed, clamp Quality to the new valid range
                // Note: other part of the behavior is in GraphicsCompositorAssetNodeUpdater (hide Quality if Dither set to None)
                // TODO: This should be moved to FXAA-specific code to be plugin-ready (asset property changed works only at asset level)
                var ownerNode = memberNode.Parent;
                if (typeof(FXAAEffect).IsAssignableFrom(ownerNode.Type) && propertyName == nameof(FXAAEffect.Dither))
                {
                    var qualityNode = ownerNode[nameof(FXAAEffect.Quality)];
                    var dither      = (FXAAEffect.DitherType)memberNode.Retrieve();

                    // Get new valid quality range
                    var(minQuality, maxQuality) = FXAAEffect.GetQualityRange(dither);

                    // Clamp and set it back (if different)
                    var quality = (int)qualityNode.Retrieve();
                    if (quality < minQuality)
                    {
                        qualityNode.Update(minQuality);
                    }
                    else if (quality > maxQuality)
                    {
                        qualityNode.Update(maxQuality);
                    }
                }
            }
        }
Exemple #7
0
        protected static void UpdateGameSideContent(IGraphNode gameSideNode, object value, ContentChangeType changeType, NodeIndex index)
        {
            switch (changeType)
            {
            case ContentChangeType.ValueChange:
                ((IMemberNode)gameSideNode).Update(value);
                break;

            case ContentChangeType.CollectionUpdate:
                ((IObjectNode)gameSideNode).Update(value, index);
                break;

            case ContentChangeType.CollectionAdd:
                ((IObjectNode)gameSideNode).Add(value, index);
                break;

            case ContentChangeType.CollectionRemove:
                var item = gameSideNode.Retrieve(index);
                ((IObjectNode)gameSideNode).Remove(item, index);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #8
0
 public virtual bool IsTargetItemObjectReference(IObjectNode collection, NodeIndex itemIndex, object value)
 {
     return(false);
 }
 private static YamlAssetMetadata <T> RemoveFirstIndexInYamlPath <T>([CanBeNull] YamlAssetMetadata <T> metadata, NodeIndex index)
 {
     if (metadata != null)
     {
         // If we had an index we need to remove it from our override paths
         if (index != NodeIndex.Empty)
         {
             var fixedMetadata = new YamlAssetMetadata <T>();
             foreach (var entry in metadata)
             {
                 // We're filling a new dictionary because we are destroying hash codes by muting the keys
                 var newPath = entry.Key.Elements.Count > 0 ? new YamlAssetPath(entry.Key.Elements.Skip(1)) : entry.Key;
                 fixedMetadata.Set(newPath, entry.Value);
             }
             metadata = fixedMetadata;
         }
     }
     return(metadata);
 }
        /// <summary>
        ///  Each of the query words must be found in at least one field ∀w ∃f
        /// </summary>
        public SearchResult IsMatch(BaseNode node)
        {
            SearchResult result = null;

            if (node == null)
            {
                return(null);
            }

            if (NodeIndex > -1)
            {
                if (node is TimedNode timedNode && timedNode.Index == NodeIndex)
                {
                    result = new SearchResult(node);
                    var prefix = "Node id: ";
                    result.AddMatch(prefix + NodeIndex.ToString(), NodeIndex.ToString());
                    return(result);
                }
            }

            var searchFields = PopulateSearchFields(node);

            if (TypeKeyword != null)
            {
                // zeroth field is always the type
                if (string.Equals(TypeKeyword, searchFields[0], StringComparison.OrdinalIgnoreCase) ||
                    // special case for types derived from Task, $task should still work
                    (TypeKeyword == "task" && searchFields.Count > 1 && searchFields[1] == "Task"))
                {
                    // this node is of the type that we need, search other fields
                    if (result == null)
                    {
                        result = new SearchResult(node, IncludeDuration, IncludeStart, IncludeEnd);
                    }

                    result.AddMatchByNodeType();
                }
                else
                {
                    return(null);
                }
            }

            bool nameMatched  = false;
            bool valueMatched = false;

            for (int i = 0; i < Words.Count; i++)
            {
                bool anyFieldMatched = false;
                var  word            = Words[i];

                for (int j = 0; j < searchFields.Count; j++)
                {
                    var field = searchFields[j];

                    if (!MatchesInStrings[i].Contains(field))
                    {
                        // no point looking here, we know this string doesn't match anything
                        continue;
                    }

                    if (result == null)
                    {
                        result = new SearchResult(node, IncludeDuration, IncludeStart, IncludeEnd);
                    }

                    // if matched on the type of the node (always field 0), special case it
                    if (j == 0)
                    {
                        result.AddMatchByNodeType();
                    }
                    else
                    {
                        string fullText = field;
                        var    named    = node as NameValueNode;

                        // NameValueNode is special case have to check in which field to search
                        if (named != null && (nameToSearch != null || valueToSearch != null))
                        {
                            if (j == 1 && word == nameToSearch)
                            {
                                result.AddMatch(fullText, word, addAtBeginning: true);
                                nameMatched     = true;
                                anyFieldMatched = true;
                                break;
                            }

                            if (j == 2 && word == valueToSearch)
                            {
                                result.AddMatch(fullText, word);
                                valueMatched    = true;
                                anyFieldMatched = true;
                                break;
                            }
                        }
                        else
                        {
                            result.AddMatch(fullText, word);
                            anyFieldMatched = true;
                            break;
                        }
                    }
                }

                if (!anyFieldMatched)
                {
                    return(null);
                }
            }

            if (result == null)
            {
                return(null);
            }

            if (nameToSearch != null && valueToSearch != null && (!nameMatched || !valueMatched))
            {
                return(null);
            }

            bool showResult = IncludeMatchers.Count == 0;

            foreach (NodeQueryMatcher matcher in IncludeMatchers)
            {
                if (!showResult)
                {
                    showResult = IsUnder(matcher, result);
                }
            }

            if (!showResult)
            {
                return(null);
            }

            foreach (NodeQueryMatcher matcher in ExcludeMatchers)
            {
                if (IsUnder(matcher, result))
                {
                    return(null);
                }
            }

            return(result);
        }
Exemple #11
0
    private void _Render()
    {
        if (0 == _gridTransforms.Count) {
            return;
        }

        if (null == AStar.gridMap || 0 == AStar.gridMap.Count || _wasRender) {
            //_RayCastNode();
            return;
        }

        _wasRender = true;
        //movementArrayIndex = 0;
        // Set suitable Materials for All GRID_MAP's NODES
        movementArray.Clear();
        for (int i = 0; i < AStar.gridMap.Count; i++) {
            for (int j = 0; j < AStar.gridMap[i].Count; j++) {
                // if Not WalkAble NODE [Set Red Material]
                if (false == AStar.gridMap[i][j]) {
                    //_SetMaterial(_gridTransforms[i][j].renderer, redMat);
                    _nodeStatesGrid[i][j].HighlightTile( "red" );

                } else if ( // else if START or END NODE [Set Blue Material]
                    AStar.startIndex.i == i && AStar.startIndex.j == j ||
                    AStar.endIndex.i == i && AStar.endIndex.j == j
                ) {
                    _nodeStatesGrid[i][j].HighlightTile( "blue" );
                    if ( _nodeStatesGrid[i][j] != null){
                            Vector3 tileVector = _nodeStatesGrid[i][j].transform.position;
                            //tileVector = new Vector3(tileVector.x , tileVector.y , tileVector.z );
                            //movementArray[ movementArray.Length ] = tileVector;
                            //movementArray.Add ( tileVector );

                    }
                    //_SetMaterial(_gridTransforms[i][j].renderer, blueMat);
                } else {
                    _tmpNodeIndex = new NodeIndex();
                    _tmpNodeIndex.i = i;
                    _tmpNodeIndex.j = j;
                    // if PATH NODE [Set Green Material] else [Set White Material]
                    if (AStar.ContainsNodeIndex(AStar.pathNodes, _tmpNodeIndex)) {
                        _nodeStatesGrid[i][j].HighlightTile( "green" );
                        if ( _nodeStatesGrid[i][j] != null){
                            Vector3 tileVector = _nodeStatesGrid[i][j].transform.position;
                            //tileVector = new Vector3(tileVector.x , tileVector.y , tileVector.z );
                            //movementArray[ movementArray.Length ] = tileVector;
                            movementArray.Add ( tileVector );
                        }

                        //Debug.Log("HI");
                        //_SetMaterial(_gridTransforms[i][j].renderer, greenMat);
                    } else {
                        //_SetMaterial(_gridTransforms[i][j].renderer, whiteMat);
                        _nodeStatesGrid[i][j].HighlightTile( "white" );
                    }
                }
            }
        }
    }
Exemple #12
0
 private Node Postfix(Node node, bool allowPostfixInvocation)
 {
     if (node == null || !TokensRemain)
         return node;
     // handle { i+ = 1 } assign operators
     if (HasNextToken && Current.type == OPERATOR && Next.type == ASSIGN)
     {
         string op = Current.image;
         Advance(); Advance();
         var right = Expression();
         if (right == null)
         {
             // TODO error
         }
         return new NodeAssign(node, new NodeInfix(node, right, op));
     }
     switch (Current.type)
     {
         case ASSIGN: Advance(); return new NodeAssign(node, Expression());
         case OPEN_BRACE:
             if (Location.line != node.EndLine || !allowPostfixInvocation)
                 break;
             Advance();
             List<Node> args;
             if (!Check(CLOSE_BRACE))
                 args = CommaExpressions();
             else args = new List<Node>();
             Expect(CLOSE_BRACE, "Expected a close brace (')') to end the function argument list.");
             return Postfix(new NodeInvoke(node, args), allowPostfixInvocation);
         case OPEN_SQUARE_BRACE:
             if (Location.line != node.EndLine)
                 break;
             Advance();
             if (Check(OPERATOR) && HasNextToken && Next.type == CLOSE_SQUARE_BRACE)
             {
                 node = new NodeOperatorIndex(node, Current.image);
                 Advance();
             }
             else if (Check(CLOSE_SQUARE_BRACE))
             {
                 Advance();
                 log.Error(Location, "At least one argument is needed to index an object.");
                 return node;
             }
             else node = new NodeIndex(node, CommaExpressions());
             Expect(CLOSE_SQUARE_BRACE, "Expected a close brace (']') to end the operator index.");
             return Postfix(node, allowPostfixInvocation);
         case DOT:
             Advance();
             // TODO do other checks, such as infix/prefix/as
             // for now, just check identifier indexing.
             string ident;
             ExpectIdentifier(out ident, "Identifier expected for field indexing.");
             return Postfix(new NodeFieldIndex(node, ident), allowPostfixInvocation);
         case AS:
             Advance();
             if (!TokensRemain)
             {
                 log.Error(tokens[-1].location, "Expected expression for 'as' cast, but the end of the file was reached.");
                 break;
             }
             var type = PrimaryExpression();
             if (type == null)
             {
                 log.Error(tokens[-1].location, "Expected expression for 'as' cast.");
                 break;
             }
             var a = new NodeAs(node, type);
             return a;
     }
     return node;
 }
Exemple #13
0
    private static void CheckAdjacents( bool diag_ )
    {
        nodeIndexes.Clear();
        removeNodeIndexes.Clear();

        if (null == currentNode) {
            return;
        }

        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i - 1; // Up Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j;		// Current Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        if ( diag_ == true ){
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i - 1; // Up Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j + 1;	// Right Column Adjacent Node
        nodeIndexes.Add(nodeIndex);

        }
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i; 	// Current Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j + 1;	// Right Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        if ( diag_ == true ){
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i + 1; // Down Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j + 1;	// Right Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        }
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i + 1; // Down Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j;		// Current Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        if ( diag_ == true ){
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i + 1; // Down Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j - 1;	// Left Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        }
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i; 	// Current Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j - 1;	// Left Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        if ( diag_ == true ){
        nodeIndex = new NodeIndex();
        nodeIndex.i = currentNode.nodeIndex.i - 1; // Up Row Adjacent Node
        nodeIndex.j = currentNode.nodeIndex.j - 1;	// Left Column Adjacent Node
        nodeIndexes.Add(nodeIndex);
        }

        foreach (NodeIndex n in nodeIndexes) {
            if (
                n.i < 0 || n.j < 0 ||
                n.i >= gridMap.Count || n.j >= gridMap[0].Count ||
                false == gridMap[n.i][n.j] ||
                ContainsNodeIndex(openList, n) || ContainsNodeIndex(closedList, n)
            ) {
                removeNodeIndexes.Add(n);
            }
        }

        foreach (NodeIndex n in removeNodeIndexes) {
            nodeIndexes.Remove(n);
        }

        foreach (NodeIndex indx in nodeIndexes) {
            node = GetNodeByIndex(openList, indx);
            if (null == node) {
                // ADD New Node in Open List
                node = new Node();
                node.nodeIndex.i = indx.i;
                node.nodeIndex.j = indx.j;
                openList.Add(node);

                if (
                    node.nodeIndex.i != currentNode.nodeIndex.i &&
                    node.nodeIndex.j != currentNode.nodeIndex.j
                ) {
                    node.G = 14 + currentNode.G;
                } else {
                    node.G = 10 + currentNode.G;
                }

                node.H = CalcHeuristicPrice(node);
                node.F = node.G + node.H;
            } else {
                if (
                    node.nodeIndex.i != currentNode.nodeIndex.i &&
                    node.nodeIndex.j != currentNode.nodeIndex.j
                ) {
                    if (node.G > 14 + currentNode.G) {
                        node.G = 14 + currentNode.G;
                        node.F = node.G + node.H;
                        node.parent = currentNode;
                    }
                } else {
                    if (node.G > 10 + currentNode.G) {
                        node.G = 10 + currentNode.G;
                        node.F = node.G + node.H;
                        node.parent = currentNode;
                    }
                }
            }

            // ADD Parent Node
            node.parent = currentNode;
        }
    }
        protected virtual void CollectContentReference(AssetId contentId, IGraphNode content, NodeIndex index)
        {
            if (contentId == AssetId.Empty)
            {
                return;
            }

            ContentReferences.Add(new ContentReferenceAccessor(contentId, content, index));
        }
Exemple #15
0
 void ASTVisitor.Accept(NodeIndex value)
 {
     Accept(value);
 }
 public AssetContentValueChangeOperation(IAssetNode node, ContentChangeType changeType, NodeIndex index, object oldValue, object newValue, OverrideType previousOverride, OverrideType newOverride, ItemId itemId, IEnumerable <IDirtiable> dirtiables)
     : base(node, changeType, index, oldValue, newValue, dirtiables)
 {
     this.previousOverride = previousOverride;
     this.itemId           = itemId;
     this.newOverride      = newOverride;
 }
Exemple #17
0
 internal void Accept(NodeIndex index)
 {
     index.target.Visit(this);
     index.args.ForEach(arg => arg.Visit(this));
     builder.currentLineNumber = index.target.EndLine;
     builder.OpILoad((uint)index.args.Count);
 }
Exemple #18
0
    public static Node GetNodeByIndex(List<Node> list, NodeIndex indx)
    {
        if (null == list || null == indx) return null;

        foreach (Node n in list) {
            if (n.nodeIndex.i == indx.i && n.nodeIndex.j == indx.j) {
                return n;
            }
        }

        return null;
    }
Exemple #19
0
 private void RaiseNodeChanging(object newValue, ContentChangeType changeType, NodeIndex index)
 {
     if (ShouldRaiseEvent(changeType, index))
     {
         RaiseValueChanging(newValue);
     }
 }
 /// <inheritdoc/>
 protected override bool ShouldVisitTargetItem(IObjectNode collectionNode, NodeIndex index)
 {
     return(base.ShouldVisitTargetItem(collectionNode, index) && !PropertyGraphDefinition.IsTargetItemObjectReference(collectionNode, index, collectionNode.Retrieve(index)));
 }
Exemple #21
0
        // TODO: replace targetNode & index arguments by a NodeAccessor
        private void Paste([NotNull] IPasteItem pasteResultItem, IGraphNode targetNode, NodeIndex index, bool replace)
        {
            if (pasteResultItem?.Data == null)
            {
                throw new ArgumentNullException(nameof(pasteResultItem));
            }
            if (targetNode == null)
            {
                throw new ArgumentNullException(nameof(targetNode));
            }

            var copiedData           = pasteResultItem.Data;
            var copiedDataType       = copiedData.GetType();
            var copiedDataDescriptor = TypeDescriptorFactory.Default.Find(copiedDataType);
            var memberNode           = targetNode as IMemberNode;

            // We're pasting in a node that is not a collection (nor a dictionary), let's just do a member update
            if (!CollectionDescriptor.IsCollection(targetNode.Type))
            {
                if (CanUpdateMember(memberNode, copiedData))
                {
                    UpdateMember(memberNode, copiedData);
                }
                return;
            }

            // Check if target collection/dictionary is null.
            if (memberNode != null && memberNode.Target == null)
            {
                // Check if the type has a public constructor with no arguments
                if (targetNode.Type.GetConstructor(Type.EmptyTypes) != null)
                {
                    // Instantiate a new collection (based on node type)
                    memberNode.Update(Activator.CreateInstance(targetNode.Type));
                }
            }

            var collectionNode = memberNode != null ? memberNode.Target : (IObjectNode)targetNode;

            // The collection/dictionary is null and we couldn't construct it, let's stop here
            if (collectionNode == null)
            {
                return;
            }

            // We're pasting in a dictionary. In this case the only accepted input is a (compatible) dictionary
            if (copiedDataDescriptor.Category == DescriptorCategory.Dictionary && DictionaryDescriptor.IsDictionary(targetNode.Type))
            {
                var copiedDataDictionaryDescriptor = (DictionaryDescriptor)copiedDataDescriptor;
                var existingKeys = collectionNode.Indices.ToList();
                if (replace)
                {
                    var keys = ((DictionaryDescriptor)collectionNode.Descriptor).GetKeys(collectionNode.Retrieve()).Cast <object>().ToList();
                    if (index.IsEmpty)
                    {
                        // If this operation is a replace of the whole dictionary, let's first clear it
                        foreach (var key in keys)
                        {
                            var itemIndex = new NodeIndex(key);
                            if (CanRemoveItem(collectionNode, itemIndex))
                            {
                                var itemToRemove = targetNode.Retrieve(itemIndex);
                                collectionNode.Remove(itemToRemove, itemIndex);
                            }
                        }
                    }
                    else
                    {
                        // Otherwise, just remove the corresponding item
                        if (CanRemoveItem(collectionNode, index))
                        {
                            var itemToRemove = targetNode.Retrieve(index);
                            collectionNode.Remove(itemToRemove, index);
                        }
                    }
                }
                foreach (var kv in copiedDataDictionaryDescriptor.GetEnumerator(copiedData))
                {
                    var itemIndex = new NodeIndex(kv.Key);
                    if (existingKeys.Contains(itemIndex))
                    {
                        // Replace if the key already exists
                        if (CanReplaceItem(collectionNode, itemIndex, kv.Value))
                        {
                            ReplaceItem(collectionNode, itemIndex, kv.Value);
                        }
                    }
                    else
                    {
                        // Add if the key does not exist
                        if (CanInsertItem(collectionNode, itemIndex, kv.Value))
                        {
                            InsertItem(collectionNode, itemIndex, kv.Value);
                        }
                    }
                }
            }
            else if (targetNode.Descriptor.Category == DescriptorCategory.Collection)
            {
                var targetCollectionDescriptor = (CollectionDescriptor)targetNode.Descriptor;
                if (replace)
                {
                    // No index, we're replacing the whole collection
                    if (index.IsEmpty)
                    {
                        // First clear the collection
                        var count = targetCollectionDescriptor.GetCollectionCount(targetNode.Retrieve());
                        for (var j = count - 1; j >= 0; j--)
                        {
                            var itemIndex = new NodeIndex(j);
                            if (CanRemoveItem(collectionNode, itemIndex))
                            {
                                var itemToRemove = targetNode.Retrieve(itemIndex);
                                collectionNode.Remove(itemToRemove, itemIndex);
                            }
                        }

                        // Then add the new items
                        var i = 0;
                        foreach (var item in EnumerateItems(copiedData, copiedDataDescriptor))
                        {
                            var itemIndex = new NodeIndex(i);
                            if (CanInsertItem(collectionNode, itemIndex, item))
                            {
                                InsertItem(collectionNode, itemIndex, item);
                                i++;
                            }
                        }
                    }
                    else
                    {
                        // We're replacing a single item with a given index...
                        var  startIndex        = index.Int;
                        var  i                 = 0;
                        bool firstItemReplaced = false;
                        foreach (var item in EnumerateItems(copiedData, copiedDataDescriptor))
                        {
                            var itemIndex = new NodeIndex(startIndex + i);
                            if (!firstItemReplaced)
                            {
                                // We replace the first item.
                                if (CanReplaceItem(collectionNode, itemIndex, item))
                                {
                                    ReplaceItem(collectionNode, itemIndex, item);
                                    firstItemReplaced = true;
                                    i++;
                                }
                            }
                            else if (CanInsertItem(collectionNode, itemIndex, item))
                            {
                                // We insert the following items that have no pre-existing counter-part.
                                InsertItem(collectionNode, itemIndex, item);
                                i++;
                            }
                        }
                    }
                }
                else
                {
                    // No index, we're replacing the whole collection
                    if (index.IsEmpty)
                    {
                        // Add the new items
                        var i = targetCollectionDescriptor.GetCollectionCount(targetNode.Retrieve());
                        foreach (var item in EnumerateItems(copiedData, copiedDataDescriptor))
                        {
                            var itemIndex = new NodeIndex(i);
                            if (CanInsertItem(collectionNode, itemIndex, item))
                            {
                                InsertItem(collectionNode, itemIndex, item);
                                i++;
                            }
                        }
                    }
                    else
                    {
                        // Handling non-replacing paste
                        var i = index.Int;
                        foreach (var item in EnumerateItems(copiedData, copiedDataDescriptor))
                        {
                            // We're pasting a collection into the collection, let's add all items at the given index if provided or at the end of the collection.
                            var itemIndex = new NodeIndex(i);
                            if (CanInsertItem(collectionNode, itemIndex, item))
                            {
                                InsertItem(collectionNode, itemIndex, item);
                                i++;
                            }
                        }
                    }
                }
            }
        }
Exemple #22
0
        private static object RetrieveValue(IGraphNode node, object value, ContentChangeType changeType, NodeIndex index)
        {
            switch (changeType)
            {
            case ContentChangeType.ValueChange:
                return(node.Retrieve());

            case ContentChangeType.CollectionUpdate:
                return(node.Retrieve(index));

            case ContentChangeType.CollectionAdd:
            case ContentChangeType.CollectionRemove:
                return(value);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #23
0
 protected virtual bool CanRemoveItem(IObjectNode collection, NodeIndex index)
 {
     return(true);
 }
Exemple #24
0
        private async Task UpdateGameSideReference([NotNull] AssetCompositeEditorViewModel editor, [NotNull] IGraphNode gameSideNode, ContentChangeType changeType, object oldValue, object newValue, NodeIndex index)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }

            if (!AssetRegistry.IsContentType(gameSideNode.Descriptor.GetInnerCollectionType()))
            {
                return;
            }

            // Grab the old referenced object if it's not null
            AttachedReference reference = null;

            if (!ReferenceEquals(oldValue, null))
            {
                reference = AttachedReferenceManager.GetAttachedReference(oldValue);
            }

            // Switch to game thread to actually update objects
            await editor.Controller.InvokeTask(() =>
            {
                // For references, push null instead of the real value, the editor asset loader will set the actual value later
                switch (changeType)
                {
                case ContentChangeType.ValueChange:
                    ((IMemberNode)gameSideNode).Update(null);
                    break;

                case ContentChangeType.CollectionUpdate:
                    ((IObjectNode)gameSideNode).Update(null, index);
                    break;

                case ContentChangeType.CollectionAdd:
                    ((IObjectNode)gameSideNode).Add(null, index);
                    break;

                case ContentChangeType.CollectionRemove:
                    var oldValueGameSide = gameSideNode.Retrieve(index);
                    ((IObjectNode)gameSideNode).Remove(oldValueGameSide, index);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(changeType), changeType, null);
                }

                if (oldValue == newValue)
                {
                    return(Task.CompletedTask);
                }

                // Unregister the previous value
                if (reference != null)
                {
                    return(editor.Controller.Loader.Manager.ClearContentReference(Owner.Id, reference.Id, gameSideNode, index));
                }
                return(Task.CompletedTask);
            });
        }
Exemple #25
0
 protected virtual bool CanInsertItem(IObjectNode collection, NodeIndex index, object newItem)
 {
     return(true);
 }
        public override void ReadData(ESPReader reader, long dataEnd)
        {
            while (reader.BaseStream.Position < dataEnd)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "EDID":
                    if (EditorID == null)
                    {
                        EditorID = new SimpleSubrecord <String>();
                    }

                    EditorID.ReadBinary(reader);
                    break;

                case "OBND":
                    if (ObjectBounds == null)
                    {
                        ObjectBounds = new ObjectBounds();
                    }

                    ObjectBounds.ReadBinary(reader);
                    break;

                case "MODL":
                    if (Model == null)
                    {
                        Model = new Model();
                    }

                    Model.ReadBinary(reader);
                    break;

                case "DATA":
                    if (NodeIndex == null)
                    {
                        NodeIndex = new SimpleSubrecord <Int32>();
                    }

                    NodeIndex.ReadBinary(reader);
                    break;

                case "SNAM":
                    if (Sound == null)
                    {
                        Sound = new RecordReference();
                    }

                    Sound.ReadBinary(reader);
                    break;

                case "DNAM":
                    if (Data == null)
                    {
                        Data = new AddonNodeData();
                    }

                    Data.ReadBinary(reader);
                    break;

                default:
                    throw new Exception();
                }
            }
        }
Exemple #27
0
 protected virtual void ReplaceItem(IObjectNode collection, NodeIndex index, object newItem)
 {
     collection.Update(newItem, index);
 }
Exemple #28
0
 public void AddChild(NodeIndex child)
 {
     m_unmutableChildren.Add(child);
 }
Exemple #29
0
 protected virtual void InsertItem(IObjectNode collection, NodeIndex index, object newItem)
 {
     collection.Add(newItem, index);
 }
Exemple #30
0
    /// <summary>
    /// Reads the Nodes Element
    /// </summary>
    private static void ReadNodesFromXml(XmlReader reader, MemoryGraph graph)
    {
        Debug.Assert(reader.NodeType == XmlNodeType.Element);
        var inputDepth = reader.Depth;

        reader.Read();      // Advance to children

        var children    = new GrowableArray <NodeIndex>(1000);
        var typeStorage = graph.AllocTypeNodeStorage();

        while (inputDepth < reader.Depth)
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "Node":
                {
                    NodeIndex     readNodeIndex = (NodeIndex)FetchInt(reader, "Index", -1);
                    NodeTypeIndex typeIndex     = (NodeTypeIndex)FetchInt(reader, "TypeIndex", -1);
                    int           size          = FetchInt(reader, "Size");

                    if (readNodeIndex == NodeIndex.Invalid)
                    {
                        throw new ApplicationException("Node element does not have a Index attribute.");
                    }

                    if (typeIndex == NodeTypeIndex.Invalid)
                    {
                        throw new ApplicationException("Node element does not have a TypeIndex attribute.");
                    }

                    // TODO FIX NOW very inefficient.   Use ReadValueChunk and FastStream to make more efficient.
                    children.Clear();
                    var body = reader.ReadElementContentAsString();
                    foreach (var num in Regex.Split(body, @"\s+"))
                    {
                        if (num.Length > 0)
                        {
                            children.Add((NodeIndex)int.Parse(num));
                        }
                    }

                    if (size == 0)
                    {
                        size = graph.GetType(typeIndex, typeStorage).Size;
                    }

                    // TODO should probably just reserve node index 0 to be an undefined object?
                    NodeIndex nodeIndex = 0;
                    if (readNodeIndex != 0)
                    {
                        nodeIndex = graph.CreateNode();
                    }

                    if (readNodeIndex != nodeIndex)
                    {
                        throw new ApplicationException("Node Indexes do not start at 0 or 1 and increase consecutively.");
                    }

                    graph.SetNode(nodeIndex, typeIndex, size, children);
                }
                break;

                default:
                    Debug.WriteLine("Skipping unknown element {0}", reader.Name);
                    reader.Skip();
                    break;
                }
            }
            else if (!reader.Read())
            {
                break;
            }
        }
    }
Exemple #31
0
 public abstract bool IsChildPartReference(IGraphNode node, NodeIndex index);
 public ContentReferenceAccessor(AssetId contentId, IGraphNode node, NodeIndex index)
 {
     ContentId = contentId;
     Node      = node;
     Index     = index;
 }
Exemple #33
0
    public IEnumerator MapSurroundings(Direction facingDirection)
    {
        //Get the results from the front sensors
        CollisionType[] sensorsFrontResults = sensorsFront.GetIsPathFree();

        //Get the results from the left sensors
        CollisionType[] sensorsLeftResults = sensorsLeft.GetIsPathFree();

        //Get the results from the right sensors
        CollisionType[] sensorsRightResults = sensorsRight.GetIsPathFree();

        NodeIndex previousNodeIndex = null;


        previousNodeIndex = nodeTable.GetCurrentNodeIndex();
        for (int i = 0; i < sensorsFrontResults.Length; i++)
        {
            if (sensorsFrontResults[i] == CollisionType.None)
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    nodesConnection = Direction.Front;
                    newNodeIndex    = GetNodeIndexUp(i);
                    break;

                case Direction.Left:
                    nodesConnection = Direction.Left;
                    newNodeIndex    = GetNodeIndexLeft(i);
                    break;

                case Direction.Right:
                    nodesConnection = Direction.Right;
                    newNodeIndex    = GetNodeIndexRight(i);
                    break;

                case Direction.Back:
                    nodesConnection = Direction.Back;
                    newNodeIndex    = GetNodeIndexDown(i);
                    break;
                }

                nodeTable.NewAddNode(newNodeIndex, previousNodeIndex, nodesConnection);
                previousNodeIndex = newNodeIndex;
            }
            else if (sensorsFrontResults[i] == CollisionType.Objective)
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    nodesConnection = Direction.Front;
                    newNodeIndex    = GetNodeIndexUp(i);
                    break;

                case Direction.Left:
                    nodesConnection = Direction.Left;
                    newNodeIndex    = GetNodeIndexLeft(i);
                    break;

                case Direction.Right:
                    nodesConnection = Direction.Right;
                    newNodeIndex    = GetNodeIndexRight(i);
                    break;

                case Direction.Back:
                    nodesConnection = Direction.Back;
                    newNodeIndex    = GetNodeIndexDown(i);
                    break;
                }
                nodeTable.NewAddNode(newNodeIndex, previousNodeIndex, nodesConnection, true);
                previousNodeIndex = newNodeIndex;
            }
            else
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    nodesConnection = Direction.Front;
                    newNodeIndex    = GetNodeIndexUp(i);
                    break;

                case Direction.Left:
                    nodesConnection = Direction.Left;
                    newNodeIndex    = GetNodeIndexLeft(i);
                    break;

                case Direction.Right:
                    nodesConnection = Direction.Right;
                    newNodeIndex    = GetNodeIndexRight(i);
                    break;

                case Direction.Back:
                    nodesConnection = Direction.Back;
                    newNodeIndex    = GetNodeIndexDown(i);
                    break;
                }

                nodeTable.AddNodeNoConnection(newNodeIndex, previousNodeIndex, nodesConnection);
                break;
            }
        }

        previousNodeIndex = nodeTable.GetCurrentNodeIndex();
        for (int i = 0; i < sensorsLeftResults.Length; i++)
        {
            if (sensorsLeftResults[i] == CollisionType.None)
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    newNodeIndex    = GetNodeIndexLeft(i);
                    nodesConnection = Direction.Left;
                    break;

                case Direction.Left:
                    newNodeIndex    = GetNodeIndexDown(i);
                    nodesConnection = Direction.Back;
                    break;

                case Direction.Right:
                    newNodeIndex    = GetNodeIndexUp(i);
                    nodesConnection = Direction.Front;
                    break;

                case Direction.Back:
                    newNodeIndex    = GetNodeIndexRight(i);
                    nodesConnection = Direction.Right;
                    break;
                }

                nodeTable.NewAddNode(newNodeIndex, previousNodeIndex, nodesConnection);
                previousNodeIndex = newNodeIndex;
            }
            else
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    newNodeIndex    = GetNodeIndexLeft(i);
                    nodesConnection = Direction.Left;
                    break;

                case Direction.Left:
                    newNodeIndex    = GetNodeIndexDown(i);
                    nodesConnection = Direction.Back;
                    break;

                case Direction.Right:
                    newNodeIndex    = GetNodeIndexUp(i);
                    nodesConnection = Direction.Front;
                    break;

                case Direction.Back:
                    newNodeIndex    = GetNodeIndexRight(i);
                    nodesConnection = Direction.Right;
                    break;
                }

                nodeTable.AddNodeNoConnection(newNodeIndex, previousNodeIndex, nodesConnection);
                break;
            }
        }

        previousNodeIndex = nodeTable.GetCurrentNodeIndex();
        for (int i = 0; i < sensorsRightResults.Length; i++)
        {
            if (sensorsRightResults[i] == CollisionType.None)
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    newNodeIndex    = GetNodeIndexRight(i);
                    nodesConnection = Direction.Right;
                    break;

                case Direction.Left:
                    newNodeIndex    = GetNodeIndexUp(i);
                    nodesConnection = Direction.Front;
                    break;

                case Direction.Right:
                    newNodeIndex    = GetNodeIndexDown(i);
                    nodesConnection = Direction.Back;
                    break;

                case Direction.Back:
                    newNodeIndex    = GetNodeIndexLeft(i);
                    nodesConnection = Direction.Left;
                    break;
                }

                nodeTable.NewAddNode(newNodeIndex, previousNodeIndex, nodesConnection);
                previousNodeIndex = newNodeIndex;
            }
            else
            {
                NodeIndex newNodeIndex    = null;
                Direction nodesConnection = Direction.Front;

                switch (facingDirection)
                {
                case Direction.Front:
                    newNodeIndex    = GetNodeIndexRight(i);
                    nodesConnection = Direction.Right;
                    break;

                case Direction.Left:
                    newNodeIndex    = GetNodeIndexUp(i);
                    nodesConnection = Direction.Front;
                    break;

                case Direction.Right:
                    newNodeIndex    = GetNodeIndexDown(i);
                    nodesConnection = Direction.Back;
                    break;

                case Direction.Back:
                    newNodeIndex    = GetNodeIndexLeft(i);
                    nodesConnection = Direction.Left;
                    break;
                }

                nodeTable.AddNodeNoConnection(newNodeIndex, previousNodeIndex, nodesConnection);
                break;
            }
        }
        yield return(null);
    }
        private void VisitNode(MemoryNode currentNode)
        {
            MemoryNode oldMemNode = currentNode;

            // Get the generation for the current node.
            int generation = _HeapInfo.GenerationFor(oldMemNode.Address);

            // Create a MemoryNodeBuilder for the new graph that represents the current node
            // unless the current node is the root, as we've already created one.
            MemoryNodeBuilder newMemNodeBuilder = null;

            if (currentNode.Index == _OriginalMemoryGraph.RootIndex)
            {
                newMemNodeBuilder = _RootNode;
            }
            else
            {
                // Get the parent node.
                MemoryNodeBuilder parentMemNodeBuilder = null;
                if ((oldMemNode.Address != 0) && (generation > _GenerationToCondemn))
                {
                    if (generation == 1)
                    {
                        parentMemNodeBuilder = _Gen1RootNode;
                    }
                    else
                    {
                        parentMemNodeBuilder = _Gen2RootNode;
                    }
                }
                else
                {
                    parentMemNodeBuilder = _OldNodeToNewParentMap[(int)currentNode.Index];
                }

                if (parentMemNodeBuilder == null)
                {
                    parentMemNodeBuilder = _UnknownRootNode;
                }

                // Get the current node's type and object address.
                NodeType nodeType = _OriginalMemoryGraph.GetType(oldMemNode.TypeIndex, _OldNodeTypeStorage);

                // Create the new generation aware type name.
                string typeName = null;
                if (oldMemNode.Address != 0 && generation >= 0)
                {
                    if (generation == 3)
                    {
                        typeName = string.Format("LOH: {0}", nodeType.Name);
                    }
                    else
                    {
                        typeName = string.Format("Gen{0}: {1}", generation, nodeType.Name);
                    }
                }
                else
                {
                    if (oldMemNode.Address != 0)
                    {
                        _Log.WriteLine(string.Format("Generation: {0}; Address: {1}; Type: {2}", generation, oldMemNode.Address, nodeType.Name));
                    }
                    typeName = nodeType.Name;
                }

                // Create the new node.
                if (ShouldAddToGraph(oldMemNode, nodeType))
                {
                    if (oldMemNode.Address == 0)
                    {
                        newMemNodeBuilder = parentMemNodeBuilder.FindOrCreateChild(typeName);
                    }
                    else
                    {
                        NodeIndex newNodeIndex = _NewMemoryGraph.GetNodeIndex(oldMemNode.Address);
                        newMemNodeBuilder = new MemoryNodeBuilder(_NewMemoryGraph, typeName, null, newNodeIndex);

                        parentMemNodeBuilder.AddChild(newMemNodeBuilder);

                        // Set the object size.
                        if (generation <= _GenerationToCondemn)
                        {
                            newMemNodeBuilder.Size = oldMemNode.Size;
                        }
                        else
                        {
                            _Log.WriteLine("Ignoring Object Size: " + typeName);
                        }
                    }
                }
            }

            // Associate all children of the current node with this object's new MemoryNodeBuilder.
            for (NodeIndex childIndex = oldMemNode.GetFirstChildIndex(); childIndex != NodeIndex.Invalid; childIndex = oldMemNode.GetNextChildIndex())
            {
                _OldNodeToNewParentMap[(int)childIndex] = newMemNodeBuilder;
            }
        }
Exemple #35
0
 bool IPropertyProviderViewModel.ShouldConstructItem(IObjectNode collection, NodeIndex index) => true;
 internal ITreeViewControllerNode(NodeIndex nodeIdx, int childNum, bool isRefByChild = false)
 {
     m_nodeIdx      = nodeIdx;
     m_childNum     = childNum;
     m_isRefByChild = isRefByChild;
 }
Exemple #37
0
    public static bool ContainsNodeIndex(List<Node> list, NodeIndex indx)
    {
        if (null == list || null == indx) return false;

        foreach (Node n in list) {
            if (n.nodeIndex.i == indx.i && n.nodeIndex.j == indx.j) {
                return true;
            }
        }

        return false;
    }