示例#1
0
    public static void SaveUserBoard(Board myBoard, string userBoardName)
    {
        State.TaskAdd("SaveUserBoard");
        userBoardName = userBoardName.ToLower();

        // Create DynamoDB wrapper
        BoardDDB ddbBoard   = new BoardDDB();
        string   identityID = Identity.Credentials.GetIdentityId();

        ddbBoard.IdentityID = identityID;
        ddbBoard.BoardID    = System.Guid.NewGuid() + delimiter + userBoardName;
        ddbBoard.BoardName  = userBoardName;
        ddbBoard.UserBoard  = myBoard;
        ddbBoard.Votes_A    = 0;
        ddbBoard.Votes_D    = 0;
        // the plays are set initially to 1 because
        // the board is always played once during creation
        // this also prevents divide-by-zero errors
        ddbBoard.Plays_A         = 1;
        ddbBoard.Plays_D         = -1;
        ddbBoard.Wins_A          = 0;
        ddbBoard.Wins_D          = 0;
        ddbBoard.VotesPlaysRatio = 0f;
        ddbBoard.WinsPlaysRatio  = 0f;

        string printJSON = ActorGameManager.SerializeGameBoard(myBoard);

        Debug.Log("Saving Board: " + printJSON);

        //  Save the board
        Context.SaveAsync(ddbBoard, (result) =>
        {
            if (result.Exception == null)
            {
                Debug.Log("Board saved to UserBoards table");
                State.gameState = GameState.boards;
                SceneManager.LoadScene("boards");
                State.TaskDone("SaveUserBoard");
            }
            else
            {
                Debug.LogWarning("Board save to UserBoards table failed.");
                State.TaskDone("SaveUserBoard");
            }
        });
    }