/// <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(); } }