Example #1
0
        public int CompareTo(IRulesetInfo other)
        {
            if (!(other is RulesetInfo ruleset))
            {
                throw new ArgumentException($@"Object is not of type {nameof(RulesetInfo)}.", nameof(other));
            }

            return(CompareTo(ruleset));
        }
Example #2
0
        private void load()
        {
            maskingContainer.BorderColour = colours.Yellow;

            ruleset = rulesets.GetRuleset(Item.RulesetID);
            var rulesetInstance = ruleset?.CreateInstance();

            requiredMods = Item.RequiredMods.Select(m => m.ToMod(rulesetInstance)).ToArray();
        }
Example #3
0
        /// <summary>
        /// Initializes a new <see cref="Group"/>.
        /// </summary>
        /// <param name="id">Unique ID of new group.</param>
        /// <param name="color">The color of player who controlles the group.</param>
        /// <param name="info">Ruleset state.</param>
        public Group(int id, StoneColor color, IRulesetInfo info)
        {
            _id            = id;
            _groupColor    = color;
            _libertyCount  = 0;
            _members       = new List <Position>();
            _checkedInters = new bool[info.BoardSize.Width, info.BoardSize.Height];
            _rulesetInfo   = info;

            _rulesetInfo.GroupState.Groups[id] = this;
        }
Example #4
0
 public IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList <Mod> mods = null)
 {
     try
     {
         using (var cancellationTokenSource = new CancellationTokenSource(10_000))
         {
             // don't apply the default timeout when debugger is attached (may be breakpointing / debugging).
             return(GetPlayableBeatmap(ruleset, mods ?? Array.Empty <Mod>(), Debugger.IsAttached ? new CancellationToken() : cancellationTokenSource.Token));
         }
     }
     catch (OperationCanceledException)
     {
         throw new BeatmapLoadTimeoutException(BeatmapInfo);
     }
 }
Example #5
0
        public GetScoresRequest(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global, IEnumerable <IMod> mods = null)
        {
            if (beatmapInfo.OnlineID <= 0)
            {
                throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(IBeatmapInfo.OnlineID)}.");
            }

            if (scope == BeatmapLeaderboardScope.Local)
            {
                throw new InvalidOperationException("Should not attempt to request online scores for a local scoped leaderboard");
            }

            this.beatmapInfo = beatmapInfo;
            this.scope       = scope;
            this.ruleset     = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
            this.mods        = mods ?? Array.Empty <IMod>();
        }
Example #6
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);
 }
Example #7
0
 public GroupedDifficultyIcon(IEnumerable <IBeatmapInfo> beatmaps, IRulesetInfo ruleset, Color4 counterColour)
     : base(beatmaps.OrderBy(b => b.StarRating).Last(), ruleset, null, false)
 {
     AddInternal(new OsuSpriteText
     {
         Anchor  = Anchor.CentreRight,
         Origin  = Anchor.CentreRight,
         Padding = new MarginPadding {
             Left = Size.X
         },
         Margin = new MarginPadding {
             Left = 2, Right = 5
         },
         Font   = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),
         Text   = beatmaps.Count().ToString(),
         Colour = counterColour,
     });
 }
Example #8
0
        /// <summary>
        /// Initializes a new <see cref="Group"/> as a copy of the given group.
        /// </summary>
        /// <param name="group">The group to copy.</param>
        /// <param name="info">Ruleset state.</param>
        public Group(Group group, IRulesetInfo info)
        {
            _id           = group.ID;
            _groupColor   = group.GroupColor;
            _libertyCount = group.LibertyCount;
            _members      = new List <Position>();
            _members.AddRange(group.Members);
            _checkedInters = new bool[info.BoardSize.Width, info.BoardSize.Height];
            _rulesetInfo   = info;

            for (int i = 0; i < info.BoardSize.Width; i++)
            {
                for (int j = 0; j < info.BoardSize.Height; j++)
                {
                    _checkedInters[i, j] = group._checkedInters[i, j];
                }
            }
        }
Example #9
0
        /// <summary>
        /// Initializes a new <see cref="GroupState"/> as a copy of the given group state.
        /// </summary>
        /// <param name="groupState">The group state to copy.</param>
        /// <param name="info">Ruleset state.</param>
        public GroupState(GroupState groupState, IRulesetInfo info)
            : this(info)
        {
            for (int x = 0; x < info.BoardSize.Width; x++)
            {
                for (int y = 0; y < info.BoardSize.Height; y++)
                {
                    GroupMap[x, y] = groupState.GroupMap[x, y];
                }
            }

            for (int i = 0; i < groupState.Groups.Length; i++)
            {
                if (groupState.Groups[i] != null)
                {
                    Groups[i] = new Group(groupState.Groups[i], info);
                }
            }
        }
