// Attempts to save the current game (if successful, applies the save penalty then returns to the game) private void SaveGame() { // First restore the continuation save GameData gameData = LoadGame(true); if (gameData != null) { ResumeGame(gameData); if (GameDataIsValid(gameData, true)) { // Add the penalty for saving before saving the current game scoreController.AddSavePenalty(); // Attempt to save the current game if (persistenceController.SaveGame(PlayerPrefs.GetString("CurrentFile"))) { // Save has worked, so remove prefs no longer needed, confirm save to player and then restart game TidyLoadSavePrefs(); textDisplayController.AddTextToLog(playerMessageController.GetMessage("266Resume")); RestartGame(gameData); return; } } else { // Invalid data will have ended the game, so simply return return; } } // Save has failed, so show warning dialogue warningType = SaveLoadType.PLAYER_SAVE; OpenWarningDialogue(); }
// Handler for the RETRY button on the warning dialogue public void WarningDialogueRetry() { CloseWarningDialogue(); SaveLoadType wType = warningType; warningType = SaveLoadType.NO_WARNING; switch (wType) { case SaveLoadType.CONTINUATION_LOAD: ResumeFromLoad(true); break; case SaveLoadType.CONTINUATION_SAVE: ContinuationSave(); break; case SaveLoadType.PLAYER_LOAD: ResumeFromLoad(false); break; case SaveLoadType.PLAYER_SAVE: SaveGame(); break; default: break; } }
// ========= PUBLIC METHODS ========= // Attempts a continuation save and warns player if it isn't successful - returns true if successful, false otherwise public bool ContinuationSave() { if (!persistenceController.SaveGame(null)) { warningType = SaveLoadType.CONTINUATION_SAVE; OpenWarningDialogue(); return(false); } else { // Prepare a string for player prefs describing the continuation status for the current player string gameStatus; ScoreMode scoreMode; if (CurrentGameStatus == GameStatus.PLAYING) { gameStatus = "Game in progress (Current score: "; scoreMode = ScoreMode.INTERIM; } else { gameStatus = "Game ended (Final score: "; scoreMode = ScoreMode.FINAL; } int[] score = scoreController.CalculateScore(scoreMode); PlayerPrefs.SetString("Player" + PlayerPrefs.GetInt("CurrentPlayer") + "Status", gameStatus + score[0] + " of a possible " + score[1] + " in " + Turns + " turn" + (Turns != 1 ? "s)" : ")")); return(true); } }
// Handler for the CANCEL button on the warning dialogue public void WarningDialogueCancel() { SaveLoadType wType = warningType; warningType = SaveLoadType.NO_WARNING; CloseWarningDialogue(); if (wType == SaveLoadType.CONTINUATION_LOAD || wType == SaveLoadType.PLAYER_LOAD) { StartCoroutine(GoToScene("Menu")); } }
// Attempts to load a game and warns player if it isn't successful private GameData LoadGame(bool isContinuation) { GameData gameData = persistenceController.LoadGame(isContinuation ? null : PlayerPrefs.GetString("CurrentFile")); if (gameData == null) { warningType = isContinuation ? SaveLoadType.CONTINUATION_LOAD : SaveLoadType.PLAYER_LOAD; OpenWarningDialogue(); return(null); } else { return(gameData); } }
public void Load(SaveLoadType saveLoadType) { switch (saveLoadType) { case SaveLoadType.PlayerPrefs: saveLoader = new PlayerPrefsSaveLoader(); break; case SaveLoadType.Text: saveLoader = new TextSaveLoader(); break; case SaveLoadType.Binary: saveLoader = new BinarySaveLoader(); break; } walletDictionary = saveLoader.Load(); }
// Load an resume a game private void ResumeFromLoad(bool isContinuation) { GameData gameData = LoadGame(isContinuation); if (gameData != null) { TidyLoadSavePrefs(); ResumeGame(gameData); // Ensure that the data type loaded was the right type for this load type and was data for this player and, if its a continuation load, it was the correct continuation data for this player... if (GameDataIsValid(gameData, isContinuation)) { RestartGame(gameData); } } else { warningType = isContinuation ? SaveLoadType.CONTINUATION_LOAD : SaveLoadType.PLAYER_LOAD; OpenWarningDialogue(); } }
//static int offset(Type c, string m) //(((size_t)&((c *)8)->m) - 8) //{ // var index = m.IndexOf('.'); // var handle = (index != -1) ? // c.GetField(m[..index], BindingFlags.Instance | BindingFlags.NonPublic).FieldType.GetField(m[(index + 1)..], BindingFlags.Instance | BindingFlags.NonPublic).FieldHandle : // c.GetField(m, BindingFlags.Instance | BindingFlags.NonPublic).FieldHandle; // var offset = Marshal.ReadInt32(handle.Value + (4 + IntPtr.Size)) & 0xFFFFFF; // return offset; //} //static int item_size(Type c, string m) //sizeof(((c *)0)->m) //{ // var size = Common.SizeOf(c.GetField(m, BindingFlags.Instance | BindingFlags.NonPublic).FieldType); // return size; //} /* * An empty entry. Just to pad bytes on disk. * @param t The type on disk. */ internal static SaveLoadDesc SLD_EMPTY(SaveLoadType t) =>