private void DeserializeSave(XmlReader reader) { save = serializer.Deserialize(reader) as SaveData; }
/// <summary> /// Return the highscore for the required level /// </summary> /// <param name="map"></param> /// <returns></returns> public ScoreLine GetBestScoreForLevel(String map, ScoreType scoreType) { try { ScoreLine[] result = null; if (save.ScoresBylevel[scoreType].TryGetValue(map, out result)) { return result[0]; } else { save.AddScore(map, scoreType, ScoreLine.GetDefaultScoreLine(1)); return GetBestScoreForLevel(map, scoreType); } } catch (IndexOutOfRangeException) { this.save = new SaveData(); this.Save(); //This exception is throwed only if you have an old savegame //For now I just reset scores and options throw new Exception(LocalizedStrings.GetString("CorruptedSavegame")); } }
/// <summary> /// Load a saved game /// </summary> public void Load() { #if WINDOWS Stream stream = null; #endif try { #if XBOX if (TGPAContext.Instance.SaveDevice.FileExists(containerName, filename) == false) { this.Save(); } // make sure the device is ready if (TGPAContext.Instance.SaveDevice.IsReady) { // load a file asynchronously. this will trigger IsBusy to return true // for the duration of the save process. TGPAContext.Instance.SaveDevice.LoadAsync( containerName, filename, stream => { using (XmlReader reader = XmlReader.Create(stream)) { DeserializeSave(reader); } } ); } #else stream = File.OpenRead(filePath); XmlReader reader = XmlReader.Create(stream); DeserializeSave(reader); stream.Close(); #endif } catch (Exception e) { #if WINDOWS if (stream != null) { stream.Close(); } #endif //New savegame save = new SaveData(); Logger.Log(LogLevel.Error, "Exception when loading savegame : " + e.Message); this.Save(); } Logger.Log(LogLevel.Info, "Savedgame loaded"); }
public Saver() { #if WINDOWS folderName = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "Saved Games"), containerName); filePath = System.IO.Path.Combine(folderName, filename); #endif save = new SaveData(); }