Example #1
0
 /// <summary>
 /// loads all saved games slots, to show the load choices
 /// </summary>
 public void LoadSaveSlots()
 {
     foreach (string s in FolderSystem.getAllSaveSlotNames())
     {
         SaveableGame game = LoadSaveable <SaveableGame>
                                 (FolderSystem.getGameSavePath(Path.GetFileName(s)));
         allSavedGames.Add(game);
     }
 }
Example #2
0
    private void SaveGameAndScenesToFile(string saveName)
    {
        FolderSystem.createNewSaveSlotDirectory(saveName);

        ///save game
        Save(FolderSystem.getGameSavePath(currentGame.GameName), currentGame);

        ///create or overwrite all changed scenes
        foreach (SaveableScene s in currentGame.AllScenes)
        {
            ///if the scene exists, but was not changed since the last save, it doesnt need to be saved again
            if (s.DirtyData)
            {
                Save(FolderSystem.getSceneSavePath(currentGame, s.SceneName), s);
                s.DirtyData = false;
            }
        }
    }
Example #3
0
    public void LoadGame_(int index)
    {
        timer.start("started loading");
        lock (SyncRoot)
        {
            IsDataRestored = true;

            IsLoading = true;

            internIsLoading = true;

            ///reload game out of file (in case a reference changed something)
            allSavedGames[index] = LoadSaveable <SaveableGame>
                                       (FolderSystem.getGameSavePath(allSavedGames[index].GameName));

            timer.addCheckPoint("read data out of file");

            ///clones the save slot, so it can be edited without altering the save slot
            currentGame = allSavedGames[index];

            currentGame.loadGame(this);
        }
    }
Example #4
0
    private bool SaveGame_(string saveName, out string resultMessage)
    {
        timer.start("Save Game");
        bool result = true;
        // try
        // {
        SaveableGame overwriteThis =
            allSavedGames.Where(game => game.GameName == saveName).FirstOrDefault();

        ///if a game is overwritten, and its not the current game,
        ///or a new save slot is created the current
        ///game has to be reloaded from file, to avoid two games
        ///in the game list have the same reference
        bool overwriteCurrent = saveName == currentGame.GameName;

        ///the current game index is used, to destroy the reference between the
        ///original loaded game and the new save slot.
        int currentGameIndex = -1;

        ///this is only needed, when a different save slot than the current
        ///is used or no save slot is overwritten (new one or other)
        if (!overwriteCurrent || overwriteThis == null)
        {
            currentGameIndex = allSavedGames.IndexOf(currentGame);
        }

        string oldGameName = currentGame.GameName;

        ///converts all objects into saveable objects
        currentGame.saveCurrentScene(PersistentGameDataController.SaveType.Game);

        timer.addCheckPoint("current scene saved");

        currentGame.GameName = saveName;

        if (overwriteThis != null && !overwriteCurrent)
        {
            allSavedGames.Remove(overwriteThis);
            FolderSystem.DeleteGame(overwriteThis);
            overwriteThis = null;
        }

        ///store game and loaded scenes in file
        SaveGameAndScenesToFile(saveName);

        ///if a new save slot is created, all not loaded scenes must be copied
        ///in the new director, so all data is transfered
        if (overwriteThis == null)
        {
            ///only copy if the current game exists in the savedGameList
            if (currentGameIndex >= 0)
            {
                CopyAllNotLoadedScenesToDirectory
                    (FolderSystem.getDefaulScenePath(saveName));
            }
            allSavedGames.Add(currentGame);
        }

        ///if the index is bigger equals zero the old game should/will be reloaded
        ///to avoid two saved games reference to the same saveableGame
        if (currentGameIndex >= 0)
        {
            ///load old game and set it in the savedgame list
            allSavedGames[currentGameIndex] = LoadSaveable <SaveableGame>
                                                  (FolderSystem.getGameSavePath(oldGameName));
        }

        resultMessage = "Game saved.";
        result        = true;

        /*  }
         * catch (System.Exception ex)
         * {
         *    ///if an error occured, the first attempt to fix it, is to
         *    ///reload the existing games out of the files
         *    loadSaveSlots();
         *    resultMessage = "An error occured while saving the game: " +
         *        ex.ToString() + ", StackTrace:" + ex.StackTrace;
         *    result = false;
         *    Debug.LogWarning(resultMessage);
         * }*/
        timer.finish("finished saving");
        return(result);
    }