protected override void DoRecursivelyResolve(Dictionary <string, DataDefinition> local, Dictionary <string, DataDefinition> global, Dictionary <string, Dictionary <string, DataDefinition> > referenceableDefinitions)
        {
            if (DefKey != null)
            {
                var key = DefKey.ToLower();

                Dictionary <string, DataDefinition> defs = null;
                if (local.ContainsKey(key))
                {
                    defs = local;
                }
                else if (global.ContainsKey(key))
                {
                    defs = global;
                }

                if (defs != null)
                {
                    var def = defs[key] as ReferenceDefinition;
                    Keys = def.Keys;

                    ListCollectionView lcv = new ListCollectionView(Keys);
                    lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2"));
                    ItemsSource = lcv;
                }
                else
                {
                    throw new Exception("Failed to find key " + DefKey + "!");
                }
            }

            foreach (var key in Keys)
            {
                Dictionary <string, DataDefinition> defs = null;
                if (local.ContainsKey(key.Item1.ToLower()))
                {
                    defs = local;
                }
                else if (global.ContainsKey(key.Item1.ToLower()))
                {
                    defs = global;
                }

                if (defs != null)
                {
                    var def = defs[key.Item1.ToLower()];

                    if (def is GraphNodeDefinition)
                    {
                        Definitions[key.Item1] = def as GraphNodeDefinition;
                    }
                    else if (key.Item1 != "---")
                    {
                        throw new Exception("Tried to add definition of type " + def.GetType() + " (key = " + key.Item1 + ") to graph reference!");
                    }
                }
                else
                {
                    throw new Exception("Failed to find key " + key.Item1 + "!");
                }
            }

            if (Keys.Count == 0)
            {
                Keys.Add(new Tuple <string, string>("---", "---"));

                ListCollectionView lcv = new ListCollectionView(Keys);
                lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2"));
                ItemsSource = lcv;

                Definitions["---"] = new GraphStructDefinition();
            }
        }
Пример #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);
        }