Esempio n. 1
0
    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);
    }
Esempio n. 2
0
    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();
        }
    }
Esempio n. 3
0
    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();
    }