示例#1
0
        public IEnumerator GetPageScoreSaber(int page, int cat)
        {
            yield return(null);

            scoreSaber = true;
            _moreSongsListViewController.SetLoadingState(true);
            _moreSongsListViewController.TogglePageUpDownButtons((page > 0), true);
            _moreSongsListViewController.SetContent(null);
            if (page <= collectedPages)
            {
                string url = $"{PluginConfig.scoresaberURL}/api.php?function=get-leaderboards&cat={cat}&limit=6&page={(page + 1)}&unique=1";
                if (cat == 3)
                {
                    url = url + "&ranked=1";
                }
                UnityWebRequest www = UnityWebRequest.Get(url);
                www.timeout = 15;
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    Plugin.log.Error($"Unable to connect to {PluginConfig.scoresaberURL}! " + (www.isNetworkError ? $"Network error: {www.error}" : (www.isHttpError ? $"HTTP error: {www.error}" : "Unknown error")));
                }
                else
                {
                    try
                    {
                        JObject jNode = JObject.Parse(www.downloadHandler.text);
                        currentPageSongs.Clear();
                        for (int i = 0; i < Math.Min(jNode["songs"].Children().Count(), songsPerPage); i++)
                        {
                            currentPageSongs.Add(new Song((JObject)jNode["songs"][i], true));
                        }
                        currentSortSongs.AddRange(currentPageSongs);
                        collectedPages++;

                        _moreSongsListViewController.SetContent(currentSortSongs.GetRange(page * 6, Math.Min(6, currentSortSongs.Count - (currentPage * 6))));
                    }
                    catch (Exception e)
                    {
                        Plugin.log.Critical("Unable to parse response! Exception: " + e);
                    }
                }
            }
            else
            {
                _moreSongsListViewController.SetContent(currentSortSongs.GetRange(page * 6, Math.Min(6, currentSortSongs.Count - (currentPage * 6))));
            }

            _moreSongsListViewController.SetLoadingState(false);
        }
        public IEnumerator GetPage(int page, string sortBy)
        {
            yield return(null);

            _moreSongsListViewController.SetLoadingState(true);
            _moreSongsListViewController.TogglePageUpDownButtons((page > 0), true);
            _moreSongsListViewController.SetContent(null);

            UnityWebRequest www = UnityWebRequest.Get($"{PluginConfig.beatsaverURL}/api/songs/{sortBy}/{(page * 6)}");

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

            if (www.isNetworkError || www.isHttpError)
            {
                Plugin.log.Error($"Unable to connect to {PluginConfig.beatsaverURL}! " + (www.isNetworkError ? $"Network error: {www.error}" : (www.isHttpError ? $"HTTP error: {www.error}" : "Unknown error")));
            }
            else
            {
                try
                {
                    JSONNode node = JSON.Parse(www.downloadHandler.text);

                    currentPageSongs.Clear();

                    for (int i = 0; i < Math.Min(node["songs"].Count, songsPerPage); i++)
                    {
                        currentPageSongs.Add(new Song(node["songs"][i]));
                    }

                    _moreSongsListViewController.SetContent(currentPageSongs);
                }
                catch (Exception e)
                {
                    Plugin.log.Critical("Unable to parse response! Exception: " + e);
                }
            }
            _moreSongsListViewController.SetLoadingState(false);
        }