public override void onPress() { //if save type if true, we will save our current save data if (owner.isSaving()) { SaveGameData newData = SaveManager.packData(); if (this.saveData == null) { newData.fileName = SaveManager.generateNewFileName(); this.owner.loadEntries(new SaveDataEntry(this.owner, null)); //add a new blank entry this.setName(newData.heroData.name); } else { //newData.playTime = this.saveData.playTime + newData.playTime; newData.fileName = this.saveData.fileName; } SaveManager.saveGame(newData.fileName, newData, false); this.saveData = newData; this.owner.getPreviousPanel().setMessage("Game saved!"); } //if save type if false, we will load our current save data else { if (this.saveData == null) { this.owner.getPreviousPanel().setMessage("An empty save file cannot be loaded."); } else { this.owner.getPreviousPanel().setMessage("Game loaded!"); ScreenTransition.requestTransition(delegate() { InGameMenu.reset(); SaveManager.unpackData(this.saveData); WorldManager.updateCameraOffset(Hero.instance); }); } } }
public static void unpackData(SaveGameData data) { Hero h1 = Hero.instance; h1.loadSaveStructure(data.heroData); KeyboardManager.loadKeyControls(data.inputKeys); Quest.loadQuestStateSave(data.questStates); WorldManager.clearMaps(); WorldManager.setRoomNoTransition(data.roomName); GameClock.loadSaveStructure(data.playTime); CharacterManager.loadSaveStructure(data.characterStates); InGameMenu.refreshPanelLists(); }
/// <summary> /// Saves a game to an external file in the "SaveData" folder. /// By default the save file is encrypted. /// </summary> /// <param name="fileName">Name to give saved data file</param> /// <param name="saveGame">Data to be saved</param> /// <param name="encrypt">Optional, specifies whether output file should be encrypted (True by default)</param> public static bool saveGame(string fileName, SaveGameData saveGame, bool encrypt=true) { if (!Directory.Exists(Directories.SAVEDATA)) Directory.CreateDirectory(Directories.SAVEDATA); if (fileName.StartsWith(Directories.SAVEDATA)) fileName = fileName.Substring(Directories.SAVEDATA.Length); try { // unencrypted method (stable) if (!encrypt) { Stream fStream = new FileStream(Directories.SAVEDATA + fileName, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); serializer.Serialize(fStream, saveGame); fStream.Close(); } // encrypted method else { Stream memStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); serializer.Serialize(memStream, saveGame); encryptFile(memStream, Directories.SAVEDATA + fileName); memStream.Close(); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); return false; } return true; }
public static SaveGameData packData() { SaveGameData data = new SaveGameData(); Hero h1 = Hero.instance; data.heroData = h1.getSaveStructure(); data.inputKeys = KeyboardManager.getKeyControls(); data.questStates = Quest.getQuestStateSave(); data.roomName = WorldManager.m_currentRoomID; data.playTime = GameClock.getSaveStructure(); data.characterStates = CharacterManager.getSaveStructure(); return data; }
public void setSaveData(SaveGameData data) { this.saveData = data; }
public SaveDataEntry(SaveDataPanel owner, SaveGameData data) : base("Temp", 0, 0) { this.owner = owner; this.setSaveData(data); }