private XmasWorldBuilder retreiveBuilderFromMap() { var type = typeof(MapTypes); var memInfo = type.GetMember(Map.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(MapTypeAttribute), false); var MapType = ((MapTypeAttribute)attributes[0]).Type; XmasWorldBuilder worldbuilder = (XmasWorldBuilder)Activator.CreateInstance(MapType); return(worldbuilder); }
/// <summary> /// Opens a Halo/Halo 2 based map for reading / writing (not readonly). /// </summary> /// <param name="type">MapTypes.(Internal, MainMenu, MPShared, SPShared, Bitmaps)</param> /// <param name="readOnly">opens map file as read-only (does NOT apply to internal map file)</param> /// <remarks></remarks> public void OpenMap(MapTypes type, bool readOnly) { if (isOpen && type == this.openMapType) { if (!(type != MapTypes.Internal && (FS.CanWrite == readOnly))) { return; } } CloseMap(); try { string temp = string.Empty; //int x = 0; switch (type) { case MapTypes.Internal: temp = filePath; break; case MapTypes.MainMenu: // x = filePath.LastIndexOf('\\'); // temp = filePath.Substring(0, x + 1) + "mainmenu.map"; temp = Prefs.pathMainmenu; if ((!Prefs.useDefaultMaps) && (filePath.LastIndexOf('\\') != -1)) { string currentMainMenu = filePath.Substring(0, filePath.LastIndexOf('\\') + 1) + "mainmenu.map"; if (File.Exists(currentMainMenu)) { temp = currentMainMenu; } } break; case MapTypes.MPShared: temp = Prefs.pathShared; if ((!Prefs.useDefaultMaps) && (filePath.LastIndexOf('\\') != -1)) { string currentMPShared = filePath.Substring(0, filePath.LastIndexOf('\\') + 1) + "shared.map"; if (File.Exists(currentMPShared)) { temp = currentMPShared; } } break; case MapTypes.SPShared: temp = Prefs.pathSPShared; if ((!Prefs.useDefaultMaps) && (filePath.LastIndexOf('\\') != -1)) { string currentSPShared = filePath.Substring(0, filePath.LastIndexOf('\\') + 1) + "single_player_shared.map"; if (File.Exists(currentSPShared)) { temp = currentSPShared; } } break; case MapTypes.Bitmaps: temp = Prefs.pathBitmaps; break; } FileAccess fa = FileAccess.Read; if (type == MapTypes.Internal) { fa = FileAccess.ReadWrite; } if (type != MapTypes.Internal && !readOnly) { if ( MessageBox.Show( "You are about to write to a shared file\n" + temp + "\nContinue?", "Write to shared file?", MessageBoxButtons.YesNo) == DialogResult.Yes) { fa = FileAccess.ReadWrite; } else { return; } } FS = new FileStream(temp, FileMode.Open, fa); BR = new BinaryReader(FS); if (fa != FileAccess.Read) { BW = new BinaryWriter(FS); } isOpen = true; openMapType = type; } catch (Exception ex) { if (type.ToString() == "Internal") { Global.ShowErrorMsg(filePath + " - Not Found\n", ex); } else { Global.ShowErrorMsg(type + " - Map Not Found\n", ex); } isOpen = false; } }
public string GetLatLngString(LatLng latLng, MapTypes map) { if (latLng == null) { throw new ValidationException("LatLng object is NULL", ValidationErrors.Empty); } if (latLng.IsSet == false) { return("0.000000,0.000000"); } double[] ar = new double[2]; switch (map) { case MapTypes.YandexMap: // Longitude and latitude in degrees; ar[0] = latLng.Lng; ar[1] = latLng.Lat; break; case MapTypes.GoogleMap: // comma-separated {latitude,longitude} pair ar[0] = latLng.Lat; ar[1] = latLng.Lng; break; default: throw new ValidationException("Could not convert LatLng to string for map: " + map.ToString(), ValidationErrors.IncorrectType); } return(String.Concat(ar[0].ToString("0.000000", CultureInfo.InvariantCulture), ",", ar[1].ToString("0.000000", CultureInfo.InvariantCulture))); }
public LatLng ParseLatLng(string s, MapTypes mapType) { // Assume that coordinates are comma or slash separated. And decimal separator is dot string[] ar = s.Split(",/".ToCharArray()); if (ar?.Length != 2) { throw new ValidationException("Expected 2 coordinates, separated with comma or slash. Error parsing incorrect string: " + s, ValidationErrors.NotEqual); } var ll = new LatLng(); switch (mapType) { case MapTypes.YandexMap: break; case MapTypes.GoogleMap: // Expected lattiude/longtitude ll.Lat = Double.Parse(ar[0], CultureInfo.InvariantCulture); ll.Lng = Double.Parse(ar[1], CultureInfo.InvariantCulture); break; default: throw new ValidationException("Could not parse string to LatLng for map type: " + mapType.ToString(), ValidationErrors.IncorrectType); } return(ll); }