public void CreateFrom(DataDefinition definition)
        {
            var structDef = definition as StructDefinition;

            if (structDef == null)
            {
                throw new Exception("Timeline keyframe must reference a StructDefinition. Not a " + definition.GetType());
            }

            Name       = structDef.Name;
            ToolTip    = structDef.ToolTip;
            TextColour = structDef.TextColour;
            LoadBackgroundCol(structDef.TextColour);
            VisibleIf     = structDef.VisibleIf;
            SkipIfDefault = structDef.SkipIfDefault;
            Description   = structDef.Description;

            foreach (var childDef in structDef.Children)
            {
                Children.Add(childDef);

                if (childDef.Name == "Time")
                {
                    TimeDefinition = (NumberDefinition)childDef;
                }
                else if (childDef.Name == "Duration")
                {
                    DurationDefinition = (NumberDefinition)childDef;

                    var lockDef = new BooleanDefinition();
                    lockDef.Name = "LockDuration";
                    DurationDefinition.Attributes.Add(lockDef);
                }
            }

            if (TimeDefinition == null)
            {
                throw new Exception("Tried to create a KeyframeDefinition from a StructDefinition without a Time element!");
            }
        }
예제 #2
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);
        }
예제 #3
0
        public override void Parse(XElement definition)
        {
            if (Name == "")
            {
                Name = "Keyframe";
            }

            Description  = definition.Attribute("Description")?.Value?.ToString();
            Extends      = definition.Attribute("Extends")?.Value?.ToString()?.ToLower();
            ExtendsAfter = definition.Attribute("ExtendsAfter")?.Value?.ToString()?.ToLower();

            var backgroundCol = definition.Attribute("Background")?.Value?.ToString();

            if (backgroundCol != null)
            {
                var split = backgroundCol.Split(new char[] { ',' });

                byte r = 0;
                byte g = 0;
                byte b = 0;
                byte a = 0;

                byte.TryParse(split[0], out r);
                byte.TryParse(split[1], out g);
                byte.TryParse(split[2], out b);
                byte.TryParse(split[3], out a);

                var col = Color.FromArgb(a, r, g, b);
                Background = new SolidColorBrush(col);
                Background.Freeze();
            }

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

                    if (child.Name == "Time")
                    {
                        TimeDefinition = (NumberDefinition)childDef;
                    }
                    if (child.Name == "Duration")
                    {
                        DurationDefinition = (NumberDefinition)childDef;

                        var lockDef = new BooleanDefinition();
                        lockDef.Name = "LockDuration";
                        DurationDefinition.Attributes.Add(lockDef);
                    }
                }
            }

            if (TimeDefinition == null)
            {
                TimeDefinition = Children.FirstOrDefault(e => e.Name == "Time") as NumberDefinition;
            }

            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");
                    }
                }
            }
        }
        public override void Parse(XElement definition)
        {
            if (Name == "")
            {
                Name = "Keyframe";
            }

            Description  = definition.Attribute("Description")?.Value?.ToString();
            Extends      = definition.Attribute("Extends")?.Value?.ToString()?.ToLower();
            ExtendsAfter = definition.Attribute("ExtendsAfter")?.Value?.ToString()?.ToLower();

            var backgroundCol = definition.Attribute("Background")?.Value?.ToString();

            if (backgroundCol != null)
            {
                TextColour = backgroundCol;
                LoadBackgroundCol(backgroundCol);
            }

            foreach (var child in definition.Elements())
            {
                if (child.Name == "Attributes")
                {
                }
                else
                {
                    var childDef = LoadDefinition(child);
                    Children.Add(childDef);

                    if (child.Name == "Time")
                    {
                        TimeDefinition = (NumberDefinition)childDef;
                    }
                    if (child.Name == "Duration")
                    {
                        DurationDefinition = (NumberDefinition)childDef;

                        var lockDef = new BooleanDefinition();
                        lockDef.Name = "LockDuration";
                        DurationDefinition.Attributes.Add(lockDef);
                    }
                }
            }

            if (TimeDefinition == null)
            {
                TimeDefinition = Children.FirstOrDefault(e => e.Name == "Time") as NumberDefinition;
            }

            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))
                    {
                        throw new Exception("Tried to collapse a struct that has a non-primitive child. This does not work!");
                    }
                    else if (Seperator == "," && type is ColourDefinition)
                    {
                        throw new Exception("If collapsing a colour the seperator should not be a comma (as colours use that to seperate their components). Please use something else.");
                    }
                    else if (Seperator == "," && type is VectorDefinition)
                    {
                        throw new Exception("If collapsing a vector the seperator should not be a comma (as vectors use that to seperate their components). Please use something else.");
                    }
                }
            }
        }