示例#1
0
        private void PopulateFields(NodeDesc node)
        {
            var fields = GetType().GetFields();

            foreach (var field in fields)
            {
                foreach (var parameter in node.parameters)
                {
                    if (parameter.key.ToLower() == field.Name.ToLower())
                    {
                        if (field.FieldType == typeof(int))
                        {
                            field.SetValue(this, int.Parse(parameter.value));
                        }
                        else if (field.FieldType == typeof(float))
                        {
                            field.SetValue(this, float.Parse(parameter.value));
                        }
                        else if (field.FieldType == typeof(string))
                        {
                            field.SetValue(this, parameter.value);
                        }
                    }
                }
            }
        }
示例#2
0
        public void Deserialize(NodeDesc node)
        {
            PopulateFields(node);

            for (int i = 0; i < node.children.Count; ++i)
            {
                var child = NodeFactory.Create(node.children[i].typeName);
                children.Add(child);
                child.Deserialize(node.children[i]);
            }
        }
示例#3
0
        public Blueprint(string text)
        {
            var lines = text.Split('\n');

            Stack <NodeDesc> stack = new Stack <NodeDesc>();
            NodeDesc         prev  = null;

            foreach (var unfilteredLine in lines)
            {
                var line = unfilteredLine
                           .Replace("\t", string.Empty)
                           .Replace("\r", string.Empty);

                var node = new NodeDesc();

                var tokens = line.Split(' ');
                node.typeName = tokens[0];

                int depth = TreeDepth(unfilteredLine);

                if (depth > stack.Count)
                {
                    stack.Push(prev);
                }

                while (depth < stack.Count)
                {
                    stack.Pop();
                }

                if (stack.Count == 0)
                {
                    root = node;
                }
                else
                {
                    var parent = stack.Peek();
                    parent.children.Add(node);
                }

                // Read parameters
                for (int i = 1; i < tokens.Length; ++i)
                {
                    node.parameters.Add(new Parameter(tokens[i]));
                }

                prev = node;
            }
        }