コード例 #1
0
        private IEnumerable <SceneNodeModel> XmlToNodes(SceneNodeModel parent, XmlNode xml)
        {
            var header     = xml.GetStringAttribute("header");
            var type       = xml.GetEnumAttribute <NodeType>("type") ?? NodeType.None;
            var visible    = xml.GetBoolAttribute("visible") ?? true;
            var visibility = visible ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

            var minGame = xml.GetEnumAttribute <CacheType>("minGame");
            var maxGame = xml.GetEnumAttribute <CacheType>("maxGame");

            if (ScenarioTag.CacheFile.CacheType < minGame || ScenarioTag.CacheFile.CacheType >= maxGame)
            {
                return(Enumerable.Empty <SceneNodeModel>());
            }

            var nodeInstance = new SceneNodeModel(header, type)
            {
                Visibility = visibility, Tag = parent?.Tag
            };

            IEnumerable <SceneNodeModel> nodes;

            if (xml.Name == "placeholder" && parent != null)
            {
                nodes = GetPlaceholderInstances(parent, nodeInstance).ToList();
            }
            else
            {
                nodes = Enumerable.Repeat(nodeInstance, 1);
            }

            foreach (var node in nodes)
            {
                var children = xml.ChildNodes.OfType <XmlNode>().SelectMany(n => XmlToNodes(node, n));
                foreach (var c in children)
                {
                    node.Items.Add(c);
                }
            }

            return(nodes);
        }
コード例 #2
0
 private IEnumerable <SceneNodeModel> GetPlaceholderInstances(SceneNodeModel parent, SceneNodeModel placeholder)
 {
     if (placeholder.NodeType == NodeType.AiDefaultZoneItem)
     {
         return(Enumerable.Repeat(SquadHierarchy.DefaultZone, 1).Select(z => new SceneNodeModel(z.GetDisplayName(), NodeType.AiDefaultZoneItem)
         {
             Tag = z, IconType = 1
         }));
     }
     if (placeholder.NodeType == NodeType.AiZoneItem)
     {
         return(SquadHierarchy.Zones.Select(z => new SceneNodeModel(z.GetDisplayName(), NodeType.AiZoneItem)
         {
             Tag = z, IconType = 1
         }));
     }
     else if (placeholder.NodeType == NodeType.AiSquadItem)
     {
         return((parent.Tag as AiZone).Squads.Select(e => new SceneNodeModel(e.GetDisplayName(), NodeType.AiSquadItem)
         {
             Tag = e, IconType = 1
         }));
     }
     else if (placeholder.NodeType == NodeType.AiEncounterItem)
     {
         return((parent.Tag as AiSquad).Encounters.Select(s => new SceneNodeModel(s.GetDisplayName(), NodeType.AiEncounterItem)
         {
             Tag = s, IconType = 1
         }));
     }
     else
     {
         return new List <SceneNodeModel> {
                    placeholder
         }
     };
 }