public static SkillTree CreateSkillTree(StartLoadingWindow start = null, UpdateLoadingWindow update = null, CloseLoadingWindow finish = null) { string skilltreeobj = ""; if (Directory.Exists("Data")) { if (File.Exists("Data\\Skilltree.txt")) { skilltreeobj = File.ReadAllText("Data\\Skilltree.txt"); } if (!File.Exists("Data\\Assets")) { Directory.CreateDirectory("Data\\Assets"); } } else { Directory.CreateDirectory("Data"); Directory.CreateDirectory("Data\\Assets"); } bool displayProgress = false; if (skilltreeobj == "") { displayProgress = (start != null && update != null && finish != null); if (displayProgress) { start(); } string uriString = "http://www.pathofexile.com/passive-skill-tree/"; var req = (HttpWebRequest)WebRequest.Create(uriString); var resp = (HttpWebResponse)req.GetResponse(); string code = new StreamReader(resp.GetResponseStream()).ReadToEnd(); var regex = new Regex("var passiveSkillTreeData.*"); skilltreeobj = regex.Match(code).Value.Replace("root", "main").Replace("\\/", "/"); skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 2) + ""; File.WriteAllText("Data\\Skilltree.txt", skilltreeobj); } if (displayProgress) { update(25, 100); } var skillTree = new SkillTree(skilltreeobj, displayProgress, update); if (displayProgress) { finish(); } return(skillTree); }
public static SkillTree CreateSkillTree(StartLoadingWindow start = null, UpdateLoadingWindow update = null, CloseLoadingWindow finish = null) { AssetsFolderPath = AppData.GetFolder(Path.Combine("Data", "Assets"), true); DataFolderPath = AppData.GetFolder("Data", true); string skillTreeFile = DataFolderPath + "Skilltree.txt"; string skilltreeobj = ""; if (File.Exists(skillTreeFile)) { skilltreeobj = File.ReadAllText(skillTreeFile); } bool displayProgress = false; if (skilltreeobj == "") { displayProgress = (start != null && update != null && finish != null); if (displayProgress) { start(L10n.Message("Downloading Skill tree assets")); } string uriString = SkillTree.TreeAddress; var req = (HttpWebRequest)WebRequest.Create(uriString); var resp = (HttpWebResponse)req.GetResponse(); string code = new StreamReader(resp.GetResponseStream()).ReadToEnd(); var regex = new Regex("var passiveSkillTreeData.*"); skilltreeobj = regex.Match(code).Value.Replace("\\/", "/"); skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 1) + ""; File.WriteAllText(skillTreeFile, skilltreeobj); } if (displayProgress) { update(25, 100); } var skillTree = new SkillTree(skilltreeobj, displayProgress, update); if (displayProgress) { finish(); } return(skillTree); }
public static SkillTree CreateSkillTree(startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { string skilltreeobj = ""; if (Directory.Exists("Data")) { if (File.Exists("Data\\Skilltree.txt")) { skilltreeobj = File.ReadAllText("Data\\Skilltree.txt"); } } else { Directory.CreateDirectory("Data"); Directory.CreateDirectory("Data\\Assets"); } if (skilltreeobj == "") { bool displayProgress = (start != null && update != null && finish != null); if (displayProgress) { start(); } //loadingWindow.Dispatcher.Invoke(DispatcherPriority.Background,new Action(delegate { })); string uriString = "http://web.poe.garena.tw/passive-skill-tree/"; //string uriString = "http://www.pathofexile.com/passive-skill-tree/"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriString); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); string code = new StreamReader(resp.GetResponseStream()).ReadToEnd(); Regex regex = new Regex("var passiveSkillTreeData.*"); skilltreeobj = regex.Match(code).Value.Replace("root", "main").Replace("\\/", "/"); skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 2) + ""; File.WriteAllText("Data\\Skilltree.txt", skilltreeobj); if (displayProgress) { finish(); } } return(new SkillTree(skilltreeobj, start, update, finish)); }
public void OpenOrDownloadImages(UpdateLoadingWindow update = null) { //Application int count = 0; foreach (var image in Images.Keys.ToArray()) { if (!File.Exists("Data\\Assets\\" + image)) { System.Net.WebClient _WebClient = new System.Net.WebClient(); _WebClient.DownloadFile(urlpath + image, "Data\\Assets\\" + image); } Images[image] = new BitmapImage(new Uri("Data\\Assets\\" + image, UriKind.Relative)); if (update != null) { update(count * 100 / Images.Count, 100); } ++count; } }
public static SkillTree CreateSkillTree(startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { string skilltreeobj = ""; if (Directory.Exists("Data")) { if (File.Exists("Data\\Skilltree.txt")) { skilltreeobj = File.ReadAllText("Data\\Skilltree.txt"); } } else { Directory.CreateDirectory("Data"); Directory.CreateDirectory("Data\\Assets"); } if (skilltreeobj == "") { bool displayProgress = (start != null && update != null && finish != null); if (displayProgress) start(); //loadingWindow.Dispatcher.Invoke(DispatcherPriority.Background,new Action(delegate { })); string uriString = "http://www.pathofexile.com/passive-skill-tree/"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriString); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); string code = new StreamReader(resp.GetResponseStream()).ReadToEnd(); Regex regex = new Regex("var passiveSkillTreeData.*"); skilltreeobj = regex.Match(code).Value.Replace("root", "main").Replace("\\/", "/"); skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 2) + ""; File.WriteAllText("Data\\Skilltree.txt", skilltreeobj); if (displayProgress) finish(); } return new SkillTree(skilltreeobj, start, update, finish); }
public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { bool displayProgress = (start != null && update != null && finish != null); // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) ); JsonSerializerSettings jss = new JsonSerializerSettings { Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; var inTree = JsonConvert.DeserializeObject <PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss); foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) { continue; } iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) { continue; } iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var ass in inTree.assets) { assets[ass.Key] = new Asset(ass.Key, ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First()); } if (displayProgress) { start( ); } iconActiveSkills.OpenOrDownloadImages(update); iconInActiveSkills.OpenOrDownloadImages(update); if (displayProgress) { finish( ); } foreach (var c in inTree.characterData) { CharBaseAttributes[c.Key] = new Dictionary <string, float>() { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } }; } foreach (var nd in inTree.nodes) { Skillnodes.Add(nd.id, new SkillTree.SkillNode() { id = nd.id, name = nd.dn, attributes = nd.sd, orbit = nd.o, orbitIndex = nd.oidx, icon = nd.icon, linkID = nd.ot, g = nd.g, da = nd.da, ia = nd.ia, ks = nd.ks, not = nd.not, sa = nd.sa, Mastery = nd.m, spc = nd.spc.Count() > 0?(int?)nd.spc[0]:null }); } List <ushort[]> links = new List <ushort[]>( ); foreach (var skillNode in Skillnodes) { foreach (ushort i in skillNode.Value.linkID) { if ( links.Count( nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) == 1) { continue; } links.Add(new ushort[] { skillNode.Key, i }); } } foreach (ushort[] ints in links) { if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]])) { Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]); } if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]])) { Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]); } } foreach (var gp in inTree.groups) { NodeGroup ng = new NodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); ng.Nodes = gp.Value.n; NodeGroups.Add(ng); } foreach (SkillTree.NodeGroup group in NodeGroups) { foreach (ushort node in group.Nodes) { Skillnodes[node].NodeGroup = group; } } TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1), new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1)); InitNodeSurround( ); DrawNodeSurround( ); DrawNodeBaseSurround( ); DrawSkillIconLayer( ); DrawBackgroundLayer( ); InitFaceBrushesAndLayer( ); DrawLinkBackgroundLayer( ); InitOtherDynamicLayers( ); CreateCombineVisual( ); Regex regexAttrib = new Regex("[0-9]*\\.?[0-9]+"); foreach (var skillNode in Skillnodes) { skillNode.Value.Attributes = new Dictionary <string, List <float> >( ); foreach (string s in skillNode.Value.attributes) { List <float> values = new List <float>( ); foreach (Match m in regexAttrib.Matches(s)) { if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#"))) { AttributeTypes.Add(regexAttrib.Replace(s, "#")); } if (m.Value == "") { values.Add(float.NaN); } else { values.Add(float.Parse(m.Value, System.Globalization.CultureInfo.InvariantCulture)); } } string cs = (regexAttrib.Replace(s, "#")); skillNode.Value.Attributes[cs] = values; } } Solver = new Solver(Skillnodes); }
public SkillTree(String treestring, bool displayProgress, UpdateLoadingWindow update) { PoESkillTree inTree = null; if (!_Initialized) { var jss = new JsonSerializerSettings { Error = delegate(object sender, ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; inTree = JsonConvert.DeserializeObject <PoESkillTree>(treestring.Replace("Additional ", ""), jss); } int qindex = 0; if (!_Initialized) { SkillTree._IconInActiveSkills = new SkillIcons(); //TODO: (SpaceOgre) This is not used atm, so no need to run it. foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) { continue; } _IconInActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { _IconInActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } } if (!_Initialized) { SkillTree._IconActiveSkills = new SkillIcons(); foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) { continue; } _IconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { _IconActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } } if (!_Initialized) { foreach (var ass in inTree.assets) { _assets[ass.Key] = new Asset(ass.Key, ass.Value.ContainsKey(0.3835f) ? ass.Value[0.3835f] : ass.Value.Values.First()); } } if (!_Initialized) { _rootNodeList = new List <int>(); if (inTree.root != null) { foreach (int i in inTree.root.ot) { _rootNodeList.Add(i); } } else if (inTree.main != null) { foreach (int i in inTree.main.ot) { _rootNodeList.Add(i); } } } if (displayProgress) { update(50, 100); } if (!_Initialized) { _IconActiveSkills.OpenOrDownloadImages(update); } if (displayProgress) { update(75, 100); } if (!_Initialized) { _IconInActiveSkills.OpenOrDownloadImages(update); } if (!_Initialized) { _CharBaseAttributes = new Dictionary <string, float> [7]; foreach (var c in inTree.characterData) { _CharBaseAttributes[c.Key] = new Dictionary <string, float> { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } }; } } if (!_Initialized) { _Skillnodes = new Dictionary <ushort, SkillNode>(); foreach (Node nd in inTree.nodes) { _Skillnodes.Add(nd.id, new SkillNode { Id = nd.id, Name = nd.dn, attributes = nd.sd, Orbit = nd.o, OrbitIndex = nd.oidx, Icon = nd.icon, LinkId = nd.ot, G = nd.g, Da = nd.da, Ia = nd.ia, IsKeyStone = nd.ks, IsNotable = nd.not, Sa = nd.sa, IsMastery = nd.m, Spc = nd.spc.Count() > 0 ? (int?)nd.spc[0] : null }); if (_rootNodeList.Contains(nd.id)) { _rootNodeClassDictionary.Add(nd.dn.ToString().ToUpper(), nd.id); foreach (int linkedNode in nd.ot) { _startNodeDictionary.Add(linkedNode, nd.id); } } foreach (int node in nd.ot) { if (!_startNodeDictionary.ContainsKey(nd.id) && _rootNodeList.Contains(node)) { _startNodeDictionary.Add(nd.id, node); } } } foreach (var skillNode in Skillnodes) { foreach (ushort i in skillNode.Value.LinkId) { if ( _links.Count(nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) == 1) { continue; } _links.Add(new[] { skillNode.Key, i }); } } foreach (var ints in _links) { if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]])) { Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]); } if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]])) { Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]); } } } if (!_Initialized) { _NodeGroups = new List <SkillNodeGroup>(); foreach (var gp in inTree.groups) { var ng = new SkillNodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); foreach (ushort node in gp.Value.n) { ng.Nodes.Add(Skillnodes[node]); } NodeGroups.Add(ng); } foreach (SkillNodeGroup group in NodeGroups) { foreach (SkillNode node in group.Nodes) { node.SkillNodeGroup = group; } } } if (!_Initialized) { _TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1), new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1)); } InitNodeSurround();// DrawNodeSurround(); DrawNodeBaseSurround(); InitSkillIconLayers(); DrawSkillIconLayer(); DrawBackgroundLayer(); InitFaceBrushesAndLayer(); DrawLinkBackgroundLayer(_links); InitOtherDynamicLayers(); CreateCombineVisual(); if (_links != null) { var regexAttrib = new Regex("[0-9]*\\.?[0-9]+"); foreach (var skillNode in Skillnodes) { skillNode.Value.Attributes = new Dictionary <string, List <float> >(); foreach (string s in skillNode.Value.attributes) { var values = new List <float>(); foreach (Match m in regexAttrib.Matches(s)) { if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#"))) { AttributeTypes.Add(regexAttrib.Replace(s, "#")); } if (m.Value == "") { values.Add(float.NaN); } else { values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture)); } } string cs = (regexAttrib.Replace(s, "#")); skillNode.Value.Attributes[cs] = values; } } } if (displayProgress) { update(100, 100); } _Initialized = true; }
public void OpenOrDownloadImages(UpdateLoadingWindow update = null) { //Application int count = 0; foreach (var image in Images.Keys.ToArray()) { if (!File.Exists("Data\\Assets\\" + image)) { System.Net.WebClient _WebClient = new System.Net.WebClient(); _WebClient.DownloadFile(urlpath + image, "Data\\Assets\\" + image); } Images[image] = new BitmapImage(new Uri("Data\\Assets\\" + image, UriKind.Relative)); if (update != null) update(count * 100 / Images.Count, 100); ++count; } }
public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { bool displayProgress = ( start != null && update != null && finish != null ); // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) ); JsonSerializerSettings jss = new JsonSerializerSettings { Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; var inTree = JsonConvert.DeserializeObject<PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss); int qindex = 0; foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) continue; iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) continue; iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } qindex = 0; foreach(var ass in inTree.assets) { assets[ass.Key] = new Asset(ass.Key,ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First()); } if ( displayProgress ) start( ); iconActiveSkills.OpenOrDownloadImages(update ); iconInActiveSkills.OpenOrDownloadImages(update ); if ( displayProgress ) finish( ); foreach( var c in inTree.characterData) { CharBaseAttributes[c.Key] = new Dictionary<string, float>() { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } }; } foreach (var nd in inTree.nodes) { Skillnodes.Add(nd.id, new SkillTree.SkillNode() { id = nd.id, name = nd.dn, attributes = nd.sd, orbit = nd.o, orbitIndex =nd.oidx, icon = nd.icon, linkID =nd.ot, g = nd.g, da = nd.da, ia = nd.ia, ks = nd.ks, not = nd.not, sa = nd.sa, Mastery = nd.m, spc=nd.spc.Count()>0?(int?)nd.spc[0]:null }); } List<ushort[]> links = new List<ushort[]>( ); foreach ( var skillNode in Skillnodes ) { foreach ( ushort i in skillNode.Value.linkID ) { if ( links.Count( nd => ( nd[ 0 ] == i && nd[ 1 ] == skillNode.Key ) || nd[ 0 ] == skillNode.Key && nd[ 1 ] == i ) == 1 ) { continue; } links.Add( new ushort[] { skillNode.Key , i } ); } } foreach ( ushort[] ints in links ) { if ( !Skillnodes[ ints[ 0 ] ].Neighbor.Contains( Skillnodes[ ints[ 1 ] ] ) ) Skillnodes[ ints[ 0 ] ].Neighbor.Add( Skillnodes[ ints[ 1 ] ] ); if ( !Skillnodes[ ints[ 1 ] ].Neighbor.Contains( Skillnodes[ ints[ 0 ] ] ) ) Skillnodes[ ints[ 1 ] ].Neighbor.Add( Skillnodes[ ints[ 0 ] ] ); } foreach(var gp in inTree.groups ) { NodeGroup ng = new NodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); ng.Nodes = gp.Value.n; NodeGroups.Add(ng); } foreach ( SkillTree.NodeGroup group in NodeGroups ) { foreach ( ushort node in group.Nodes ) { Skillnodes[ node ].NodeGroup = group; } } TRect = new Rect2D( new Vector2D( inTree.min_x * 1.1 , inTree.min_y * 1.1 ) , new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1)); InitNodeSurround( ); DrawNodeSurround( ); DrawNodeBaseSurround( ); DrawSkillIconLayer( ); DrawBackgroundLayer( ); InitFaceBrushesAndLayer( ); DrawLinkBackgroundLayer( links ); InitOtherDynamicLayers( ); CreateCombineVisual( ); Regex regexAttrib = new Regex( "[0-9]*\\.?[0-9]+" ); foreach ( var skillNode in Skillnodes ) { skillNode.Value.Attributes = new Dictionary<string , List<float>>( ); foreach ( string s in skillNode.Value.attributes ) { List<float> values = new List<float>( ); foreach ( Match m in regexAttrib.Matches( s ) ) { if ( !AttributeTypes.Contains( regexAttrib.Replace( s , "#" ) ) ) AttributeTypes.Add( regexAttrib.Replace( s , "#" ) ); if ( m.Value == "" ) values.Add( float.NaN ); else values.Add( float.Parse( m.Value , System.Globalization.CultureInfo.InvariantCulture ) ); } string cs = ( regexAttrib.Replace( s , "#" ) ); skillNode.Value.Attributes[ cs ] = values; } } }
public static SkillTree CreateSkillTree(StartLoadingWindow start = null, UpdateLoadingWindow update = null, CloseLoadingWindow finish = null) { AssetsFolderPath = AppData.GetFolder(Path.Combine("Data", "Assets"), true); DataFolderPath = AppData.GetFolder("Data", true); string skillTreeFile = DataFolderPath + "Skilltree.txt"; string skilltreeobj = ""; if (File.Exists(skillTreeFile)) { skilltreeobj = File.ReadAllText(skillTreeFile); } bool displayProgress = false; if (skilltreeobj == "") { displayProgress = (start != null && update != null && finish != null); if (displayProgress) start(L10n.Message("Downloading Skill tree assets")); string uriString = SkillTree.TreeAddress; var req = (HttpWebRequest)WebRequest.Create(uriString); var resp = (HttpWebResponse)req.GetResponse(); string code = new StreamReader(resp.GetResponseStream()).ReadToEnd(); var regex = new Regex("var passiveSkillTreeData.*"); skilltreeobj = regex.Match(code).Value.Replace("\\/", "/"); skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 1) + ""; File.WriteAllText(skillTreeFile, skilltreeobj); } if (displayProgress) update(25, 100); var skillTree = new SkillTree(skilltreeobj, displayProgress, update); if (displayProgress) finish(); return skillTree; }
public SkillTree(String treestring, bool displayProgress, UpdateLoadingWindow update) { PoESkillTree inTree = null; if (!_Initialized) { var jss = new JsonSerializerSettings { Error = delegate(object sender, ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; inTree = JsonConvert.DeserializeObject<PoESkillTree>(treestring, jss); } int qindex = 0; if (!_Initialized) { SkillTree._IconInActiveSkills = new SkillIcons(); //TODO: (SpaceOgre) This is not used atm, so no need to run it. foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) continue; _IconInActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { _IconInActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } } if (!_Initialized) { SkillTree._IconActiveSkills = new SkillIcons(); foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) continue; _IconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { _IconActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } } if (!_Initialized) { foreach (var ass in inTree.assets) { _assets[ass.Key] = new Asset(ass.Key, ass.Value.ContainsKey(0.3835f) ? ass.Value[0.3835f] : ass.Value.Values.First()); } } if (!_Initialized) { _rootNodeList = new List<int>(); if (inTree.root != null) { foreach (int i in inTree.root.ot) { _rootNodeList.Add(i); } } else if (inTree.main != null) { foreach (int i in inTree.main.ot) { _rootNodeList.Add(i); } } } if (displayProgress) update(50, 100); if (!_Initialized) _IconActiveSkills.OpenOrDownloadImages(update); if (displayProgress) update(75, 100); if (!_Initialized) _IconInActiveSkills.OpenOrDownloadImages(update); if (!_Initialized) { _CharBaseAttributes = new Dictionary<string, float>[7]; foreach (var c in inTree.characterData) { _CharBaseAttributes[c.Key] = new Dictionary<string, float> { {"+# to Strength", c.Value.base_str}, {"+# to Dexterity", c.Value.base_dex}, {"+# to Intelligence", c.Value.base_int} }; } } if (!_Initialized) { _Skillnodes = new Dictionary<ushort, SkillNode>(); _rootNodeClassDictionary = new Dictionary<string, int>(); _startNodeDictionary = new Dictionary<int, int>(); foreach (Node nd in inTree.nodes) { _Skillnodes.Add(nd.id, new SkillNode { Id = nd.id, Name = nd.dn, attributes = nd.dn.Contains("Jewel Socket") ? new string[1] { "+1 Jewel Socket" } : SplitMultilineAttributes(nd.sd), Orbit = nd.o, OrbitIndex = nd.oidx, Icon = nd.icon, LinkId = nd.ot, G = nd.g, Da = nd.da, Ia = nd.ia, IsKeyStone = nd.ks, IsNotable = nd.not, IsJewelSocket = nd.dn.Contains("Jewel Socket"), Sa = nd.sa, IsMastery = nd.m, Spc = nd.spc.Count() > 0 ? (int?)nd.spc[0] : null }); if (_rootNodeList.Contains(nd.id)) { if (!_rootNodeClassDictionary.ContainsKey(nd.dn.ToString().ToUpperInvariant())) { _rootNodeClassDictionary.Add(nd.dn.ToString().ToUpperInvariant(), nd.id); } foreach (int linkedNode in nd.ot) { if (!_startNodeDictionary.ContainsKey(nd.id)) { _startNodeDictionary.Add(linkedNode, nd.id); } } } foreach (int node in nd.ot) { if (!_startNodeDictionary.ContainsKey(nd.id) && _rootNodeList.Contains(node)) { _startNodeDictionary.Add(nd.id, node); } } } foreach (var skillNode in Skillnodes) { foreach (ushort i in skillNode.Value.LinkId) { if ( _links.Count(nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) == 1) { continue; } _links.Add(new[] { skillNode.Key, i }); } } foreach (var ints in _links) { if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]])) Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]); if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]])) Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]); } } if (!_Initialized) { _NodeGroups = new List<SkillNodeGroup>(); foreach (var gp in inTree.groups) { var ng = new SkillNodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); foreach (ushort node in gp.Value.n) { ng.Nodes.Add(Skillnodes[node]); } NodeGroups.Add(ng); } foreach (SkillNodeGroup group in NodeGroups) { foreach (SkillNode node in group.Nodes) { node.SkillNodeGroup = group; } } } if (!_Initialized) { const int padding = 500; //This is to account for jewel range circles. Might need to find a better way to do it. _TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1 - padding, inTree.min_y * 1.1 - padding), new Vector2D(inTree.max_x * 1.1 + padding, inTree.max_y * 1.1 + padding)); } InitNodeSurround();// DrawNodeSurround(); DrawNodeBaseSurround(); InitSkillIconLayers(); DrawSkillIconLayer(); DrawBackgroundLayer(); InitFaceBrushesAndLayer(); DrawLinkBackgroundLayer(_links); InitOtherDynamicLayers(); CreateCombineVisual(); if (_links != null) { var regexAttrib = new Regex("[0-9]*\\.?[0-9]+"); foreach (var skillNode in Skillnodes) { skillNode.Value.Attributes = new Dictionary<string, List<float>>(); foreach (string s in skillNode.Value.attributes) { var values = new List<float>(); foreach (Match m in regexAttrib.Matches(s)) { if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#"))) AttributeTypes.Add(regexAttrib.Replace(s, "#")); if (m.Value == "") values.Add(float.NaN); else values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture)); } string cs = (regexAttrib.Replace(s, "#")); skillNode.Value.Attributes[cs] = values; } } } if (displayProgress) update(100, 100); _Initialized = true; }