/// <summary> /// Loads a savedgame file /// </summary> /// <returns>True on success</returns> public bool Load() { // File not found if (!System.IO.File.Exists(FileName)) { Trace.WriteLine("[SaveGame]Read() : Unable to find file \"" + FileName + "\" !"); return(false); } // Flush slots for (int i = 0; i < GameSettings.MaxGameSaveSlot; i++) { Slots[i] = new SaveGameSlot(); } // Open document XmlDocument xml = new XmlDocument(); xml.Load(FileName); // Bad tag if (xml.DocumentElement.Name != Tag) { Trace.WriteLine("[SaveGame]Read() : Bad file format !"); return(false); } // Load the right slot foreach (XmlNode node in xml.DocumentElement) { switch (node.Name) { #region slot case "slot": { int id = int.Parse(node.Attributes["id"].Value); Slots[id].Name = node.Attributes["name"].Value; foreach (XmlNode sub in node) { switch (sub.Name) { case "team": { Slots[id].Team = sub; } break; case "dungeon": { Slots[id].Dungeon = sub; } break; } } } break; #endregion case "dungeon": { DungeonName = node.Attributes["name"].Value; } break; } } return(true); }
/// <summary> /// Loads a savedgame file /// </summary> /// <returns>True on success</returns> public bool Load() { // File not found if (!System.IO.File.Exists(FileName)) { Trace.WriteLine("[SaveGame]Read() : Unable to find file \"" + FileName + "\" !"); return false; } // Flush slots for (int i = 0; i < GameSettings.MaxGameSaveSlot; i++) Slots[i] = new SaveGameSlot(); // Open document XmlDocument xml = new XmlDocument(); xml.Load(FileName); // Bad tag if (xml.DocumentElement.Name != Tag) { Trace.WriteLine("[SaveGame]Read() : Bad file format !"); return false; } // Load the right slot foreach (XmlNode node in xml.DocumentElement) { switch (node.Name) { #region slot case "slot": { int id = int.Parse(node.Attributes["id"].Value); Slots[id].Name = node.Attributes["name"].Value; foreach (XmlNode sub in node) { switch (sub.Name) { case "team": { Slots[id].Team = sub; } break; case "dungeon": { Slots[id].Dungeon = sub; } break; } } } break; #endregion case "dungeon": { DungeonName = node.Attributes["name"].Value; } break; } } return true; }
/// <summary> /// Constructor /// </summary> /// <param name="filename">Savegame filename</param> public SaveGame(string filename) { FileName = filename; Slots = new SaveGameSlot[GameSettings.MaxGameSaveSlot]; }