Example #1
0
        /// <summary>
        /// Creates a new <see cref="BindableStarDifficulty"/> and triggers an initial value update.
        /// </summary>
        /// <param name="beatmapInfo">The <see cref="BeatmapInfo"/> that star difficulty should correspond to.</param>
        /// <param name="initialRulesetInfo">The initial <see cref="RulesetInfo"/> to get the difficulty with.</param>
        /// <param name="initialMods">The initial <see cref="Mod"/>s to get the difficulty with.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> which stops updating the star difficulty for the given <see cref="BeatmapInfo"/>.</param>
        /// <returns>The <see cref="BindableStarDifficulty"/>.</returns>
        private BindableStarDifficulty createBindable([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo initialRulesetInfo, [CanBeNull] IEnumerable <Mod> initialMods,
                                                      CancellationToken cancellationToken)
        {
            var bindable = new BindableStarDifficulty(beatmapInfo, cancellationToken);

            updateBindable(bindable, initialRulesetInfo, initialMods, cancellationToken);
            return(bindable);
        }
Example #2
0
 /// <summary>
 /// Updates the value of a <see cref="BindableStarDifficulty"/> with a given ruleset + mods.
 /// </summary>
 /// <param name="bindable">The <see cref="BindableStarDifficulty"/> to update.</param>
 /// <param name="rulesetInfo">The <see cref="RulesetInfo"/> to update with.</param>
 /// <param name="mods">The <see cref="Mod"/>s to update with.</param>
 /// <param name="cancellationToken">A token that may be used to cancel this update.</param>
 private void updateBindable([NotNull] BindableStarDifficulty bindable, [CanBeNull] RulesetInfo rulesetInfo, [CanBeNull] IEnumerable <Mod> mods, CancellationToken cancellationToken = default)
 {
     GetDifficultyAsync(bindable.Beatmap, rulesetInfo, mods, cancellationToken).ContinueWith(t =>
     {
         // We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.
         Schedule(() =>
         {
             if (!cancellationToken.IsCancellationRequested)
             {
                 bindable.Value = t.Result;
             }
         });
     }, cancellationToken);
 }
Example #3
0
 /// <summary>
 /// Updates the value of a <see cref="BindableStarDifficulty"/> with a given ruleset + mods.
 /// </summary>
 /// <param name="bindable">The <see cref="BindableStarDifficulty"/> to update.</param>
 /// <param name="rulesetInfo">The <see cref="IRulesetInfo"/> to update with.</param>
 /// <param name="mods">The <see cref="Mod"/>s to update with.</param>
 /// <param name="cancellationToken">A token that may be used to cancel this update.</param>
 private void updateBindable([NotNull] BindableStarDifficulty bindable, [CanBeNull] IRulesetInfo rulesetInfo, [CanBeNull] IEnumerable <Mod> mods, CancellationToken cancellationToken = default)
 {
     // GetDifficultyAsync will fall back to existing data from IBeatmapInfo if not locally available
     // (contrary to GetAsync)
     GetDifficultyAsync(bindable.BeatmapInfo, rulesetInfo, mods, cancellationToken)
     .ContinueWith(t =>
     {
         // We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.
         Schedule(() =>
         {
             if (!cancellationToken.IsCancellationRequested && t.Result != null)
             {
                 bindable.Value = t.Result;
             }
         });
     }, cancellationToken);
 }