public InProgressSave(SaveInformation.SaveType type, Func <Node> currentGameRoot, Func <InProgressSave, Save> createSaveData, Action <InProgressSave, Save> performSave, string saveName) { this.currentGameRoot = currentGameRoot; this.createSaveData = createSaveData; this.performSave = performSave; this.saveName = saveName; Type = type; returnToPauseState = currentGameRoot.Invoke().GetTree().Paused; stopwatch = Stopwatch.StartNew(); // Start calculating the save name here to save some time saveNameTask = new Task <string>(CalculateNameForSave); TaskExecutor.Instance.AddTask(saveNameTask); }
private static void PerformSave(Save save, SaveInformation.SaveType type, Stopwatch stopwatch) { // TODO: implement type naming var name = "quick_save." + Constants.SAVE_EXTENSION; save.Name = name; try { save.SaveToFile(); DisplaySaveStatusMessage(true, name, stopwatch); } catch (Exception e) { DisplaySaveStatusMessage(false, "Error, an exception happened: " + e, stopwatch); return; } if (type == SaveInformation.SaveType.QuickSave) { QueueRemoveExcessQuickSaves(); } }
private static void InternalSaveHelper(SaveInformation.SaveType type, MainGameState gameState, Action <Save> copyInfoToSave, Func <Node> stateRoot, string saveName = null) { if (InProgressLoad.IsLoading || InProgressSave.IsSaving) { GD.PrintErr("Can't start save while a load or save is in progress"); return; } new InProgressSave(type, stateRoot, data => CreateSaveObject(gameState, data.Type), (inProgress, save) => { copyInfoToSave.Invoke(save); if (PreventSavingIfExtinct(inProgress, save)) { return; } PerformSave(inProgress, save); }, saveName).Start(); }