/*************************************************************FILE HANDLING*/ /*************************************************************FILE HANDLING*/ /*************************************************************FILE HANDLING*/ // Regular "Save" method. public void SaveMap() { // Check if this map has a name, meaning it has been saved before. If it hasn't, promt the user to name it using the "SaveAs()" method. if (map.GetMapName() == null) { SaveAs(); } else { MapIO.SaveMap(map); } }
/********************************OUTPUT*/ /********************************OUTPUT*/ /********************************OUTPUT*/ /********************************OUTPUT*/ // Saves the supplied map to the supplied mapName path. public static void SaveMap(Map map) { // Create a string builder to store all of the map information. StringBuilder guts = new StringBuilder(); // Create a string builder to store all of the images to load for this map. StringBuilder imageNames = new StringBuilder(); // Create a list to store all of the file names of every image in this map. List <String> images = new List <String>(); /*********************************BUILD OUTPUT STRING*/ // Begin by writing a commented title to the text file. imageNames.AppendLine(MapIO.COMMENT + " Map file for: " + Path.GetFileNameWithoutExtension(map.GetMapName())); imageNames.AppendLine(); // Let the map loader know it's tile to load images. imageNames.AppendLine(MapIO.IMAGE_LOAD); // Let the map loader know it's time to load the map information. guts.AppendLine(); guts.AppendLine(MapIO.MAP_LOAD); // Write map dimensions. guts.AppendLine("" + map.GetColumns()); guts.AppendLine("" + map.GetRows()); // Write tile information. for (int i = 0; i < map.GetColumns(); i++) { for (int j = 0; j < map.GetRows(); j++) { // Write the tile coordinates. guts.AppendLine("" + i); guts.AppendLine("" + j); /* Cycle through each layer of the tile and write down the image names. Goes in this layer order: * Floor * Wall * Decor */ for (int x = 0; x < map.GetTiles()[i, j].GetImageKeys().Length; x++) { guts.AppendLine("" + map.GetTiles()[i, j].GetImageKeys()[x]); } // Store this tile's images into the library. FileImages(map.GetTiles()[i, j], images); } } // Mark the end of the map load. guts.AppendLine(MapIO.MAP_CLOSE); // Mark the end of the save file. guts.AppendLine(MapIO.CLOSE_FILE); // Write down all of the images used in this map. foreach (String name in images) { if (name != Tile.NO_IMAGE) { imageNames.AppendLine("" + name); } } // Terminate the image load sequence. imageNames.AppendLine(MapIO.IMAGE_CLOSE); imageNames.Append(guts.ToString()); // Dump everything into a text file. System.IO.File.WriteAllText(map.GetMapName(), imageNames.ToString()); MessageBox.Show("Map Saved."); }
/********************************OUTPUT*/ /********************************OUTPUT*/ /********************************OUTPUT*/ /********************************OUTPUT*/ // Saves the supplied map to the supplied mapName path. public static void SaveMap(Map map) { // Create a string builder to store all of the map information. StringBuilder guts = new StringBuilder(); // Create a string builder to store all of the images to load for this map. StringBuilder imageNames = new StringBuilder(); // Create a list to store all of the file names of every image in this map. List<String> images = new List<String>(); /*********************************BUILD OUTPUT STRING*/ // Begin by writing a commented title to the text file. imageNames.AppendLine(MapIO.COMMENT + " Map file for: " + Path.GetFileNameWithoutExtension(map.GetMapName())); imageNames.AppendLine(); // Let the map loader know it's tile to load images. imageNames.AppendLine(MapIO.IMAGE_LOAD); // Let the map loader know it's time to load the map information. guts.AppendLine(); guts.AppendLine(MapIO.MAP_LOAD); // Write map dimensions. guts.AppendLine("" + map.GetColumns()); guts.AppendLine("" + map.GetRows()); // Write tile information. for (int i = 0; i < map.GetColumns(); i++) { for (int j = 0; j < map.GetRows(); j++) { // Write the tile coordinates. guts.AppendLine("" + i); guts.AppendLine("" + j); /* Cycle through each layer of the tile and write down the image names. Goes in this layer order: * Floor * Wall * Decor */ for (int x = 0; x < map.GetTiles()[i, j].GetImageKeys().Length; x++) guts.AppendLine("" + map.GetTiles()[i,j].GetImageKeys()[x]); // Store this tile's images into the library. FileImages(map.GetTiles()[i, j], images); } } // Mark the end of the map load. guts.AppendLine(MapIO.MAP_CLOSE); // Mark the end of the save file. guts.AppendLine(MapIO.CLOSE_FILE); // Write down all of the images used in this map. foreach (String name in images) { if(name != Tile.NO_IMAGE) imageNames.AppendLine("" + name); } // Terminate the image load sequence. imageNames.AppendLine(MapIO.IMAGE_CLOSE); imageNames.Append(guts.ToString()); // Dump everything into a text file. System.IO.File.WriteAllText(map.GetMapName(), imageNames.ToString()); MessageBox.Show("Map Saved."); }