Example #1
0
        protected async Task <JobStats> GetScoreSaberAsync(BeatSyncConfig config, IJobBuilder jobBuilder, JobManager jobManager, CancellationToken cancellationToken)
        {
            ScoreSaberConfig sourceConfig = config.ScoreSaber;
            JobStats         sourceStats  = new JobStats();

            if (!sourceConfig.Enabled)
            {
                return(sourceStats);
            }
            ScoreSaberReader reader = new ScoreSaberReader();

            FeedConfigBase[] feedConfigs = new FeedConfigBase[] { sourceConfig.TopRanked, sourceConfig.LatestRanked, sourceConfig.Trending, sourceConfig.TopPlayed };
            if (!feedConfigs.Any(f => f.Enabled))
            {
                Logger.log?.Info($"No feeds enabled for {reader.Name}");
                return(sourceStats);
            }
            SourceStarted?.Invoke(this, "ScoreSaber");
            foreach (FeedConfigBase?feedConfig in feedConfigs.Where(c => c.Enabled))
            {
                Logger.log?.Info($"  Starting {feedConfig.GetType().Name} feed...");
                FeedResult results = await reader.GetSongsFromFeedAsync(feedConfig.ToFeedSettings()).ConfigureAwait(false);

                if (results.Successful)
                {
                    IEnumerable <IJob>?jobs       = CreateJobs(results, jobBuilder, jobManager, cancellationToken);
                    JobResult[]        jobResults = await Task.WhenAll(jobs.Select(j => j.JobTask).ToArray());

                    JobStats feedStats = new JobStats(jobResults);
                    ProcessFinishedJobs(jobs, jobBuilder.SongTargets, config, feedConfig);
                    Logger.log?.Info($"  Finished {feedConfig.GetType().Name} feed: ({feedStats}).");
                    sourceStats += feedStats;
                }
                else
                {
                    if (results.Exception != null)
                    {
                        Logger.log?.Error($"  Error getting results from {feedConfig.GetType().Name}: {results.Exception.Message}");
                        Logger.log?.Debug(results.Exception);
                    }
                    else
                    {
                        Logger.log?.Error($"  Error getting results from {feedConfig.GetType().Name}: Unknown error.");
                    }
                }
            }

            Logger.log?.Info($"  Finished ScoreSaber reading: ({sourceStats}).");
            return(sourceStats);
        }
Example #2
0
        public void Changed_ScoreSaber()
        {
            var c            = new PluginConfig();
            var defaultValue = c.ScoreSaber;
            var newValue     = new ScoreSaberConfig();

            Assert.AreEqual(defaultValue, c.ScoreSaber);
            c.ResetConfigChanged();
            Assert.IsFalse(c.ConfigChanged);

            c.ScoreSaber = newValue;

            Assert.IsTrue(c.ConfigChanged);
            Assert.AreEqual(newValue, c.ScoreSaber);
        }
Example #3
0
        public static void CreateScoreSaberSettingsUI(SubMenu parent, ScoreSaberConfig sourceConfig)
        {
            string sourceName = "ScoreSaber";

            CreateSourceSettings(sourceName, parent, sourceConfig);

            var latestRanked       = CreateFeedSettings("Latest Ranked", sourceName, sourceConfig.LatestRanked, parent);
            var topRanked          = CreateFeedSettings("Top Ranked", sourceName, sourceConfig.TopRanked, parent);
            var trending           = CreateFeedSettings("Trending", sourceName, sourceConfig.Trending, parent);
            var trendingRankedOnly = trending.AddBool("Ranked Only",
                                                      $"Get only ranked songs from the Trending feed.");

            trendingRankedOnly.GetValue += delegate { return(sourceConfig.Trending.RankedOnly); };
            trendingRankedOnly.SetValue += delegate(bool value)
            {
                if (sourceConfig.Trending.RankedOnly == value)
                {
                    return;
                }
                sourceConfig.Trending.RankedOnly = value;
                // Config.ConfigChanged = true;
            };
            var topPlayed           = CreateFeedSettings("Top Played", sourceName, sourceConfig.TopPlayed, parent);
            var topPlayedRankedOnly = topPlayed.AddBool("Ranked Only",
                                                        $"Get only ranked songs from the Trending feed.");

            topPlayedRankedOnly.GetValue += delegate { return(sourceConfig.TopPlayed.RankedOnly); };
            topPlayedRankedOnly.SetValue += delegate(bool value)
            {
                if (sourceConfig.TopPlayed.RankedOnly == value)
                {
                    return;
                }
                sourceConfig.TopPlayed.RankedOnly = value;
                // Config.ConfigChanged = true;
            };
        }