/// <summary> /// Constructor. /// </summary> public GridForm() { InitializeComponent(); // an empty map. _mapEditor.CurrentMap = MapFactory.BuildNew(); // load the sheet _sheetEditor.CurrentSheet = SheetFactory.LoadSheetFromFile(); // setup form components RefreshDisplay(); }
/// <summary> /// Returns a new Sheet object instantiated from the .xml storage file. /// </summary> public static Sheet LoadSheetFromFile() { Sheet loadedSheet = SheetFactory.GetBlank(); try { string fileName = Path.Combine(Environment.CurrentDirectory, SheetEditor.SheetFileName); if (File.Exists(fileName)) { FileStream fs = new FileStream(fileName, FileMode.Open); XmlReader reader = XmlReader.Create(fs); XmlSerializer xml = new XmlSerializer(typeof(Sheet)); loadedSheet = (Sheet)xml.Deserialize(reader); reader.Close(); fs.Close(); } return(loadedSheet); } catch (Exception e) { throw new Exception("Failed loading sheets from .xml!", e); } }