Beispiel #1
0
        private static IEnumerator GetSongLeaderboardCoroutine(CustomLeaderboardController clc, string songHash, LevelDifficulty difficulty, string characteristic, string teamId = "-1", bool useTeamColors = false)
        {
            UnityWebRequest www = UnityWebRequest.Get($"{discordCommunityApi}/leaderboards/{songHash}/{(int)difficulty}/{characteristic}/{teamId}");

            www.timeout = 30;
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Logger.Error($"Error getting leaderboard data: {www.error}");
            }
            else
            {
                try
                {
                    var node = JSON.Parse(www.downloadHandler.text);

                    List <CustomLeaderboardTableView.CustomScoreData> scores = new List <CustomLeaderboardTableView.CustomScoreData>();
                    int myPos = -1;
                    foreach (var score in node)
                    {
                        scores.Add(new CustomLeaderboardTableView.CustomScoreData(
                                       Convert.ToInt32(score.Value["score"].ToString()),
                                       score.Value["player"],
                                       Convert.ToInt32(score.Value["place"].ToString()),
                                       score.Value["fullCombo"] == "true",
                                       score.Value["team"]
                                       ));

                        //If one of the scores is us, set the "special" score position to the right value
                        if (score.Value["userId"] == Convert.ToString(Plugin.UserId))
                        {
                            myPos = Convert.ToInt32(score.Value["place"] - 1);
                        }
                    }
                    clc.SetScores(scores, myPos, useTeamColors);
                }
                catch (Exception e)
                {
                    Logger.Error($"Error parsing leaderboard data: {e}");
                    yield break;
                }
            }
        }
Beispiel #2
0
        private void SongListRowSelected(Song song)
        {
            Action <IBeatmapLevel> songLoaded = (level) =>
            {
                song.Beatmap = SongUtils.GetClosestDifficultyPreferLower(level, (BeatmapDifficulty)(int)song.Difficulty, song.Characteristic);

                //Open up the custom/global leaderboard pane when we need to
                if (_communityLeaderboard == null)
                {
                    _communityLeaderboard              = BeatSaberUI.CreateViewController <CustomLeaderboardController>();
                    _communityLeaderboard.PlayPressed += SongPlayPressed;
                }
                SetLeftScreenViewController(_communityLeaderboard);

                if (_globalLeaderboard == null)
                {
                    _globalLeaderboard      = Resources.FindObjectsOfTypeAll <PlatformLeaderboardViewController>().First();
                    _globalLeaderboard.name = "Community Global Leaderboard";
                }

                //Change global leaderboard view
                _globalLeaderboard.SetData(song.Beatmap);

                SetRightScreenViewController(_globalLeaderboard);

                //Change community leaderboard view
                //Use the currently selected team, if it exists
                //TODO: Reimplement?
                //int teamIndex = _communityLeaderboard.selectedTeamIndex;
                //if (teamIndex <= -1) teamIndex = Team.allTeams.FindIndex(x => x.TeamId == Player.Instance.Team);
                _communityLeaderboard.SetSong(song, -1);
            };

            //When the row is selected, load the beatmap
            SongUtils.LoadSong(song.PreviewBeatmap, songLoaded);
        }
Beispiel #3
0
 //Gets the top 10 scores for a song and posts them to the provided leaderboard
 public static void GetSongLeaderboard(CustomLeaderboardController clc, string songHash, LevelDifficulty difficulty, string characteristic, string teamId, bool useTeamColors = false)
 {
     SharedCoroutineStarter.instance.StartCoroutine(GetSongLeaderboardCoroutine(clc, songHash, difficulty, characteristic, teamId, useTeamColors));
 }