//TODO Untested //Returns the header of a specified save slot. //The header contains information about the save file. If the save slot is empty it will return "Empty Save Slot". //Usage: Save Slots should be represented by buttons that the user can click and the button text should be a save slot header to display its information. //Pressing the button should call SaveFileManager.LoadGame(saveSlotIndex) where each button represents different save slots. public string GetSaveSlotHeader(int _saveSlotIndex) { if (_saveSlotIndex < 0 || _saveSlotIndex > 8) { //This game will have a maximum 8 save slots hardcoded. Debug.LogError("[Error] Invalid save slot index! Slot number must be between from 1 to 8."); return("[Error] Invalid Save slot index!"); } if (availableSaveFiles == null) { availableSaveFiles = SaveFileReaderWriter.CheckAvailableSaveFiles(Application.persistentDataPath, savefileName); } if (availableSaveFiles != null) { if (availableSaveFiles.Length <= 0) { Debug.LogError("[Error] availableSaveFiles array not initialized!"); return("[Error] availableSaveFiles array not initialized!"); } } else { Debug.LogError("[Error] availableSaveFiles array not initialized!"); return("[Error] availableSaveFiles array not initialized!"); } return(availableSaveFiles[_saveSlotIndex - 1]); }
//Saves game data at given save slot index public void SaveGame(int _saveSlotIndex) { if (_saveSlotIndex <= 0 || _saveSlotIndex > 8) //This game will have a maximum 8 (0 to 8) save slots hardcoded. 0 slot should be reserved for quicksave { Debug.LogError("[Error] Invalid save slot index! Slot number must be between from 1 to 8."); return; } loadedSaveData = new SaveData(); loadedSaveData.savefileHeader = "Marco Lives: " + loadedSaveData.livesAmount + "; Ammo: " + loadedSaveData.ammoAmount + "; Seeds: " + loadedSaveData.seedsCollected + "; Levels Unlocked: " + loadedSaveData.levelsUnlocked; loadedSaveData.gameVersion = this.gameVersion; loadedSaveData.playerLocationX = this.playerLocation.x; loadedSaveData.playerLocationY = this.playerLocation.y; loadedSaveData.playerLocationZ = this.playerLocation.z; loadedSaveData.playerOrientationX = this.playerOrientation.x; loadedSaveData.playerOrientationY = this.playerOrientation.y; loadedSaveData.playerOrientationZ = this.playerOrientation.z; loadedSaveData.livesAmount = this.livesAmount; loadedSaveData.ammoAmount = this.ammoAmount; loadedSaveData.seedsCollected = this.seedsCollected; loadedSaveData.aliensKilled = this.aliensKilled; loadedSaveData.currentLevel = this.currentLevel; //0 means not in a level loadedSaveData.levelsUnlocked = this.levelsUnlocked; SaveFileReaderWriter.WriteToSaveFile(Application.persistentDataPath + "/" + savefileName + _saveSlotIndex + ".hamsave", loadedSaveData); }
//Loads save file data at given save slot index public SaveData LoadGame(int _saveSlotIndex) { if (_saveSlotIndex < 0 || _saveSlotIndex > 8) //This game will have a maximum 8 save slots hardcoded. { Debug.LogError("[Error] Invalid save slot index! Slot number must be between from 0 to 8."); return(null); } if (!File.Exists(Application.persistentDataPath + "/" + savefileName + _saveSlotIndex + ".hamsave")) { Debug.LogError("[Error] File does not exist; Cannot load a save file that does not exist."); return(null); } loadedSaveData = SaveFileReaderWriter.ReadFromSaveFile(Application.persistentDataPath + "/" + savefileName + _saveSlotIndex + ".hamsave"); if (this.gameVersion != loadedSaveData.gameVersion) { Debug.LogWarning("[Warning] Cannot load save file; incompatible version. "); return(null); } this.savefileHeader = loadedSaveData.savefileHeader; this.playerLocation = new Vector3(loadedSaveData.playerLocationX, loadedSaveData.playerLocationY, loadedSaveData.playerLocationZ); this.playerOrientation = new Vector3(loadedSaveData.playerOrientationX, loadedSaveData.playerOrientationY, loadedSaveData.playerOrientationZ); this.livesAmount = loadedSaveData.livesAmount; this.ammoAmount = loadedSaveData.ammoAmount; this.seedsCollected = loadedSaveData.seedsCollected; this.aliensKilled = loadedSaveData.aliensKilled; this.currentLevel = loadedSaveData.currentLevel; //0 means not in a level this.levelsUnlocked = loadedSaveData.levelsUnlocked; return(loadedSaveData); }
public MainWindow( PriceInUsdProvider priceInUsdProvider, CoinMarketCapDataProvider coinMarketCapDataProvider, TaxCalculator taxCalculator, PortfolioSummaryProvider portfolioSummaryProvider, FormFactory formFactory, SaveFileReaderWriter saveFileReaderWriter) { InitializeComponent(); this._priceInUsdProvider = priceInUsdProvider; this._coinMarketCapDataProvider = coinMarketCapDataProvider; this._taxCalculator = taxCalculator; this._portfolioSummaryProvider = portfolioSummaryProvider; this._formFactory = formFactory; this._saveFileReaderWriter = saveFileReaderWriter; this.SummaryDataRefreshTimer.Tick += (object o, EventArgs e) => this.UpdateSummaryData(); this.SummaryDataRefreshTimer.Start(); this.SetupDataGrids(); this.SetupEventHandlers(); this.KeyPreview = true; this.KeyDown += this.MainWindow_KeyDown; }
//Saves given game data at given save slot index public void SaveGame(int _saveSlotIndex, SaveData _saveData) { if (_saveSlotIndex <= 0 || _saveSlotIndex > 8) //This game will have a maximum 8 save slots hardcoded. { Debug.LogError("[Error] Invalid save slot index! Slot number must be between from 1 to 8."); return; } _saveData.gameVersion = this.gameVersion; _saveData.savefileHeader = "Marco Lives: " + _saveData.livesAmount + "; Ammo: " + _saveData.ammoAmount + "; Seeds: " + _saveData.seedsCollected + "; Levels Unlocked: " + _saveData.levelsUnlocked; SaveFileReaderWriter.WriteToSaveFile(Application.persistentDataPath + "/" + savefileName + _saveSlotIndex + ".hamsave", _saveData); }
private IEnumerator QuickSaveRoutine(float delay) { canActivateCheckpoint = false; if (saveManagerRef) { saveManagerRef.QuickSave(); } else { SaveData newData = new SaveData(); newData.gameVersion = "0.1"; SaveFileReaderWriter.WriteToSaveFile(Application.persistentDataPath + "/Hamstronaut0.hamsave", newData); } yield return(new WaitForSeconds(delay)); canActivateCheckpoint = true; }
public void QuickSave() { loadedSaveData = new SaveData(); loadedSaveData.savefileHeader = "(Quicksave) Marco Lives: " + loadedSaveData.livesAmount + "; Ammo: " + loadedSaveData.ammoAmount + "; Seeds: " + loadedSaveData.seedsCollected + "; Levels Unlocked: " + loadedSaveData.levelsUnlocked; loadedSaveData.gameVersion = this.gameVersion; loadedSaveData.playerLocationX = this.playerLocation.x; loadedSaveData.playerLocationY = this.playerLocation.y; loadedSaveData.playerLocationZ = this.playerLocation.z; loadedSaveData.playerOrientationX = this.playerOrientation.x; loadedSaveData.playerOrientationY = this.playerOrientation.y; loadedSaveData.playerOrientationZ = this.playerOrientation.z; loadedSaveData.livesAmount = this.livesAmount; loadedSaveData.ammoAmount = this.ammoAmount; loadedSaveData.seedsCollected = this.seedsCollected; loadedSaveData.aliensKilled = this.aliensKilled; loadedSaveData.currentLevel = this.currentLevel; //0 means not in a level loadedSaveData.levelsUnlocked = this.levelsUnlocked; SaveFileReaderWriter.WriteToSaveFile(Application.persistentDataPath + "/" + savefileName + "0.hamsave", loadedSaveData); }