public GKTurnBasedMatch(Dictionary <string, object> dict)
    {
        if (dict.ContainsKey("matchId"))
        {
            matchId = dict["matchId"].ToString();
        }

        if (dict.ContainsKey("status"))
        {
            status = (GKTurnBasedMatchStatus)int.Parse(dict["status"].ToString());
        }

        if (dict.ContainsKey("message"))
        {
            message = dict["message"].ToString();
        }

        // grab and convert the date
        if (dict.ContainsKey("creationDate"))
        {
            var timeSinceEpoch = double.Parse(dict["creationDate"].ToString());
            var intermediate   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            creationDate = intermediate.AddSeconds(timeSinceEpoch);
        }

        // get the participants
        if (dict.ContainsKey("participants"))
        {
            var participantsList = dict["participants"] as List <object>;
            participants = new List <GKTurnBasedParticipant>(participantsList.Count);

            foreach (Dictionary <string, object> particpantDict in participantsList)
            {
                if (particpantDict != null)
                {
                    participants.Add(new GKTurnBasedParticipant(particpantDict));
                }
                else
                {
                    participants.Add(new GKTurnBasedParticipant());
                }
            }
        }

        // get the current participant
        if (dict.ContainsKey("currentParticipant"))
        {
            currentParticipant = new GKTurnBasedParticipant(dict["currentParticipant"] as Dictionary <string, object>);
        }
    }
Example #2
0
        public static TurnBasedMatchStatus ToTurnBasedMatchStatus(this GKTurnBasedMatchStatus status)
        {
            switch (status)
            {
            case GKTurnBasedMatchStatus.Open:
                return(TurnBasedMatchStatus.Active);

            case GKTurnBasedMatchStatus.Matching:
                return(TurnBasedMatchStatus.Matching);

            case GKTurnBasedMatchStatus.Ended:
                return(TurnBasedMatchStatus.Ended);

            case GKTurnBasedMatchStatus.Unknown:
            default:
                return(TurnBasedMatchStatus.Unknown);
            }
        }