예제 #1
0
    // Attempts to save the current game (if successful, applies the save penalty then returns to the game)
    private void SaveGame()
    {
        // First restore the continuation save
        GameData gameData = LoadGame(true);

        if (gameData != null)
        {
            ResumeGame(gameData);

            if (GameDataIsValid(gameData, true))
            {
                // Add the penalty for saving before saving the current game
                scoreController.AddSavePenalty();

                // Attempt to save the current game
                if (persistenceController.SaveGame(PlayerPrefs.GetString("CurrentFile")))
                {
                    // Save has worked, so remove prefs no longer needed, confirm save to player and then restart game
                    TidyLoadSavePrefs();
                    textDisplayController.AddTextToLog(playerMessageController.GetMessage("266Resume"));
                    RestartGame(gameData);
                    return;
                }
            }
            else
            {
                // Invalid data will have ended the game, so simply return
                return;
            }
        }

        // Save has failed, so show warning dialogue
        warningType = SaveLoadType.PLAYER_SAVE;
        OpenWarningDialogue();
    }
예제 #2
0
    // Handler for the RETRY button on the warning dialogue
    public void WarningDialogueRetry()
    {
        CloseWarningDialogue();
        SaveLoadType wType = warningType;

        warningType = SaveLoadType.NO_WARNING;

        switch (wType)
        {
        case SaveLoadType.CONTINUATION_LOAD:
            ResumeFromLoad(true);
            break;

        case SaveLoadType.CONTINUATION_SAVE:
            ContinuationSave();
            break;

        case SaveLoadType.PLAYER_LOAD:
            ResumeFromLoad(false);
            break;

        case SaveLoadType.PLAYER_SAVE:
            SaveGame();
            break;

        default:
            break;
        }
    }
예제 #3
0
    // ========= PUBLIC METHODS =========

    // Attempts a continuation save and warns player if it isn't successful - returns true if successful, false otherwise
    public bool ContinuationSave()
    {
        if (!persistenceController.SaveGame(null))
        {
            warningType = SaveLoadType.CONTINUATION_SAVE;
            OpenWarningDialogue();
            return(false);
        }
        else
        {
            // Prepare a string for player prefs describing the continuation status for the current player
            string    gameStatus;
            ScoreMode scoreMode;

            if (CurrentGameStatus == GameStatus.PLAYING)
            {
                gameStatus = "Game in progress (Current score: ";
                scoreMode  = ScoreMode.INTERIM;
            }
            else
            {
                gameStatus = "Game ended (Final score: ";
                scoreMode  = ScoreMode.FINAL;
            }

            int[] score = scoreController.CalculateScore(scoreMode);
            PlayerPrefs.SetString("Player" + PlayerPrefs.GetInt("CurrentPlayer") + "Status", gameStatus + score[0] + " of a possible " + score[1] + " in " + Turns + " turn" + (Turns != 1 ? "s)" : ")"));
            return(true);
        }
    }
예제 #4
0
    // Handler for the CANCEL button on the warning dialogue
    public void WarningDialogueCancel()
    {
        SaveLoadType wType = warningType;

        warningType = SaveLoadType.NO_WARNING;
        CloseWarningDialogue();

        if (wType == SaveLoadType.CONTINUATION_LOAD || wType == SaveLoadType.PLAYER_LOAD)
        {
            StartCoroutine(GoToScene("Menu"));
        }
    }
예제 #5
0
    // Attempts to load a game and warns player if it isn't successful
    private GameData LoadGame(bool isContinuation)
    {
        GameData gameData = persistenceController.LoadGame(isContinuation ? null : PlayerPrefs.GetString("CurrentFile"));

        if (gameData == null)
        {
            warningType = isContinuation ? SaveLoadType.CONTINUATION_LOAD : SaveLoadType.PLAYER_LOAD;
            OpenWarningDialogue();
            return(null);
        }
        else
        {
            return(gameData);
        }
    }
예제 #6
0
    public void Load(SaveLoadType saveLoadType)
    {
        switch (saveLoadType)
        {
        case SaveLoadType.PlayerPrefs:
            saveLoader = new PlayerPrefsSaveLoader();
            break;

        case SaveLoadType.Text:
            saveLoader = new TextSaveLoader();
            break;

        case SaveLoadType.Binary:
            saveLoader = new BinarySaveLoader();
            break;
        }

        walletDictionary = saveLoader.Load();
    }
예제 #7
0
    // Load an resume a game
    private void ResumeFromLoad(bool isContinuation)
    {
        GameData gameData = LoadGame(isContinuation);

        if (gameData != null)
        {
            TidyLoadSavePrefs();
            ResumeGame(gameData);

            // Ensure that the data type loaded was the right type for this load type and was data for this player and, if its a continuation load, it was the correct continuation data for this player...
            if (GameDataIsValid(gameData, isContinuation))
            {
                RestartGame(gameData);
            }
        }
        else
        {
            warningType = isContinuation ? SaveLoadType.CONTINUATION_LOAD : SaveLoadType.PLAYER_LOAD;
            OpenWarningDialogue();
        }
    }
예제 #8
0
    //static int offset(Type c, string m) //(((size_t)&((c *)8)->m) - 8)
    //{
    //	var index = m.IndexOf('.');
    //	var handle = (index != -1) ?
    //		c.GetField(m[..index], BindingFlags.Instance | BindingFlags.NonPublic).FieldType.GetField(m[(index + 1)..], BindingFlags.Instance | BindingFlags.NonPublic).FieldHandle :
    //		c.GetField(m, BindingFlags.Instance | BindingFlags.NonPublic).FieldHandle;
    //	var offset = Marshal.ReadInt32(handle.Value + (4 + IntPtr.Size)) & 0xFFFFFF;
    //	return offset;
    //}

    //static int item_size(Type c, string m) //sizeof(((c *)0)->m)
    //{
    //	var size = Common.SizeOf(c.GetField(m, BindingFlags.Instance | BindingFlags.NonPublic).FieldType);
    //	return size;
    //}

    /*
     * An empty entry. Just to pad bytes on disk.
     * @param t The type on disk.
     */
    internal static SaveLoadDesc SLD_EMPTY(SaveLoadType t) =>