/// <inheritdoc />
        public bool OnNodeList(ListValueReflection reflection, NodeReflection nodeReflection, out IList newValue)
        {
            ConfigNode[] nodes = Node.GetNodes(reflection.NodeId);
            var          load  = new LoadVisitor();

            int index = 0;
            int i     = 0;

            var items = new List <object>(nodes.Length);

            foreach (ConfigNode node in nodes)
            {
                if (!node.TryGetValue("index", ref i))
                {
                    i = index;
                }
                index++;

                load.Node = node;
                object item = nodeReflection.Load(load, out int errors);
                SetItem(items, item, i);

                if (errors > 0)
                {
                    FARLogger.ErrorFormat("{0} errors while loading {1}[{2}]",
                                          errors.ToString(),
                                          node.name,
                                          i.ToString());
                }
            }

            newValue = items;
            return(true);
        }
        /// <inheritdoc />
        public bool OnNode(object nodeObject, NodeReflection reflection, out object newValue)
        {
            ConfigNode node = string.IsNullOrEmpty(reflection.Name)
                                  ? Node.GetNode(reflection.Id)
                                  : Node.GetNode(reflection.Id, "name", reflection.Name);

            if (node != null)
            {
                var load = new LoadVisitor {
                    Node = node
                };
                int errors = reflection.Load(load, ref nodeObject);

                if (errors > 0)
                {
                    FARLogger.ErrorFormat("{0} errors while loading {1}[{2}]",
                                          errors.ToString(),
                                          node.name,
                                          reflection.Name);
                }
            }

            newValue = nodeObject;
            return(true);
        }
        /// <inheritdoc />
        public bool OnListNode(
            int index,
            object value,
            ListValueReflection reflection,
            NodeReflection nodeReflection,
            out object newValue
            )
        {
            if (index == 0 && IsPatch)
            {
                Node.AddNode(string.IsNullOrEmpty(reflection.Name)
                                 ? $"!{reflection.NodeId},*"
                                 : $"!{reflection.NodeId}[{reflection.Name}],*");
            }

            newValue = default;
            var save = new SaveVisitor
            {
                IsPatch = false,
                Node    = new ConfigNode()
            };

            nodeReflection.Save(save, value);

            if (save.Node.HasData)
            {
                Serialization.AddNode(Node, save.Node, nodeReflection.Id, reflection.Name);
            }

            return(false);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Common common = new Common()
            {
                B = 30
            };

            NodeReflection reflection = new NodeReflection();
            Node           node       = reflection.GetReflectNode(common);

            Debug.WriteLine(node.ToString());
            Common result = reflection.CreateObject <Common>(node);

            Debug.WriteLine("value {0} {1} {2}", result.A, result.B, result.C);

            string    xml    = "<?xml version=\"1.0\"?><name>value</name>";
            XmlPacker packer = new XmlPacker();

            packer.IgnoreWhitespace = true;
            packer.Parse(node);
            string packed = packer.ToString();

            Debug.WriteLine(packed);
        }
Пример #5
0
 protected override void OnGraphEnable()
 {
     if (GetNode <TerrainOutput>() == null)
     {
         AddNode(NodeReflection.Instantiate <TerrainOutput>());
     }
 }
Пример #6
0
        protected override void OnGraphEnable()
        {
            base.OnGraphEnable();

            if (GetNode <StartDialog>() == null)
            {
                var start = NodeReflection.Instantiate <StartDialog>();
                AddNode(start);
            }

            if (GetNode <EndDialog>() == null)
            {
                var end = NodeReflection.Instantiate <EndDialog>();
                end.Position = new Vector2(300, 0);
                AddNode(end);
            }
        }
        /// <inheritdoc />
        public bool OnNode(object value, NodeReflection reflection, out object newValue)
        {
            newValue = default;
            var save = new SaveVisitor
            {
                IsPatch = IsPatch,
                Node    = new ConfigNode()
            };

            reflection.Save(save, value);

            if (save.Node.HasData)
            {
                Serialization.AddNode(Node, save.Node, reflection.Id, reflection.Name, IsPatch);
            }

            return(false);
        }
Пример #8
0
        public void SaveAndReload()
        {
            commonClass = new Common()
            {
                A = 30,
                B = 10.5f
            };
            NodeReflection reflection = new NodeReflection();

            Node node = reflection.GetReflectNode(commonClass);

            Assert.AreEqual((int)node["A"].Value.Value, 30);
            Assert.AreEqual((float)node["B"].Value.Value, 10.5f);

            Common result = reflection.CreateObject <Common>(node);

            Assert.AreEqual(result.A, commonClass.A);
            Assert.AreEqual(result.B, commonClass.B);
        }
Пример #9
0
        /// <summary>
        /// On asset creation in the editor, initialize with some default event nodes.
        /// </summary>
        protected override void OnGraphEnable()
        {
            if (Nodes.Count > 0)
            {
                return;
            }

            if (GetNode <OnEnable>() == null)
            {
                var node = NodeReflection.Instantiate <OnEnable>();
                AddNode(node);
            }

            if (GetNode <OnUpdate>() == null)
            {
                var node = NodeReflection.Instantiate <OnUpdate>();
                node.Position = new Vector2(0, 100);
                AddNode(node);
            }
        }