/** Creates any modal pop up's requested by the loading co-routine. */ public override void Update() { base.Update(); if (requestPopup != null) { var modalState = requestPopup(); if (errorAction != null) { var errorActionCopy = errorAction; modalState.OnStateClose += delegate { errorActionCopy(); }; } Engine.PushState(modalState); requestPopup = null; errorAction = null; } }
/** Loads game content. */ private void LoadGame() { // 1. Load graphics try { CoM.LoadGraphics(); } catch (Exception e) { HandleException("Load Graphics", e); return; } // 2. Load the game data if (!CoM.HasAllStaticData()) { requestPopup = CreateMissingGameFilesNotice; } try { CoM.LoadGameData(); } catch (Exception e) { errorMessage = "An error has occured while loading the game data.\n" + "The game can not run.\n" + "\n" + e.Message + "\n" + e.StackTrace; Trace.LogError("Error loading game data: " + e.Message + "\n" + e.StackTrace); requestPopup = CreateErrorNotice; return; } // 3. Load save file try { if (!SaveFile.HasSave) { Trace.Log("No save file detected, resetting game."); CoM.State.Reset(); } else { CoM.State.Load(); } } catch (Exception e) { errorMessage = "An error has occured while loadind the save file.\n" + "Really sorry about this. The only way to continue is to reset the save game.\n" + "All characters and progress will be lost.\n" + "Press OK to continue.\n" + "\n" + e.Message + "\n" + e.StackTrace; errorAction = CoM.State.Reset; string longError = "Error loading save file: " + e.Message + "\n" + e.StackTrace + "\n"; if (e.InnerException != null) { string additionalErrorInformation = "\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace; longError += additionalErrorInformation; errorMessage += additionalErrorInformation; } Trace.LogWarning(longError); requestPopup = CreateErrorNotice; return; } }
private void HandleException(string action, Exception e) { errorMessage = e.Message; Trace.LogError(errorMessage + "\n" + e.StackTrace); requestPopup = CreateErrorNotice; }