public void Save(string basePath, string currentSaveDir) { if (GameState == null) { throw new CorruptSaveException("Missing GameState."); } if (UiState == null) { throw new CorruptSaveException("Missing UiState."); } var serializedGameState = SavedGameState.Save(GameState, Co8State != null); var serializedUiState = SavedUiState.Save(UiState, Co8State != null); // Write the files to the current save directory so they are added to the save archive afterwards WriteStateToDirectory(serializedGameState, serializedUiState, currentSaveDir); try { ArchiveWriter.Compress(basePath + ".tfai", basePath + ".tfaf", currentSaveDir); } finally { DeleteStateFromDirectory(currentSaveDir); } }
public void LoadGame(SavedUiState savedState) { // TODO: I think this is not used GameSystems.TimeEvent.RemoveAll(TimeEventType.AmbientLighting); GameSystems.TimeEvent.Schedule(new TimeEvent(TimeEventType.AmbientLighting), TimeSpan.FromHours(1), out _); }
public void SaveGame(SavedUiState savedState) { }
public void SaveGame(SavedUiState savedState) { // I think this is not used Stub.TODO(); }
public static SaveGameFile Load(string basePath, string currentSaveDir) { var result = new SaveGameFile(); var indexPath = basePath + ".tfai"; var archiveIndex = ArchiveIndexReader.ReadIndex(indexPath); using var dataStream = new FileStream(basePath + ".tfaf", FileMode.Open); byte[] gameStateData = null; byte[] spellPacketData = null; byte[] partyConfigData = null; byte[] mapFleeData = null; byte[] uiStateData = null; bool GrabData(ArchiveIndexEntry entry, string filename, ref byte[] bufferOut) { if (entry.Path == filename) { if (bufferOut != null) { throw new CorruptSaveException($"File {filename} exists twice in the save game!"); } var buffer = new byte[entry.Size]; dataStream.Read(buffer); if (Debugger.IsAttached) { var fullPath = Path.Join(currentSaveDir, entry.Path); File.WriteAllBytes(fullPath, buffer); } bufferOut = buffer; return(true); } return(false); } foreach (var entry in archiveIndex) { var fullPath = Path.Join(currentSaveDir, entry.Path); if (entry.Directory) { Directory.CreateDirectory(fullPath); continue; } if (GrabData(entry, MainStateFile, ref gameStateData) || GrabData(entry, ActionSequencesSpellsFile, ref spellPacketData) || GrabData(entry, PartyConfigFile, ref partyConfigData) || GrabData(entry, MapFleeFile, ref mapFleeData) || GrabData(entry, UiStateFile, ref uiStateData)) { continue; } CopyStreamToFile(dataStream, entry.Size, fullPath); } if (gameStateData == null) { throw new CorruptSaveException($"Save file is missing {MainStateFile}"); } if (spellPacketData == null) { throw new CorruptSaveException($"Save file is missing {ActionSequencesSpellsFile}"); } if (partyConfigData == null) { throw new CorruptSaveException($"Save file is missing {PartyConfigFile}"); } if (mapFleeData == null) { throw new CorruptSaveException($"Save file is missing {MapFleeFile}"); } if (uiStateData == null) { throw new CorruptSaveException($"Save file is missing {UiStateFile}"); } result.GameState = SavedGameState.Load(gameStateData, spellPacketData, partyConfigData, mapFleeData); result.UiState = SavedUiState.Load(uiStateData); // Load the optional Co8 data if it exists var co8Path = basePath + ".co8"; if (File.Exists(co8Path)) { result.Co8State = SavedCo8State.Load(co8Path); } return(result); }
public void LoadGame(SavedUiState savedState) { UiSystems.InGameSelect.FocusClear(); }