public static bool ProcessMap(string heightMapPath, int finalXSize, int finalYSize, int heightAdjust, float colourToHeightRatio, int type, MapStore gennedTypes, System.Windows.Forms.ListBox gennedTypesWindow) //Eventually, we're going to need to pass arguments! { //Load our bitmap Bitmap heightmap = null; try { heightmap = new Bitmap(heightMapPath); } catch { System.Windows.Forms.MessageBox.Show("Failed to load image - are you sure it's a valid bitmap?"); return(false); } //Resize the image Bitmap heightmapResized = new Bitmap(finalXSize, finalYSize); Graphics resizer = Graphics.FromImage((Image)heightmapResized); resizer.DrawImage(heightmap, 0, 0, finalXSize, finalYSize); //TODO: Change the resolution if need be //Store it in a legible array int[,] imageArray = new int[finalXSize, finalYSize]; for (int x = 0; x < finalXSize; x++) { for (int y = 0; y < finalYSize; y++) { float averagedPixel = ((heightmapResized.GetPixel(x, y).R) + (heightmapResized.GetPixel(x, y).G) + (heightmapResized.GetPixel(x, y).B)) / 3; averagedPixel = (averagedPixel * colourToHeightRatio) + heightAdjust; imageArray[x, y] = (int)averagedPixel; } } if (gennedTypes.getItem(type) == null) { switch (type) { case (int)ImportType.ELEV: gennedTypesWindow.Items.Add("Elevation"); break; case (int)ImportType.RAIN: gennedTypesWindow.Items.Add("Rainfall"); break; case (int)ImportType.TEMP: gennedTypesWindow.Items.Add("Temperature"); break; case (int)ImportType.DRAIN: gennedTypesWindow.Items.Add("Drainage"); break; case (int)ImportType.SAV: gennedTypesWindow.Items.Add("Savagery"); break; case (int)ImportType.VOLC: gennedTypesWindow.Items.Add("Volcanicity"); break; } } //Stuff it into our storage collection gennedTypes.setItem(type, imageArray); System.Windows.Forms.MessageBox.Show("Added to the array!"); return(true); }
public static void CommitToFile(int finalXSize, int finalYSize, string mapname, MapStore finishedTypes, string worldGenFilePath) { StreamWriter SW; SW = File.AppendText(worldGenFilePath); SW.WriteLine(); int squares = finalXSize * finalYSize; if (squares <= 289) { SW.Write(WorldGenTemplate.GetPocketSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 289) { SW.Write(WorldGenTemplate.GetSmallerSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 1089) { SW.Write(WorldGenTemplate.GetSmallSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 4225) { SW.Write(WorldGenTemplate.GetMediumSettings(mapname, finalXSize, finalYSize)); } else { SW.Write(WorldGenTemplate.GetLargeSettings(mapname, finalXSize, finalYSize)); } //SW.Write(); //Now write the remaining types for (int i = 0; i < 6; i++) { int[,] heightMap = finishedTypes.getItem(i); if (heightMap != null) { string dataType = string.Empty; switch (i) { case (int)ImportType.ELEV: dataType = "[PS_EL"; break; case (int)ImportType.RAIN: dataType = "[PS_RF"; break; case (int)ImportType.TEMP: dataType = "[PS_TP"; break; case (int)ImportType.DRAIN: dataType = "[PS_DR"; break; case (int)ImportType.SAV: dataType = "[PS_SV"; break; case (int)ImportType.VOLC: dataType = "[PS_VL"; break; } for (int y = 0; y < finalYSize; y++) { SW.WriteLine(); SW.Write(dataType); for (int x = 0; x < finalXSize; x++) { SW.Write(":"); SW.Write(heightMap[x, y]); } SW.Write("]"); } } } SW.Close(); System.Windows.Forms.MessageBox.Show("Saved!"); }
public static void CommitToFile(int finalXSize, int finalYSize, string mapname, MapStore finishedTypes, string worldGenFilePath) { StreamWriter SW; SW = File.AppendText(worldGenFilePath); SW.WriteLine(); int squares = finalXSize * finalYSize; if (squares <= 289) { SW.Write(WorldGenTemplate.GetPocketSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 289) { SW.Write(WorldGenTemplate.GetSmallerSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 1089) { SW.Write(WorldGenTemplate.GetSmallSettings(mapname, finalXSize, finalYSize)); } else if (squares <= 4225) { SW.Write(WorldGenTemplate.GetMediumSettings(mapname, finalXSize, finalYSize)); } else { SW.Write(WorldGenTemplate.GetLargeSettings(mapname, finalXSize, finalYSize)); } //SW.Write(); //Now write the remaining types for (int i = 0; i < 6; i++) { int[,] heightMap = finishedTypes.getItem(i); if (heightMap != null) { string dataType = string.Empty; switch (i) { case (int)ImportType.ELEV: dataType = "[PS_EL"; break; case (int)ImportType.RAIN: dataType = "[PS_RF"; break; case (int)ImportType.TEMP: dataType = "[PS_TP"; break; case (int)ImportType.DRAIN: dataType = "[PS_DR"; break; case (int)ImportType.SAV: dataType = "[PS_SV"; break; case (int)ImportType.VOLC: dataType = "[PS_VL"; break; } for (int y = 0; y < finalYSize; y++) { SW.WriteLine(); SW.Write(dataType); for (int x = 0; x < finalXSize; x++) { SW.Write(":"); SW.Write(heightMap[x, y]); } SW.Write("]"); } } } SW.Close(); System.Windows.Forms.MessageBox.Show("Saved!"); }
//Eventually, we're going to need to pass arguments! public static bool ProcessMap(string heightMapPath, int finalXSize, int finalYSize, int heightAdjust, float colourToHeightRatio, int type, MapStore gennedTypes, System.Windows.Forms.ListBox gennedTypesWindow) { //Load our bitmap Bitmap heightmap = null; try { heightmap = new Bitmap(heightMapPath); } catch { System.Windows.Forms.MessageBox.Show("Failed to load image - are you sure it's a valid bitmap?"); return false; } //Resize the image Bitmap heightmapResized = new Bitmap(finalXSize, finalYSize); Graphics resizer = Graphics.FromImage( (Image) heightmapResized ); resizer.DrawImage( heightmap, 0, 0, finalXSize, finalYSize ); //TODO: Change the resolution if need be //Store it in a legible array int[,] imageArray = new int[finalXSize, finalYSize]; for (int x = 0; x < finalXSize; x++) { for (int y = 0; y < finalYSize; y++) { float averagedPixel = ((heightmapResized.GetPixel(x, y).R) + (heightmapResized.GetPixel(x, y).G) + (heightmapResized.GetPixel(x, y).B)) / 3; averagedPixel = (averagedPixel * colourToHeightRatio) + heightAdjust; imageArray[x, y] = (int)averagedPixel; } } if (gennedTypes.getItem(type) == null) { switch (type) { case (int)ImportType.ELEV: gennedTypesWindow.Items.Add("Elevation"); break; case (int)ImportType.RAIN: gennedTypesWindow.Items.Add("Rainfall"); break; case (int)ImportType.TEMP: gennedTypesWindow.Items.Add("Temperature"); break; case (int)ImportType.DRAIN: gennedTypesWindow.Items.Add("Drainage"); break; case (int)ImportType.SAV: gennedTypesWindow.Items.Add("Savagery"); break; case (int)ImportType.VOLC: gennedTypesWindow.Items.Add("Volcanicity"); break; } } //Stuff it into our storage collection gennedTypes.setItem(type, imageArray); System.Windows.Forms.MessageBox.Show("Added to the array!"); return true; }
public void DisplayMap(int xSize, int ySize, int type, MapStore gennedTypes) { visualisedPictureBox.Image = (Image)HeightmapProcessing.GenerateBitmapFromData(xSize, ySize, type, gennedTypes.getItem(type)); this.Show(); }