/** * Method for load tree * Status: OK * Note: if you add a new treeLoader, update the switch... */ public void LoadTree(string path, TreeType treeType = TreeType.StockTechTree) { ResetTree(); if (_treeData == null) { return; } var parser = new Parser(); _config = parser.ParseConfig(path); switch (treeType) { case TreeType.StockTechTree: _treeLoader = new StockTechTreeLoader(); break; case TreeType.YongeTech: _treeLoader = new YongeTechTreeLoader(); break; default: throw new Exception("The techtree's file format is not reconized !"); } _treeLoader.LoadTree(_config, _treeData); _treeData.LinkNodes(); _treeData.WorkspaceViewModel.StatusBarText = "Tree Loaded"; }
public void LoadTree(string path, TreeType treeType = TreeType.TechMananger) { ResetTree(); var nameNodeHashtable = new Dictionary <string, TechNodeViewModel>(); if (_treeData == null) { return; } _config = ParseTree(path); switch (treeType) { case TreeType.TechMananger: var techNodes = _config. First( child => child.Name == "TECHNOLOGY_TREE_DEFINITION"). Children.Where(node => node.Name == "NODE"). ToArray(); foreach (var node in techNodes.Where( kerbalNode => kerbalNode.Values.ContainsKey("name"))) { var v = node.Values; var name = v["name"].First(); TechNodeViewModel techNodeViewModel; if (nameNodeHashtable.ContainsKey(name)) { techNodeViewModel = nameNodeHashtable[name]; } else { techNodeViewModel = new TechNodeViewModel(); nameNodeHashtable.Add(name, techNodeViewModel); } techNodeViewModel.TechNode.PopulateFromSource(node); if (v.ContainsKey("parents")) { var parentsString = v["parents"].First(); var parents = parentsString.Split(','); foreach (var parent in parents. Where( parent => !nameNodeHashtable.ContainsKey(parent))) { nameNodeHashtable.Add(parent, new TechNodeViewModel()); } foreach (var parent in parents .Where( parent => !String.IsNullOrEmpty(parent) && nameNodeHashtable. ContainsKey(parent))) { techNodeViewModel.Parents.Add(nameNodeHashtable[parent]); } } _treeData.TechTree.Add(techNodeViewModel); } break; case TreeType.ATC: var atcNodes = _config.First(child => child.Name == "TECH_TREE"). Children.Where(node => node.Name == "TECH_NODE"). ToArray(); foreach (var node in atcNodes.Where( kerbalNode => kerbalNode.Values.ContainsKey("name"))) { var v = node.Values; var name = v["name"].First(); TechNodeViewModel techNodeViewModel; if (nameNodeHashtable.ContainsKey(name)) { techNodeViewModel = nameNodeHashtable[name]; } else { techNodeViewModel = new TechNodeViewModel(); nameNodeHashtable.Add(name, techNodeViewModel); } techNodeViewModel.TechNode.PopulateFromSource(node, TreeType.ATC); foreach (var parentNode in node.Children.Where(child => child.Name == "PARENT_NODE")) { var parentKeyValuePairs = parentNode.Values.Where(pair => pair.Key == "name"); var parents = new List <string>(); foreach (var parentKeyValuePair in parentKeyValuePairs) { parents.Add(parentKeyValuePair.Value.First()); } foreach (var parent in parents. Where( parent => !nameNodeHashtable.ContainsKey(parent))) { nameNodeHashtable.Add(parent, new TechNodeViewModel()); } foreach (var parent in parents .Where( parent => !String.IsNullOrEmpty(parent) && nameNodeHashtable. ContainsKey(parent))) { techNodeViewModel.Parents.Add(nameNodeHashtable[parent]); } } _treeData.TechTree.Add(techNodeViewModel); } break; } _treeData.LinkNodes(); _treeData.WorkspaceViewModel.StatusBarText = "Tree Loaded"; }