Example #10
0
 public InPlaylistGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
     : base(beatmapInfo, ruleset)
 {
 }
Example #11
0
 public SpectatingMultiplayerGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
     : base(beatmapInfo, ruleset)
 {
 }
Example #12
0
        /// <summary>
        /// Creates a new <see cref="BindableStarDifficulty"/> and triggers an initial value update.
        /// </summary>
        /// <param name="beatmapInfo">The <see cref="IBeatmapInfo"/> that star difficulty should correspond to.</param>
        /// <param name="initialRulesetInfo">The initial <see cref="IRulesetInfo"/> 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="IBeatmapInfo"/>.</param>
        /// <returns>The <see cref="BindableStarDifficulty"/>.</returns>
        private BindableStarDifficulty createBindable([NotNull] IBeatmapInfo beatmapInfo, [CanBeNull] IRulesetInfo initialRulesetInfo, [CanBeNull] IEnumerable <Mod> initialMods,
                                                      CancellationToken cancellationToken)
        {
            var bindable = new BindableStarDifficulty(beatmapInfo, cancellationToken);

            updateBindable(bindable, initialRulesetInfo, initialMods, cancellationToken);
            return(bindable);
        }
Example #13
0
        public virtual IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList <Mod> mods, CancellationToken token)
        {
            var rulesetInstance = ruleset.CreateInstance();

            if (rulesetInstance == null)
            {
                throw new RulesetLoadException("Creating ruleset instance failed when attempting to create playable beatmap.");
            }

            IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

            // Check if the beatmap can be converted
            if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
            {
                throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
            }

            // Apply conversion mods
            foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmapConverter(converter);
            }

            // Convert
            IBeatmap converted = converter.Convert(token);

            // Apply conversion mods to the result
            foreach (var mod in mods.OfType <IApplicableAfterBeatmapConversion>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            // Apply difficulty mods
            if (mods.Any(m => m is IApplicableToDifficulty))
            {
                foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToDifficulty(converted.Difficulty);
                }
            }

            IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

            foreach (var mod in mods.OfType <IApplicableToBeatmapProcessor>())
            {
                mod.ApplyToBeatmapProcessor(processor);
            }

            processor?.PreProcess();

            // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
            foreach (var obj in converted.HitObjects)
            {
                token.ThrowIfCancellationRequested();
                obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, token);
            }

            foreach (var mod in mods.OfType <IApplicableToHitObject>())
            {
                foreach (var obj in converted.HitObjects)
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToHitObject(obj);
                }
            }

            processor?.PostProcess();

            foreach (var mod in mods.OfType <IApplicableToBeatmap>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            return(converted);
        }
Example #14
0
 protected DifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
 {
     this.ruleset = ruleset;
     this.beatmap = beatmap;
 }
Example #15
0
 public DifficultyRetriever(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, IReadOnlyList <Mod> mods)
 {
     this.beatmapInfo = beatmapInfo;
     this.ruleset     = ruleset;
     this.mods        = mods;
 }
Example #16
0
 public GetUserRequest(long?userId = null, IRulesetInfo ruleset = null)
 {
     Lookup     = userId.ToString();
     lookupType = LookupType.Id;
     Ruleset    = ruleset;
 }
 public ManiaDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
     : base(ruleset, beatmap)
 {
     isForCurrentRuleset       = beatmap.BeatmapInfo.Ruleset.MatchesOnlineID(ruleset);
     originalOverallDifficulty = beatmap.BeatmapInfo.Difficulty.OverallDifficulty;
 }
Example #18
0
 /// <summary>
 /// Initializes a new <see cref="GroupState"/>.
 /// </summary>
 /// <param name="info">Ruleset state.</param>
 public GroupState(IRulesetInfo info)
 {
     _rulesetInfo = info;
     Groups       = new Group[info.BoardSize.Height * info.BoardSize.Width];
     GroupMap     = new int[info.BoardSize.Width, info.BoardSize.Height];
 }
Example #19
0
 public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList <Mod> mods, CancellationToken cancellationToken)
 => gameplayBeatmap;
Example #20
0
 public InSoloGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
     : base(beatmapInfo, ruleset)
 {
 }
