/// <summary>Save the provided game state <paramref name="savedGame" /> at the path specified by <paramref name="path" />.</summary> /// <param name="savedGame">The game state to save.</param> /// <param name="path">The path to save <paramref name="savedGame" /> at.</param> public static void SaveGame(object savedGame, PathInst path) { FileStream fileStream = path.CreateOverwriteFileStream(); _bf.Serialize(fileStream, savedGame); fileStream.Close(); }
/// <summary> /// Save the current game with the provided name. /// </summary> public void SaveGame() { // Do nothing if the input field is empty. string baseFileName = this.inputField.text.RemoveEnd(".tscgame"); if (IsInvalidBaseFileName(baseFileName)) { return; } // Otherwise, create a Path object from the provided text content and check it for validity. If the file // path provided is illegal, then simply return. // TODO_LATER Add a message about illegal file name. PathInst targetPath = SaveGameManager.InitializeSaveFilePathFromFileName($"{baseFileName}.tscgame"); string path = targetPath.ToString(); if (!LocalFileUtils.ValidateDllPath(ref path)) { return; } // Save the game at the desired path. SaveGameManager.SaveGame(SaveFile.CreateSaveFile(this.gameSceneManager.gameState), targetPath); // Clear out the text input, and reload the saved games. this.inputField.text = ""; this.LoadSavedGames(); }
/// <summary> /// Load the game file from the provided text name in the text input. /// </summary> public void LoadExistingGame() { // Extract the save file from the provided text file and load it. PathInst gamePath = SaveGameManager.InitializeSaveFilePathFromFileName(this.fileNameText.text); if (gamePath.Exists()) { SaveFile saveFile = SaveGameManager._bf.Deserialize(gamePath.OpenExistingFileStream()) as SaveFile; this.gameSceneManager.LoadAndInitializeScene(saveFile.gameState); // Deactivate the game menu manager and show the game window itself. gameMenuManager.Deactivate(); } else { genericNoticeDisplay.Activate(); } }
/// <summary> /// Load the game whose file name is provided below. /// </summary> /// <param name="filename">The name of the file to load.</param> /// <returns>The save file object corresponding to the provided file name.</returns> public static object LoadGame(string filename) { PathInst gamePath = InitializeSaveFilePathFromFileName(filename); return(_bf.Deserialize(gamePath.OpenExistingFileStream())); }