Example #1
0
    private void HandleGetPlayerInfoSuccess(string response)
    {
        PlayerMenuDataContainer playerInfo = JsonUtility.FromJson <PlayerMenuDataContainer>(response);

        if (currentPlayerMenuData == null)
        {
            currentPlayerMenuData = playerInfo;
            UpdateGamesView();
        }
        else if (!currentPlayerMenuData.Equals(playerInfo))
        {
            Debug.Log("Games payload not same as cached games. Update cached games");
            currentPlayerMenuData = playerInfo;
            UpdateGamesView();
        }

        /* GameObject gameButtonPrefab = Resources.Load("GameButton") as GameObject;
         *
         * // Create api that gives you gameid and whose turn
         * // will make this a lot easier
         * foreach(string gameid in playerInfo.games)
         * {
         *  // Get current players turn to decide where to place button
         *  string apiEndpoint = apiEndpointHost + getGameInfoEndpointFormat;
         *  string apiCall = string.Format(apiEndpoint, gameid);
         *
         *  //GameObject gameButton = Instantiate(gameButtonPrefab);
         *  //Vector3 localScale = gameButton.transform.localScale;
         * } */
    }
Example #2
0
    public bool Equals(PlayerMenuDataContainer other)
    {
        bool isRoomsEqual = rooms.SequenceEqual(other.rooms);
        bool isGamesEqual = true;

        Debug.Log("Games count " + games.Count());
        Debug.Log("Other games count " + other.games.Count());
        if (games.Count() != other.games.Count())
        {
            isGamesEqual = false;
            Debug.Log(string.Format("Rooms equal: {0} Games equal: {1}", isRoomsEqual, isGamesEqual));
            return(isRoomsEqual && isGamesEqual);
        }
        else
        {
            //Debug.Log(JsonUtility.ToJson(other));
            // They don't arrive in the same order
            string otherGamesSerialized = JsonUtility.ToJson(other);
            Debug.Log(otherGamesSerialized);
            foreach (PlayerMenuGamesDataContainer game in games)
            {
                string gameSerialized = JsonUtility.ToJson(game);
                Debug.Log(gameSerialized);
                isGamesEqual = otherGamesSerialized.Contains(gameSerialized);
                if (!isGamesEqual)
                {
                    Debug.Log(string.Format("Rooms equal: {0} Games equal: {1}", isRoomsEqual, isGamesEqual));
                    return(isRoomsEqual && isGamesEqual);
                }
            }

            /* for(int i=0; i<games.Count(); i+=1)
             * {
             *  isGamesEqual = games[i].Equals(other.games[i]);
             *  if (!isGamesEqual)
             *  {
             *      Debug.Log(string.Format("Rooms equal: {0} Games equal: {1}", isRoomsEqual, isGamesEqual));
             *      return (isRoomsEqual && isGamesEqual);
             *  }
             * } */
        }

        Debug.Log(string.Format("Rooms equal: {0} Games equal: {1}", isRoomsEqual, isGamesEqual));
        return(isRoomsEqual && isGamesEqual);
    }