Exemplo n.º 1
0
        public static void GetLeagueHistory(GetLeaguesCallBack callback)
        {
            List <string> userDataKeys = new List <string>()
            {
                "CurrentLeagues"
            };
            List <string> leagueKeys = new List <string>();
            List <TitleDescriptionButtonData> toRet = new List <TitleDescriptionButtonData>();

            // get list of league keys from PlayerData
            PlayFabClientAPI.GetUserData(new GetUserDataRequest()
            {
                Keys = userDataKeys
            },
                                         result =>
            {
                // validate this key before getting keys from JSON
                if (result.Data.ContainsKey("CurrentLeagues"))
                {
                    // parse LeagueIds from JSON into a list of string
                    var leagueListJSON  = result.Data["CurrentLeagues"].Value;
                    var leagueKeysArray = leagueListJSON.Split('"').Where((item, index) => index % 2 != 0);
                    leagueKeys          = new List <string>(leagueKeysArray);
                }

                // nested PlayFab call to get tTitleData using keys returned from UserData
                PlayFabClientAPI.GetTitleData(new GetTitleDataRequest()
                {
                    Keys = leagueKeys
                },
                                              titleResult =>
                {
                    foreach (var key in leagueKeys)
                    {
                        if (titleResult.Data.ContainsKey(key))
                        {
                            LeagueInfo leagueInfo = LeagueInfo.CreateFromJSON(titleResult.Data[key]);
                            if (leagueInfo.Status == "Complete")
                            {
                                toRet.Add(new TitleDescriptionButtonData(
                                              key,
                                              leagueInfo.Name,
                                              leagueInfo.LeagueSettings.LeagueType + "\n" + leagueInfo.Status,
                                              leagueInfo.LeagueSettings.LeagueType == "Rated"));
                            }
                        }
                    }
                    toRet.Reverse(); // put most recent league at top
                    callback(toRet);
                },
                                              RPSCommon.OnPlayFabError
                                              );
            },
                                         RPSCommon.OnPlayFabError
                                         );
        }
Exemplo n.º 2
0
        public static void GetOpenLeagues(GetLeaguesCallBack callback)
        {
            List <string> userDataKeys = new List <string>()
            {
                "CurrentLeagues"
            };
            List <string> leagueKeys = new List <string>();
            List <TitleDescriptionButtonData> toRet = new List <TitleDescriptionButtonData>();

            // get list of league keys from PlayerData
            PlayFabClientAPI.GetUserData(new GetUserDataRequest()
            {
                Keys = userDataKeys
            },
                                         result =>
            {
                // validate this key before getting keys from JSON
                if (result.Data.ContainsKey("CurrentLeagues"))
                {
                    // parse LeagueIds from JSON into a list of string
                    var leagueListJSON  = result.Data["CurrentLeagues"].Value;
                    var leagueKeysArray = leagueListJSON.Split('"').Where((item, index) => index % 2 != 0);
                    leagueKeys          = new List <string>(leagueKeysArray);
                }

                // nested PlayFab call to get tTitleData using keys returned from UserData
                PlayFabClientAPI.GetTitleData(new GetTitleDataRequest()
                {
                },   // get all data from Title
                                              titleResult =>
                {
                    foreach (var entry in titleResult.Data)
                    {
                        // TODO: if we add other kinds of data to title data, we need to check for prefix "League"
                        LeagueInfo leagueInfo = LeagueInfo.CreateFromJSON(entry.Value);
                        if (leagueInfo.Status == "Open" && !leagueKeys.Contains(entry.Key))
                        {
                            toRet.Add(new TitleDescriptionButtonData(
                                          entry.Key,
                                          leagueInfo.Name,
                                          // TODO: show game settings instead of league status here
                                          leagueInfo.LeagueSettings.LeagueType + "\n" + leagueInfo.Status,
                                          leagueInfo.LeagueSettings.LeagueType == "Rated"));
                        }
                    }
                    toRet.Reverse(); // put most recent at league at top
                    callback(toRet);
                },
                                              RPSCommon.OnPlayFabError
                                              );
            },
                                         RPSCommon.OnPlayFabError
                                         );
        }