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!"); } }
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); }