public static AnalyzeMap Load_1_2(XPathNavigator nav) { IXmlNamespaceResolver resolver = new MyNamespaceResolver(); XPathNavigator root = nav.SelectSingleNode("//atm:AnalyzeMap", resolver); Double w = (Double) root.Evaluate("number(@width)"); Double h = (Double) root.Evaluate("number(@height)"); AnalyzeMap map = new AnalyzeMap((int)w, (int)h); XPathNodeIterator iter; iter = root.Select("atm:Tile", resolver); while (iter.MoveNext()) { int x = (int)(Double)iter.Current.Evaluate("number(@x)"); int y = (int)(Double)iter.Current.Evaluate("number(@y)"); String type = (String)iter.Current.Evaluate("string(@type)"); String quality = (String)iter.Current.Evaluate("string(@quality)"); Boolean hasSalt = (Boolean)iter.Current.Evaluate("@salt = 'true'"); Boolean hasFlint = (Boolean)iter.Current.Evaluate("@flint = 'true'"); if (map.IsValidTile(x, y)) { map[x, y].Type = (TileType)Enum.Parse(typeof(TileType), type); int exactQL; if (quality != null && quality.Length != 0) { if (Int32.TryParse(quality, out exactQL)) { map[x, y].ExactQuality = exactQL; } else { map[x, y].Quality = (Quality)Enum.Parse(typeof(Quality), quality); } } if (hasSalt) map[x, y].HasSalt = true; if (hasFlint) map[x, y].HasFlint = true; } else { throw new Exception(String.Format("Tile {0},{1} is not valid for the map", x, y)); } } iter = root.Select("atm:Analyze", resolver); while (iter.MoveNext()) { int x = (int)(Double)iter.Current.Evaluate("number(@x)"); int y = (int)(Double)iter.Current.Evaluate("number(@y)"); List<AnalyzeMatch> matches = new List<AnalyzeMatch>(); XPathNodeIterator entry = iter.Current.Select("atm:Entry", resolver); while (entry.MoveNext()) { String type = (String)entry.Current.Evaluate("string(@type)"); String quality = (String)entry.Current.Evaluate("string(@quality)"); String direction = (String)entry.Current.Evaluate("string(@direction)"); int distance = (int)(Double)entry.Current.Evaluate("number(@distance)"); if (type != null && type.Length == 0) type = null; if (quality != null && quality.Length == 0) quality = null; if (direction != null && direction.Length == 0) direction = null; matches.Add(new AnalyzeMatch(distance, type, quality, direction)); } AnalyzeResult result = new AnalyzeResult(matches); result.X = x; result.Y = y; map.SetResult(x, y, result); } return map; }
public static AnalyzeMap Load_1_2(XPathNavigator nav) { IXmlNamespaceResolver resolver = new MyNamespaceResolver(); XPathNavigator root = nav.SelectSingleNode("//atm:AnalyzeMap", resolver); Double w = (Double)root.Evaluate("number(@width)"); Double h = (Double)root.Evaluate("number(@height)"); AnalyzeMap map = new AnalyzeMap((int)w, (int)h); XPathNodeIterator iter; iter = root.Select("atm:Tile", resolver); while (iter.MoveNext()) { int x = (int)(Double)iter.Current.Evaluate("number(@x)"); int y = (int)(Double)iter.Current.Evaluate("number(@y)"); String type = (String)iter.Current.Evaluate("string(@type)"); String quality = (String)iter.Current.Evaluate("string(@quality)"); Boolean hasSalt = (Boolean)iter.Current.Evaluate("@salt = 'true'"); Boolean hasFlint = (Boolean)iter.Current.Evaluate("@flint = 'true'"); if (map.IsValidTile(x, y)) { map[x, y].Type = (TileType)Enum.Parse(typeof(TileType), type); int exactQL; if (quality != null && quality.Length != 0) { if (Int32.TryParse(quality, out exactQL)) { map[x, y].ExactQuality = exactQL; } else { map[x, y].Quality = (Quality)Enum.Parse(typeof(Quality), quality); } } if (hasSalt) { map[x, y].HasSalt = true; } if (hasFlint) { map[x, y].HasFlint = true; } } else { throw new Exception(String.Format("Tile {0},{1} is not valid for the map", x, y)); } } iter = root.Select("atm:Analyze", resolver); while (iter.MoveNext()) { int x = (int)(Double)iter.Current.Evaluate("number(@x)"); int y = (int)(Double)iter.Current.Evaluate("number(@y)"); List <AnalyzeMatch> matches = new List <AnalyzeMatch>(); XPathNodeIterator entry = iter.Current.Select("atm:Entry", resolver); while (entry.MoveNext()) { String type = (String)entry.Current.Evaluate("string(@type)"); String quality = (String)entry.Current.Evaluate("string(@quality)"); String direction = (String)entry.Current.Evaluate("string(@direction)"); int distance = (int)(Double)entry.Current.Evaluate("number(@distance)"); if (type != null && type.Length == 0) { type = null; } if (quality != null && quality.Length == 0) { quality = null; } if (direction != null && direction.Length == 0) { direction = null; } matches.Add(new AnalyzeMatch(distance, type, quality, direction)); } AnalyzeResult result = new AnalyzeResult(matches); result.X = x; result.Y = y; map.SetResult(x, y, result); } return(map); }