/// <summary> /// Handles the Click event of the SaveAsToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); saveFileDialog.Filter = "Level Files (*.lvl)|*.lvl|All Files (*.*)|*.*"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string FileName = saveFileDialog.FileName; if (saveFileDialog.FileName.EndsWith("lvl")) { MapManagerXML MapManager = new MapManagerXML(); MapForm activeForm = (MapForm)this.ActiveMdiChild; if (activeForm == null) { MessageBox.Show("Null!"); } activeForm.Text = FileName; MapManager.Save(FileName, activeForm.Map, null); activeForm.Map.Levelfilename = FileName; } else { MessageBox.Show("Unsupported file format!"); } } }
/// <summary> /// Handles the Click event of the saveToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void saveToolStripMenuItem_Click(object sender, EventArgs e) { MapForm activeForm = (MapForm)this.ActiveMdiChild; if (activeForm == null) { return; } if (activeForm.Map.Levelfilename == null) { SaveAsToolStripMenuItem_Click(sender, e); } else { MapManagerXML MapManager = new MapManagerXML(); MapManager.Save(activeForm.Map.Levelfilename, activeForm.Map, null); } }
/// <summary> /// Tests the saving and loading functions /// </summary> /// <returns></returns> private bool MapSaveLoadTest(Map map) { MapManagerXML mapManager = new MapManagerXML(); try { Console.WriteLine(" - Saving map"); mapManager.Save("UnitTest.lvl", map, null); Console.WriteLine(" - Loading map"); Map newmap = mapManager.Load("UnitTest.lvl"); // Compare maps (Map.Equals() not implemented) bool result = true; bool fieldtest = true; bool paramtest = true; bool objecttest = true; Console.WriteLine(" - Comparing fields"); // Compare fields for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { if (!map.GetField(x, y).Equals(newmap.GetField(x, y))) { fieldtest = false; } } } if (!fieldtest) { result = ErrorMessage("Failed: Field test, "); } // Compare parameters if (map.StartX != newmap.StartX) { paramtest = false; } if (map.StartY != newmap.StartY) { paramtest = false; } if (map.Version != newmap.Version) { paramtest = false; } if (map.Width != newmap.Width) { paramtest = false; } if (map.Height != newmap.Height) { paramtest = false; } if (map.Author != newmap.Author) { paramtest = false; } if (!paramtest) { result = ErrorMessage("Failed: Parameters, "); } bool objectexists; Console.Write(" - Comparing objects."); // Compare objects int j = 0; foreach (IMapObject obj in map.GetObjects()) { objectexists = false; j++; if (j % 1000 == 0) { Console.Write("."); } foreach (IMapObject obj2 in newmap.GetObjects()) { if (obj.Equals(obj2)) { objectexists = true; } } if (!objectexists) { objecttest = false; } } Console.WriteLine(); if (!objecttest) { result = ErrorMessage("Failed: Objects, "); } return(result); } catch (Exception ex) { infoMessage += ex.Message; return(false); } }