Example #21
0
 /// <summary>
 /// Retrieves a bindable containing the star difficulty of a <see cref="IBeatmapInfo"/> with a given <see cref="RulesetInfo"/> and <see cref="Mod"/> combination.
 /// </summary>
 /// <remarks>
 /// The bindable will not update to follow the currently-selected ruleset and mods or its settings.
 /// </remarks>
 /// <param name="beatmapInfo">The <see cref="IBeatmapInfo"/> to get the difficulty of.</param>
 /// <param name="rulesetInfo">The <see cref="IRulesetInfo"/> to get the difficulty with. If <c>null</c>, the <paramref name="beatmapInfo"/>'s ruleset is used.</param>
 /// <param name="mods">The <see cref="Mod"/>s to get the difficulty with. If <c>null</c>, no mods will be assumed.</param>
 /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> which stops updating the star difficulty for the given <see cref="IBeatmapInfo"/>.</param>
 /// <returns>A bindable that is updated to contain the star difficulty when it becomes available. Will be null while in an initial calculating state.</returns>
 public IBindable <StarDifficulty?> GetBindableDifficulty([NotNull] IBeatmapInfo beatmapInfo, [CanBeNull] IRulesetInfo rulesetInfo, [CanBeNull] IEnumerable <Mod> mods,
                                                          CancellationToken cancellationToken = default)
 => createBindable(beatmapInfo, rulesetInfo, mods, cancellationToken);
Example #22
0
 public GetUserRequest(string username = null, IRulesetInfo ruleset = null)
 {
     Lookup     = username;
     lookupType = LookupType.Username;
     Ruleset    = ruleset;
 }
Example #23
0
 public EmptyFreeformDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
     : base(ruleset, beatmap)
 {
 }
 public PippidonDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
     : base(ruleset, beatmap)
 {
 }
Example #25
0
        private const double STAR_SCALING_FACTOR = 0.04125;         //Taken from Taiko's difficulty calculations

        public HitokoriDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap)
        {
        }
Example #26
0
 protected InGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
 {
     BeatmapInfo = beatmapInfo;
     Ruleset     = ruleset;
 }
Example #27
0
 public bool Equals(IRulesetInfo other) => other is RulesetInfo b && Equals(b);
Example #28
0
 public InMultiplayerGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
     : base(beatmapInfo, ruleset)
 {
 }
Example #29
0
 public static bool IsLegacyRuleset(this IRulesetInfo ruleset) => ruleset.OnlineID >= 0 && ruleset.OnlineID <= ILegacyRuleset.MAX_LEGACY_RULESET_ID;
Example #30
0
        /// <summary>
        /// Retrieves the difficulty of a <see cref="IBeatmapInfo"/>.
        /// </summary>
        /// <param name="beatmapInfo">The <see cref="IBeatmapInfo"/> to get the difficulty of.</param>
        /// <param name="rulesetInfo">The <see cref="IRulesetInfo"/> to get the difficulty with.</param>
        /// <param name="mods">The <see cref="Mod"/>s to get the difficulty with.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> which stops computing the star difficulty.</param>
        /// <returns>
        /// The requested <see cref="StarDifficulty"/>, if non-<see langword="null"/>.
        /// A <see langword="null"/> return value indicates that the difficulty process failed or was interrupted early,
        /// and as such there is no usable star difficulty value to be returned.
        /// </returns>
        public virtual Task <StarDifficulty?> GetDifficultyAsync([NotNull] IBeatmapInfo beatmapInfo, [CanBeNull] IRulesetInfo rulesetInfo = null,
                                                                 [CanBeNull] IEnumerable <Mod> mods = null, CancellationToken cancellationToken = default)
        {
            // In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
            rulesetInfo ??= beatmapInfo.Ruleset;

            var localBeatmapInfo = beatmapInfo as BeatmapInfo;
            var localRulesetInfo = rulesetInfo as RulesetInfo;

            // Difficulty can only be computed if the beatmap and ruleset are locally available.
            if (localBeatmapInfo?.IsManaged != true || localRulesetInfo == null)
            {
                // If not, fall back to the existing star difficulty (e.g. from an online source).
                return(Task.FromResult <StarDifficulty?>(new StarDifficulty(beatmapInfo.StarRating, (beatmapInfo as IBeatmapOnlineInfo)?.MaxCombo ?? 0)));
            }

            return(GetAsync(new DifficultyCacheLookup(localBeatmapInfo, localRulesetInfo, mods), cancellationToken));
        }