Example #1
0
        public void SerializeFourLevelTree()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c          = 'b',
                        ratio      = { aCount = 5, anCount = 0 },
                        SortedKids = new[] {
                            new Node {
                                c          = 'c',
                                ratio      = { aCount = 3, anCount = 4 },
                                SortedKids = new[] {
                                    new Node {
                                        c     = 'd',
                                        ratio = { aCount = 0x100, anCount = 0x80 }
                                    },
                                },
                            },
                            new Node {
                                c     = 'u',
                                ratio = { aCount = 2, anCount = 15 }
                            },
                        },
                    },
                }
            };
            const string serializedNode = @"(1:b)b(5:0)bc(3:4)bcd(100:80)bu(2:f)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Assert.Equal(node, NodeSerializer.Deserialize(serializedNode), NodeEqualityComparer.Instance);
        }
Example #2
0
        public void BasicIncrementWorks()
        {
            var node = new Node();

            IncrementPrefixExtensions.IncrementPrefix(ref node, true, "test", 0);
            Assert.Equal(NodeSerializer.Serialize(node), @"(0:1)t(0:1)te(0:1)tes(0:1)test(0:1)test (0:1)");
        }
Example #3
0
        private void SaveGraph()
        {
            _graphData.Nodes       = new NodeData[_nodes.Count];
            _graphData.Connections = new ConnectionData[_connections.Count];

            var i = 0;

            foreach (var node in _nodes.Values)
            {
                _graphData.Nodes[i] = NodeSerializer.Serialize(node);

                i++;
            }

            i = 0;

            foreach (var connection in _connections.Values)
            {
                _graphData.Connections[i] = new ConnectionData
                {
                    Guid = new GuidData(connection.Guid),
                    In   = new GuidData(connection.In.Guid),
                    Out  = new GuidData(connection.Out.Guid)
                };

                i++;
            }
        }
        public void Save(BehaviourGraph graph)
        {
            graph.Links.Clear();

            if (graph == null)
            {
                return;
            }

            foreach (var edge in edges.ToList())
            {
                var inputNode  = edge.input.node as TaskNode;
                var outputNode = edge.output.node as TaskNode;

                graph.Links.Add(new NodeLink
                {
                    SourceGuid = outputNode.GUID,
                    TargetGuid = inputNode.GUID
                });
            }

            graph.NodesData.Clear();

            foreach (var node in nodes.ToList().Cast <TaskNode>())
            {
                graph.NodesData.Add(new NodeData
                {
                    GUID     = node.GUID,
                    Position = node.GetPosition().position,
                    Type     = node.Type,
                    Data     = node.Data
                });
            }

            var id    = 0;
            var entry = graph.NodesData.FirstOrDefault(x => x.Type == typeof(EntryTask));

            if (entry != null)
            {
                AssignID(entry, ref id);
            }

            graph.Variables.Clear();

            foreach (var variable in Properties)
            {
                graph.Variables.Add(new Variable
                {
                    Name     = variable.Name,
                    Type     = variable.Type,
                    IsGlobal = variable.IsGlobal
                });
            }

            graph.BehaviorSource.TaskData = NodeSerializer.Serialize(graph);

            EditorUtility.SetDirty(graph);
            AssetDatabase.SaveAssets();
        }
Example #5
0
        public void IncrementWithSharedPrefixWorks()
        {
            var node = new Node();

            IncrementPrefixExtensions.IncrementPrefix(ref node, true, "test", 0);
            IncrementPrefixExtensions.IncrementPrefix(ref node, true, "taste", 0);
            Assert.Equal(NodeSerializer.Serialize(node), @"(0:2)t(0:2)ta(0:1)tas(0:1)tast(0:1)taste(0:1)taste (0:1)te(0:1)tes(0:1)test(0:1)test (0:1)");
        }
Example #6
0
        public void SingleNodeWorks()
        {
            var node = new Node {
                ratio = { aCount = 0x2468ad, anCount = 0x12345 }
            };
            const string serializedNode = @"(2468ad:12345)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Assert.Equal(node, NodeSerializer.Deserialize(serializedNode), NodeEqualityComparer.Instance);
        }
Example #7
0
        public void TestNodeSerialization()
        {
            MemoryStream ms = new MemoryStream();
            var          f  = new CoreEntityFactory();
            var          ns = new NodeSerializer(ms, f, new DummyContextFactory());

            ns.Serialize(f.CreateNode());

            ms.Position = 0;
            var doc = XDocument.Load(ms);

            Assert.Single(doc.Descendants("Node"));
        }
Example #8
0
        public void TestDeserializeNode()
        {
            MemoryStream ms       = new MemoryStream();
            var          f        = new CoreEntityFactory();
            var          ns       = new NodeSerializer(ms, f, new DummyContextFactory());
            var          nodeOrig = f.CreateNode();

            ns.Serialize(nodeOrig);

            ms.Position = 0;
            var node = ns.Deserialize();

            Assert.Equal(nodeOrig.Id, node.Id);
        }
Example #9
0
        public void TestEdgesSerialization()
        {
            MemoryStream ms = new MemoryStream();
            var          f  = new VirEntityFactory();
            var          ns = new NodeSerializer(ms, f, new DummyContextFactory());

            var node = f.CreateNode();

            node.ConnectTo(f.CreateNode(), Core.Interfaces.EdgeDirection.Both);

            ns.Serialize(node);

            ms.Position = 0;
            Assert.Single(XDocument.Load(ms).Descendants("Edge"));
        }
Example #10
0
        public void TestEdgeDeserialization()
        {
            MemoryStream ms = new MemoryStream();
            var          f  = new VirEntityFactory();
            var          ns = new NodeSerializer(ms, f, new DummyContextFactory());

            var node = new Person(f);

            node.ConnectTo(f.CreateNode(), Core.Interfaces.EdgeDirection.Both);

            ns.Serialize(node);

            ms.Position = 0;
            var nOut = ns.Deserialize();

            Assert.Single(nOut.Edges);
            Assert.IsAssignableFrom <IRemoteNode>(nOut.Edges.Single().GetOtherNode(nOut));
        }
Example #11
0
        public void DeleteNode(Guid guid)
        {
            var nodeData = NodeSerializer.Serialize(_nodes[guid]);

            _history.Execute(() =>
            {
                var node    = _nodes[guid];
                var sockets = new List <Socket>();
                node.GetSockets(sockets, SocketType.Input);
                node.GetSockets(sockets, SocketType.Output);
                foreach (var socket in sockets)
                {
                    _sockets.Remove(socket.Guid);
                }
                _nodes.Remove(guid);
            }, () => { CreateNode(nodeData); },
                             "delete node: " + nodeData.Type.FullName);
        }
Example #12
0
        public void RootNodeWithKidsWorks()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c     = 'b',
                        ratio = { aCount = 5, anCount = 0 },
                    },
                    new Node {
                        c     = 'u',
                        ratio = { aCount = 2, anCount = 15 },
                    },
                }
            };

            const string serializedNode = @"(1:b)b(5:0)u(2:f)";

            Assert.Equal(serializedNode, NodeSerializer.Serialize(node));
            Node deserialized = NodeSerializer.Deserialize(serializedNode);

            Assert.Equal(node, deserialized, NodeEqualityComparer.Instance);
        }