/// <summary> /// Delete the save game specified by the description. /// </summary> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="saveGameDescription">The description of the save game.</param> public static void DeleteSaveGameResult(StorageDevice storageDevice, SaveGameDescription saveGameDescription) { if (saveGameDescription == null) { throw new ArgumentNullException("saveGameDescription"); } if (storageDevice == null) { throw new ArgumentNullException("storageDevice"); } if (!storageDevice.IsConnected) { throw new InvalidOperationException("Cannot connect to storage device."); } // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { storageContainer.DeleteFile(saveGameDescription.FileName); storageContainer.DeleteFile("SaveGameDescription" + Path.GetFileNameWithoutExtension(saveGameDescription.FileName).Substring(8) + ".xml"); } }
/// <summary> /// Save the current state of the session. /// </summary> /// <param name="overwriteDescription"> /// The description of the save game to over-write, if any. /// </param> public static void SaveDossier(SaveGameDescription overwriteDescription) { // retrieve the storage device, asynchronously GetStorageDevice(delegate(StorageDevice storageDevice) { SaveDossierResult(storageDevice, overwriteDescription); }); }
/// <summary> /// Delete the save game specified by the description. /// </summary> /// <param name="saveGameDescription">The description of the save game.</param> public static void DeleteSaveGame(SaveGameDescription saveGameDescription) { if (saveGameDescription == null) throw new ArgumentNullException("saveGameDescription"); // get the storage device and load the session GetStorageDevice( delegate(StorageDevice storageDevice) { DeleteSaveGameResult(storageDevice, saveGameDescription); }); }
/// <summary> /// Delete the save game specified by the description. /// </summary> /// <param name="saveGameDescription">The description of the save game.</param> public static void DeleteSaveGame(SaveGameDescription saveGameDescription) { if (saveGameDescription == null) { throw new ArgumentNullException("saveGameDescription"); } // get the storage device and load the session GetStorageDevice( delegate(StorageDevice storageDevice) { DeleteSaveGameResult(storageDevice, saveGameDescription); }); }
public static void LoadFromSaveFile(SaveGameDescription saveGameDescription, DossierLoadedDelegate dossierLoadedCallback) { if (saveGameDescription == null) { throw new ArgumentNullException("saveGameDescription"); } if (dossierLoadedCallback == null) { throw new ArgumentNullException("dossierLoadedCallback"); } // get the storage device and load the session GetStorageDevice(delegate(StorageDevice storageDevice) { GameDossier loadedDossier = LoadDossierResult(storageDevice, saveGameDescription); dossierLoadedCallback(loadedDossier); }); }
/// <summary> /// Delete the save game specified by the description. /// </summary> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="saveGameDescription">The description of the save game.</param> public static void DeleteSaveGameResult(StorageDevice storageDevice, SaveGameDescription saveGameDescription) { if (saveGameDescription == null) throw new ArgumentNullException("saveGameDescription"); if (storageDevice == null) throw new ArgumentNullException("storageDevice"); if (!storageDevice.IsConnected) throw new InvalidOperationException("Cannot connect to storage device."); // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { storageContainer.DeleteFile(saveGameDescription.FileName); storageContainer.DeleteFile("SaveGameDescription" + Path.GetFileNameWithoutExtension(saveGameDescription.FileName).Substring(8) + ".xml"); } }
/// <summary> /// Save the current state of the session, with the given storage device. /// </summary> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="overwriteDescription"> /// The description of the save game to over-write, if any. /// </param> private static void SaveDossierResult(StorageDevice storageDevice, SaveGameDescription overwriteDescription) { if (storageDevice == null) { throw new ArgumentNullException("storageDevice"); } if (!storageDevice.IsConnected) { throw new InvalidOperationException("Cannot connect to storage device."); } // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { string filename; string descriptionFilename; // get the filenames if (overwriteDescription == null) { int saveGameIndex = 0; string testFilename; do { saveGameIndex++; testFilename = "SaveGame" + saveGameIndex.ToString() + ".xml"; }while (storageContainer.FileExists(testFilename)); filename = testFilename; descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml"; } else { filename = overwriteDescription.FileName; descriptionFilename = "SaveGameDescription" + Path.GetFileNameWithoutExtension( overwriteDescription.FileName).Substring(8) + ".xml"; } using (Stream stream = storageContainer.OpenFile(filename, FileMode.Create)) { using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { // <Mechadrone1SaveData> xmlWriter.WriteStartElement("Mechadrone1SaveData"); /* * // write the map information * xmlWriter.WriteStartElement("mapData"); * xmlWriter.WriteElementString("mapContentName", * TileEngine.Map.AssetName); * new XmlSerializer(typeof(PlayerPosition)).Serialize( * xmlWriter, TileEngine.PartyLeaderPosition); * new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize( * xmlWriter, singleton.removedMapChests); * new XmlSerializer( * typeof(List<WorldEntry<FixedCombat>>)).Serialize( * xmlWriter, singleton.removedMapFixedCombats); * new XmlSerializer(typeof(List<WorldEntry<Player>>)).Serialize( * xmlWriter, singleton.removedMapPlayerNpcs); * new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize( * xmlWriter, singleton.modifiedMapChests); * xmlWriter.WriteEndElement(); * * // write the quest information * xmlWriter.WriteStartElement("questData"); * xmlWriter.WriteElementString("questLineContentName", * singleton.questLine.AssetName); * xmlWriter.WriteElementString("currentQuestIndex", * singleton.currentQuestIndex.ToString()); * new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize( * xmlWriter, singleton.removedQuestChests); * new XmlSerializer( * typeof(List<WorldEntry<FixedCombat>>)).Serialize( * xmlWriter, singleton.removedQuestFixedCombats); * new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize( * xmlWriter, singleton.modifiedQuestChests); * xmlWriter.WriteElementString("currentQuestStage", * IsQuestLineComplete ? * Quest.QuestStage.NotStarted.ToString() : * singleton.quest.Stage.ToString()); * xmlWriter.WriteEndElement(); * * // write the party data * new XmlSerializer(typeof(PartySaveData)).Serialize(xmlWriter, * new PartySaveData(singleton.party)); */ // </Mechadrone1SaveData> xmlWriter.WriteEndElement(); } } // create the save game description SaveGameDescription description = new SaveGameDescription(); description.FileName = Path.GetFileName(filename); description.ChapterName = "01 - Harrowmark"; description.Description = DateTime.Now.ToString(); using (Stream stream = storageContainer.OpenFile(descriptionFilename, FileMode.Create)) { new XmlSerializer(typeof(SaveGameDescription)).Serialize(stream, description); } } }
/// <summary> /// Receives the storage device and starts a new session, /// using the data in the given save game. /// </summary> /// <remarks>The new session is created in LoadSessionResult.</remarks> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="saveGameDescription">The description of the save game.</param> private static GameDossier LoadDossierResult(StorageDevice storageDevice, SaveGameDescription saveGameDescription) { if (saveGameDescription == null) { throw new ArgumentNullException("saveGameDescription"); } if (storageDevice == null) { throw new ArgumentNullException("storageDevice"); } if (!storageDevice.IsConnected) { throw new InvalidOperationException("Cannot connect to storage device."); } GameDossier loadedDossier = new GameDossier(); // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { using (Stream stream = storageContainer.OpenFile(saveGameDescription.FileName, FileMode.Open)) { using (XmlReader xmlReader = XmlReader.Create(stream)) { // <Mechadrone1SaveData> xmlReader.ReadStartElement("Mechadrone1SaveData"); /* * // read the map information * xmlReader.ReadStartElement("mapData"); * string mapAssetName = * xmlReader.ReadElementString("mapContentName"); * PlayerPosition playerPosition = new XmlSerializer( * typeof(PlayerPosition)).Deserialize(xmlReader) * as PlayerPosition; * singleton.removedMapChests = new XmlSerializer( * typeof(List<WorldEntry<Chest>>)).Deserialize(xmlReader) * as List<WorldEntry<Chest>>; * singleton.removedMapFixedCombats = new XmlSerializer( * typeof(List<WorldEntry<FixedCombat>>)).Deserialize(xmlReader) * as List<WorldEntry<FixedCombat>>; * singleton.removedMapPlayerNpcs = new XmlSerializer( * typeof(List<WorldEntry<Player>>)).Deserialize(xmlReader) * as List<WorldEntry<Player>>; * singleton.modifiedMapChests = new XmlSerializer( * typeof(List<ModifiedChestEntry>)).Deserialize(xmlReader) * as List<ModifiedChestEntry>; * ChangeMap(mapAssetName, null); * TileEngine.PartyLeaderPosition = playerPosition; * xmlReader.ReadEndElement(); * * // read the quest information * ContentManager content = Session.ScreenManager.Game.Content; * xmlReader.ReadStartElement("questData"); * singleton.questLine = content.Load<QuestLine>( * xmlReader.ReadElementString("questLineContentName")).Clone() * as QuestLine; * singleton.currentQuestIndex = Convert.ToInt32( * xmlReader.ReadElementString("currentQuestIndex")); * for (int i = 0; i < singleton.currentQuestIndex; i++) * { * singleton.questLine.Quests[i].Stage = * Quest.QuestStage.Completed; * } * singleton.removedQuestChests = new XmlSerializer( * typeof(List<WorldEntry<Chest>>)).Deserialize(xmlReader) * as List<WorldEntry<Chest>>; * singleton.removedQuestFixedCombats = new XmlSerializer( * typeof(List<WorldEntry<FixedCombat>>)).Deserialize(xmlReader) * as List<WorldEntry<FixedCombat>>; * singleton.modifiedQuestChests = new XmlSerializer( * typeof(List<ModifiedChestEntry>)).Deserialize(xmlReader) * as List<ModifiedChestEntry>; * Quest.QuestStage questStage = (Quest.QuestStage)Enum.Parse( * typeof(Quest.QuestStage), * xmlReader.ReadElementString("currentQuestStage"), true); * if ((singleton.questLine != null) && !IsQuestLineComplete) * { * singleton.quest = * singleton.questLine.Quests[CurrentQuestIndex]; * singleton.ModifyQuest(singleton.quest); * singleton.quest.Stage = questStage; * } * xmlReader.ReadEndElement(); * * // read the party data * singleton.party = new Party(new XmlSerializer( * typeof(PartySaveData)).Deserialize(xmlReader) * as PartySaveData, content); */ // </Mechadrone1SaveData> xmlReader.ReadEndElement(); } } } return(loadedDossier); }
/// <summary> /// Save the current state of the session, with the given storage device. /// </summary> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="overwriteDescription"> /// The description of the save game to over-write, if any. /// </param> private static void SaveDossierResult(StorageDevice storageDevice, SaveGameDescription overwriteDescription) { if (storageDevice == null) throw new ArgumentNullException("storageDevice"); if (!storageDevice.IsConnected) throw new InvalidOperationException("Cannot connect to storage device."); // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { string filename; string descriptionFilename; // get the filenames if (overwriteDescription == null) { int saveGameIndex = 0; string testFilename; do { saveGameIndex++; testFilename = "SaveGame" + saveGameIndex.ToString() + ".xml"; } while (storageContainer.FileExists(testFilename)); filename = testFilename; descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml"; } else { filename = overwriteDescription.FileName; descriptionFilename = "SaveGameDescription" + Path.GetFileNameWithoutExtension( overwriteDescription.FileName).Substring(8) + ".xml"; } using (Stream stream = storageContainer.OpenFile(filename, FileMode.Create)) { using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { // <Mechadrone1SaveData> xmlWriter.WriteStartElement("Mechadrone1SaveData"); /* // write the map information xmlWriter.WriteStartElement("mapData"); xmlWriter.WriteElementString("mapContentName", TileEngine.Map.AssetName); new XmlSerializer(typeof(PlayerPosition)).Serialize( xmlWriter, TileEngine.PartyLeaderPosition); new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize( xmlWriter, singleton.removedMapChests); new XmlSerializer( typeof(List<WorldEntry<FixedCombat>>)).Serialize( xmlWriter, singleton.removedMapFixedCombats); new XmlSerializer(typeof(List<WorldEntry<Player>>)).Serialize( xmlWriter, singleton.removedMapPlayerNpcs); new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize( xmlWriter, singleton.modifiedMapChests); xmlWriter.WriteEndElement(); // write the quest information xmlWriter.WriteStartElement("questData"); xmlWriter.WriteElementString("questLineContentName", singleton.questLine.AssetName); xmlWriter.WriteElementString("currentQuestIndex", singleton.currentQuestIndex.ToString()); new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize( xmlWriter, singleton.removedQuestChests); new XmlSerializer( typeof(List<WorldEntry<FixedCombat>>)).Serialize( xmlWriter, singleton.removedQuestFixedCombats); new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize( xmlWriter, singleton.modifiedQuestChests); xmlWriter.WriteElementString("currentQuestStage", IsQuestLineComplete ? Quest.QuestStage.NotStarted.ToString() : singleton.quest.Stage.ToString()); xmlWriter.WriteEndElement(); // write the party data new XmlSerializer(typeof(PartySaveData)).Serialize(xmlWriter, new PartySaveData(singleton.party)); */ // </Mechadrone1SaveData> xmlWriter.WriteEndElement(); } } // create the save game description SaveGameDescription description = new SaveGameDescription(); description.FileName = Path.GetFileName(filename); description.ChapterName = "01 - Harrowmark"; description.Description = DateTime.Now.ToString(); using (Stream stream = storageContainer.OpenFile(descriptionFilename, FileMode.Create)) { new XmlSerializer(typeof(SaveGameDescription)).Serialize(stream, description); } } }
/// <summary> /// Receives the storage device and starts a new session, /// using the data in the given save game. /// </summary> /// <remarks>The new session is created in LoadSessionResult.</remarks> /// <param name="storageDevice">The chosen storage device.</param> /// <param name="saveGameDescription">The description of the save game.</param> private static GameDossier LoadDossierResult(StorageDevice storageDevice, SaveGameDescription saveGameDescription) { if (saveGameDescription == null) throw new ArgumentNullException("saveGameDescription"); if (storageDevice == null) throw new ArgumentNullException("storageDevice"); if (!storageDevice.IsConnected) throw new InvalidOperationException("Cannot connect to storage device."); GameDossier loadedDossier = new GameDossier(); // open the container using (StorageContainer storageContainer = OpenContainer(storageDevice)) { using (Stream stream = storageContainer.OpenFile(saveGameDescription.FileName, FileMode.Open)) { using (XmlReader xmlReader = XmlReader.Create(stream)) { // <Mechadrone1SaveData> xmlReader.ReadStartElement("Mechadrone1SaveData"); /* // read the map information xmlReader.ReadStartElement("mapData"); string mapAssetName = xmlReader.ReadElementString("mapContentName"); PlayerPosition playerPosition = new XmlSerializer( typeof(PlayerPosition)).Deserialize(xmlReader) as PlayerPosition; singleton.removedMapChests = new XmlSerializer( typeof(List<WorldEntry<Chest>>)).Deserialize(xmlReader) as List<WorldEntry<Chest>>; singleton.removedMapFixedCombats = new XmlSerializer( typeof(List<WorldEntry<FixedCombat>>)).Deserialize(xmlReader) as List<WorldEntry<FixedCombat>>; singleton.removedMapPlayerNpcs = new XmlSerializer( typeof(List<WorldEntry<Player>>)).Deserialize(xmlReader) as List<WorldEntry<Player>>; singleton.modifiedMapChests = new XmlSerializer( typeof(List<ModifiedChestEntry>)).Deserialize(xmlReader) as List<ModifiedChestEntry>; ChangeMap(mapAssetName, null); TileEngine.PartyLeaderPosition = playerPosition; xmlReader.ReadEndElement(); // read the quest information ContentManager content = Session.ScreenManager.Game.Content; xmlReader.ReadStartElement("questData"); singleton.questLine = content.Load<QuestLine>( xmlReader.ReadElementString("questLineContentName")).Clone() as QuestLine; singleton.currentQuestIndex = Convert.ToInt32( xmlReader.ReadElementString("currentQuestIndex")); for (int i = 0; i < singleton.currentQuestIndex; i++) { singleton.questLine.Quests[i].Stage = Quest.QuestStage.Completed; } singleton.removedQuestChests = new XmlSerializer( typeof(List<WorldEntry<Chest>>)).Deserialize(xmlReader) as List<WorldEntry<Chest>>; singleton.removedQuestFixedCombats = new XmlSerializer( typeof(List<WorldEntry<FixedCombat>>)).Deserialize(xmlReader) as List<WorldEntry<FixedCombat>>; singleton.modifiedQuestChests = new XmlSerializer( typeof(List<ModifiedChestEntry>)).Deserialize(xmlReader) as List<ModifiedChestEntry>; Quest.QuestStage questStage = (Quest.QuestStage)Enum.Parse( typeof(Quest.QuestStage), xmlReader.ReadElementString("currentQuestStage"), true); if ((singleton.questLine != null) && !IsQuestLineComplete) { singleton.quest = singleton.questLine.Quests[CurrentQuestIndex]; singleton.ModifyQuest(singleton.quest); singleton.quest.Stage = questStage; } xmlReader.ReadEndElement(); // read the party data singleton.party = new Party(new XmlSerializer( typeof(PartySaveData)).Deserialize(xmlReader) as PartySaveData, content); */ // </Mechadrone1SaveData> xmlReader.ReadEndElement(); } } } return loadedDossier; }
public static void LoadFromSaveFile(SaveGameDescription saveGameDescription, DossierLoadedDelegate dossierLoadedCallback) { if (saveGameDescription == null) throw new ArgumentNullException("saveGameDescription"); if (dossierLoadedCallback == null) throw new ArgumentNullException("dossierLoadedCallback"); // get the storage device and load the session GetStorageDevice(delegate(StorageDevice storageDevice) { GameDossier loadedDossier = LoadDossierResult(storageDevice, saveGameDescription); dossierLoadedCallback(loadedDossier); }); }