public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new GraphCollectionItem(this, undoRedo);

            item.X       = TryParseFloat(element, MetaNS + "X");
            item.Y       = TryParseFloat(element, MetaNS + "Y");
            item.GUID    = element.Attribute("GUID")?.Value?.ToString();
            item.Comment = element.Attribute(MetaNS + "Comment")?.Value?.ToString();

            foreach (var el in element.Elements())
            {
                var prev = el.PreviousNode as XComment;
                if (prev != null)
                {
                    var comment = new CommentDefinition().LoadData(prev, undoRedo);
                    item.Children.Add(comment);
                }

                var cdef  = ChildDefinitions.FirstOrDefault(e => e.Name == el.Name);
                var child = cdef.LoadData(el, undoRedo);
                item.Children.Add(child);

                if (item.Children.Count == MaxCount)
                {
                    break;
                }
            }

            if (element.LastNode is XComment)
            {
                var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                item.Children.Add(comment);
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new StructItem(this, undoRedo);

            if (Collapse)
            {
                var split = element.Value.Split(new string[] { Seperator }, StringSplitOptions.None);

                if (split.Length == Children.Count)
                {
                    for (int i = 0; i < split.Length; i++)
                    {
                        var      data      = split[i];
                        var      def       = Children[i] as PrimitiveDataDefinition;
                        DataItem childItem = def.LoadFromString(data, undoRedo);
                        item.Children.Add(childItem);
                    }
                }
                else
                {
                    foreach (var def in Children)
                    {
                        var child = def.CreateData(undoRedo);
                        item.Children.Add(child);
                    }
                }
            }
            else
            {
                var createdChildren = new List <DataItem>();

                var commentTexts = Children.Where(e => e is CommentDefinition).Select(e => (e as CommentDefinition).Text);

                foreach (var def in Children)
                {
                    var name = def.Name;

                    var els = !(def is CommentDefinition) ? element.Elements(name) : new List <XElement>();

                    if (els.Count() > 0)
                    {
                        var prev = els.First().PreviousNode as XComment;
                        if (prev != null)
                        {
                            var comment = new CommentDefinition().LoadData(prev, undoRedo);
                            if (!commentTexts.Contains(comment.TextValue))
                            {
                                item.Children.Add(comment);
                            }
                        }

                        if (def is CollectionDefinition)
                        {
                            CollectionItem childItem = (CollectionItem)def.LoadData(els.First(), undoRedo);
                            if (childItem.Children.Count == 0)
                            {
                                var dummyEl = new XElement(els.First().Name);
                                foreach (var el in els)
                                {
                                    dummyEl.Add(el);
                                }

                                childItem = (CollectionItem)def.LoadData(dummyEl, undoRedo);
                            }

                            item.Children.Add(childItem);
                        }
                        else
                        {
                            DataItem childItem = def.LoadData(els.First(), undoRedo);
                            item.Children.Add(childItem);
                        }
                    }
                    else
                    {
                        DataItem childItem = def.CreateData(undoRedo);
                        item.Children.Add(childItem);
                    }
                }

                if (element.LastNode is XComment)
                {
                    var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                    if (!commentTexts.Contains(comment.TextValue))
                    {
                        item.Children.Add(comment);
                    }
                }
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            foreach (var child in item.Attributes)
            {
                child.UpdateVisibleIfBinding();
            }
            foreach (var child in item.Children)
            {
                child.UpdateVisibleIfBinding();
            }

            return(item);
        }
        public override void Parse(XElement definition)
        {
            Nullable     = TryParseBool(definition, "Nullable", true);
            Description  = definition.Attribute("Description")?.Value?.ToString();
            Extends      = definition.Attribute("Extends")?.Value?.ToString()?.ToLower();
            ExtendsAfter = definition.Attribute("ExtendsAfter")?.Value?.ToString()?.ToLower();

            foreach (var node in definition.Nodes())
            {
                if (node is XComment)
                {
                    var child      = node as XComment;
                    var commentDef = new CommentDefinition();
                    commentDef.CanEdit = false;
                    commentDef.Text    = child.Value;
                    Children.Add(commentDef);
                }
                else if (node is XElement)
                {
                    var child = node as XElement;
                    if (child.Name == "Attributes")
                    {
                    }
                    else
                    {
                        var childDef = LoadDefinition(child);
                        Children.Add(childDef);
                    }
                }
            }

            var collapseAtt = definition.Attribute("Collapse");

            if (collapseAtt != null)
            {
                Collapse    = TryParseBool(definition, "Collapse");
                HadCollapse = true;
            }

            Seperator = definition.Attribute("Seperator")?.Value;
            if (Collapse && Seperator == null)
            {
                Seperator = ",";
            }

            if (Collapse)
            {
                foreach (var type in Children)
                {
                    if (!(type is PrimitiveDataDefinition))
                    {
                        Message.Show("Tried to collapse a struct that has a non-primitive child. This does not work!", "Parse Error", "Ok");
                        Collapse = false;
                        break;
                    }
                    else if (Seperator == "," && type is ColourDefinition)
                    {
                        Message.Show("If collapsing a colour the seperator should not be a comma (as colours use that to seperate their components). Please use something else.", "Parse Error", "Ok");
                    }
                    else if (Seperator == "," && type is VectorDefinition)
                    {
                        Message.Show("If collapsing a vector the seperator should not be a comma (as vectors use that to seperate their components). Please use something else.", "Parse Error", "Ok");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static DataDefinition LoadDefinition(XElement element, string forceLoadAs = null)
        {
            if (element.Name.ToString() == "Const")
            {
                var constDef = new ConstDefinition();
                constDef.Parse(element);
                return(constDef);
            }

            var name = element.Attribute(MetaNS + "RefKey")?.Value.ToString().ToUpper();

            if (name == null)
            {
                name = element.Attribute("RefKey")?.Value.ToString().ToUpper();
            }
            if (name == null)
            {
                name = element.Name.ToString().ToUpper();
            }

            if (name.EndsWith("DEF"))
            {
                name = name.Substring(0, name.Length - "DEF".Length);
            }

            if (forceLoadAs != null)
            {
                name = forceLoadAs.ToUpper();
            }

            DataDefinition definition = null;

            if (name == "STRING")
            {
                definition = new StringDefinition();
            }
            else if (name == "MULTILINESTRING")
            {
                definition = new MultilineStringDefinition();
            }
            else if (name == "STRUCT")
            {
                definition = new StructDefinition();
            }
            else if (name == "REFERENCE")
            {
                definition = new ReferenceDefinition();
            }
            else if (name == "COLLECTION")
            {
                definition = new CollectionDefinition();
            }
            else if (name == "NUMBER")
            {
                definition = new NumberDefinition();
            }
            else if (name == "BOOLEAN")
            {
                definition = new BooleanDefinition();
            }
            else if (name == "COLOUR")
            {
                definition = new ColourDefinition();
            }
            else if (name == "ENUM")
            {
                definition = new EnumDefinition();
            }
            else if (name == "FLAGS")
            {
                definition = new FlagsDefinition();
            }
            else if (name == "FILE")
            {
                definition = new FileDefinition();
            }
            else if (name == "TREE")
            {
                definition = new TreeDefinition();
            }
            else if (name == "VECTOR")
            {
                definition = new VectorDefinition();
            }
            else if (name == "TIMELINE")
            {
                definition = new TimelineDefinition();
            }
            else if (name == "GRAPHSTRUCT")
            {
                definition = new GraphStructDefinition();
            }
            else if (name == "GRAPHCOLLECTION")
            {
                definition = new GraphCollectionDefinition();
            }
            else if (name == "GRAPHREFERENCE")
            {
                definition = new GraphReferenceDefinition();
            }
            else if (name == "KEYFRAME")
            {
                definition = new KeyframeDefinition();
            }
            else if (name == "COMMENT")
            {
                definition = new CommentDefinition();
            }
            else if (name == "SKELETALANIMATION")
            {
                definition = new SkeletalAnimationDefinition();
            }
            else
            {
                throw new Exception("Unknown definition type " + name + "!");
            }

            definition.Name = element.Attribute("Name")?.Value?.ToString();
            if (string.IsNullOrWhiteSpace(definition.Name))
            {
                definition.Name = definition.GetType().ToString().Replace("Definition", "");
            }

            definition.ToolTip = element.Attribute("ToolTip")?.Value?.ToString();

            var col = element.Attribute("TextColour")?.Value?.ToString();

            if (col != null)
            {
                if (Colours.ContainsKey(col))
                {
                    col = Colours[col];
                }
                definition.TextColour = col;
            }

            var attEl = element.Element("Attributes");

            if (attEl != null)
            {
                foreach (var att in attEl.Elements())
                {
                    var attDef = LoadDefinition(att);
                    if (attDef is PrimitiveDataDefinition)
                    {
                        definition.Attributes.Add(attDef as PrimitiveDataDefinition);
                    }
                    else
                    {
                        throw new Exception("Cannot put a non-primitive into attributes!");
                    }
                }
            }

            definition.IsGlobal      = definition.TryParseBool(element, "IsGlobal");
            definition.VisibleIf     = element.Attribute("VisibleIf")?.Value?.ToString();
            definition.SkipIfDefault = definition.TryParseBool(element, "SkipIfDefault", true);

            definition.Parse(element);

            return(definition);
        }
Exemplo n.º 5
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new GraphStructItem(this, undoRedo);

            item.X       = TryParseFloat(element, MetaNS + "X");
            item.Y       = TryParseFloat(element, MetaNS + "Y");
            item.GUID    = element.Attribute("GUID")?.Value?.ToString();
            item.Comment = element.Attribute(MetaNS + "Comment")?.Value?.ToString();

            var commentTexts = Children.Where(e => e is CommentDefinition).Select(e => (e as CommentDefinition).Text);

            var createdChildren = new List <DataItem>();

            foreach (var def in Children)
            {
                var name = def.Name;

                var els = element.Elements(name);

                if (els.Count() > 0)
                {
                    var prev = els.First().PreviousNode as XComment;
                    if (prev != null)
                    {
                        var comment = new CommentDefinition().LoadData(prev, undoRedo);
                        if (!commentTexts.Contains(comment.TextValue))
                        {
                            item.Children.Add(comment);
                        }
                    }

                    if (def is CollectionDefinition)
                    {
                        CollectionItem childItem = (CollectionItem)def.LoadData(els.First(), undoRedo);
                        if (childItem.Children.Count == 0)
                        {
                            var dummyEl = new XElement(els.First().Name);
                            foreach (var el in els)
                            {
                                dummyEl.Add(el);
                            }

                            childItem = (CollectionItem)def.LoadData(dummyEl, undoRedo);
                        }

                        item.Children.Add(childItem);
                    }
                    else
                    {
                        DataItem childItem = def.LoadData(els.First(), undoRedo);
                        item.Children.Add(childItem);
                    }
                }
                else
                {
                    DataItem childItem = def.CreateData(undoRedo);
                    item.Children.Add(childItem);
                }
            }

            if (element.LastNode is XComment)
            {
                var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                if (!commentTexts.Contains(comment.TextValue))
                {
                    item.Children.Add(comment);
                }
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            item.Children.OrderBy(e => Children.IndexOf(e.Definition));

            foreach (var child in item.Attributes)
            {
                child.UpdateVisibleIfBinding();
            }
            foreach (var child in item.Children)
            {
                child.UpdateVisibleIfBinding();
            }

            return(item);
        }
Exemplo n.º 6
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new CollectionItem(this, undoRedo);

            if (Collapse && ChildDefinitions.Count == 1 && ChildDefinitions[0].WrappedDefinition is PrimitiveDataDefinition)
            {
                var primDef = ChildDefinitions[0].WrappedDefinition as PrimitiveDataDefinition;
                var split   = element.Value.Split(new string[] { Seperator }, StringSplitOptions.None);
                foreach (var s in split)
                {
                    var child = primDef.LoadFromString(s, undoRedo);
                    var citem = ChildDefinitions[0].CreateData(undoRedo) as CollectionChildItem;
                    citem.WrappedItem = child;

                    item.Children.Add(citem);

                    if (item.Children.Count == MaxCount)
                    {
                        break;
                    }
                }
            }
            else
            {
                var uncreatedAdds = AdditionalDefs.ToList();

                foreach (var el in element.Elements())
                {
                    var prev = el.PreviousNode as XComment;
                    if (prev != null)
                    {
                        var comment = new CommentDefinition().LoadData(prev, undoRedo);
                        item.Children.Add(comment);
                    }

                    var cdef = ChildDefinitions.FirstOrDefault(e => e.Name == el.Name);
                    if (cdef != null)
                    {
                        var child = cdef.LoadData(el, undoRedo);
                        item.Children.Add(child);
                    }
                    else
                    {
                        var def = AdditionalDefs.FirstOrDefault(e => e.Name == el.Name);
                        if (def != null)
                        {
                            var child = def.LoadData(el, undoRedo);
                            item.Children.Insert(0, child);

                            uncreatedAdds.Remove(def);
                        }
                        else if (ChildDefinitions.Count == 1)
                        {
                            var child = ChildDefinitions[0].LoadData(el, undoRedo);
                            item.Children.Add(child);
                        }
                        else
                        {
                            throw new Exception("Unable to find def for '" + el.Name + "' in collection '" + Name + "'!");
                        }
                    }
                }

                foreach (var def in uncreatedAdds)
                {
                    var child = def.CreateData(undoRedo);
                    item.Children.Insert(0, child);
                }

                if (element.LastNode is XComment)
                {
                    var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                    item.Children.Add(comment);
                }
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }