From a67e156883fb6f80aa10e3af6701ae2417181c48 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:09:45 +0900 Subject: [PATCH 01/28] Add `IBeatmapInfo` equality support --- osu.Game/Beatmaps/BeatmapInfo.cs | 11 +++++++++++ osu.Game/Beatmaps/IBeatmapInfo.cs | 3 ++- osu.Game/Models/RealmBeatmap.cs | 15 +++++++++++++++ .../Online/API/Requests/Responses/APIBeatmap.cs | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 5bbd48f26d..ea2346f060 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -151,6 +151,17 @@ namespace osu.Game.Beatmaps public override string ToString() => this.GetDisplayTitle(); + public bool Equals(IBeatmapInfo other) + { + if (other is BeatmapInfo b) + return Equals(b); + + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } + public bool Equals(BeatmapInfo other) { if (ID == 0 || other?.ID == 0) diff --git a/osu.Game/Beatmaps/IBeatmapInfo.cs b/osu.Game/Beatmaps/IBeatmapInfo.cs index 84ea6d3019..ab096b8897 100644 --- a/osu.Game/Beatmaps/IBeatmapInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapInfo.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Game.Database; using osu.Game.Rulesets; @@ -11,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A single beatmap difficulty. /// - public interface IBeatmapInfo : IHasOnlineID + public interface IBeatmapInfo : IHasOnlineID, IEquatable { /// /// The user-specified name given to this beatmap. diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index 9311425cb7..d1907d3ffd 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -98,6 +98,21 @@ namespace osu.Game.Models #endregion + #region Implementation of IEquatable + + public bool Equals(IBeatmapInfo? other) + { + if (other is RealmBeatmap b) + return b.ID == ID; + + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } + + #endregion + public bool AudioEquals(RealmBeatmap? other) => other != null && BeatmapSet != null && other.BeatmapSet != null diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index 2560502173..33098a2919 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -103,5 +103,17 @@ namespace osu.Game.Online.API.Requests.Responses public string Hash => throw new NotImplementedException(); #endregion + + #region Implementation of IEquatable + + public bool Equals(IBeatmapInfo? other) + { + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } + + #endregion } } From 54cd1158a4b198e55d6747fd98124e50d29aa401 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:14:11 +0900 Subject: [PATCH 02/28] Add `IBeatmapSetInfo` equality support --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 11 +++++++++++ osu.Game/Beatmaps/IBeatmapSetInfo.cs | 2 +- osu.Game/Models/RealmBeatmapSet.cs | 13 ++++++++++++- .../Online/API/Requests/Responses/APIBeatmapSet.cs | 12 ++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 0c93c4b9db..5bdaf26471 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -66,6 +66,17 @@ namespace osu.Game.Beatmaps public bool Protected { get; set; } + public bool Equals(IBeatmapSetInfo other) + { + if (other is BeatmapSetInfo b) + return Equals(b); + + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } + public bool Equals(BeatmapSetInfo other) { if (other == null) diff --git a/osu.Game/Beatmaps/IBeatmapSetInfo.cs b/osu.Game/Beatmaps/IBeatmapSetInfo.cs index 20c46d9063..67f38397d4 100644 --- a/osu.Game/Beatmaps/IBeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapSetInfo.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive. /// - public interface IBeatmapSetInfo : IHasOnlineID + public interface IBeatmapSetInfo : IHasOnlineID, IEquatable { /// /// The date when this beatmap was imported. diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index 6735510422..ddf2cf48fa 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -53,7 +53,16 @@ namespace osu.Game.Models /// The name of the file to get the storage path of. public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.StoragePath; - public override string ToString() => Metadata?.ToString() ?? base.ToString(); + public bool Equals(IBeatmapSetInfo? other) + { + if (other is RealmBeatmap b) + return b.ID == ID; + + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } public bool Equals(RealmBeatmapSet? other) { @@ -72,6 +81,8 @@ namespace osu.Game.Models return ReferenceEquals(this, other); } + public override string ToString() => Metadata?.ToString() ?? base.ToString(); + IEnumerable IBeatmapSetInfo.Beatmaps => Beatmaps; IEnumerable IBeatmapSetInfo.Files => Files; diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index 168e9d5d51..f4515c4258 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -141,5 +141,17 @@ namespace osu.Game.Online.API.Requests.Responses double IBeatmapSetInfo.MaxBPM => BPM; #endregion + + #region Implementation of IEquatable + + public bool Equals(IBeatmapSetInfo? other) + { + if (OnlineID > 0 && other?.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; + } + + #endregion } } From 7349e5521a0dbbb73b50ad7bbbab2f8e7db19c26 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:10:06 +0900 Subject: [PATCH 03/28] Update `BeatmapCollection` to use `IBeatmapInfo` --- osu.Game/Collections/BeatmapCollection.cs | 2 +- osu.Game/Collections/CollectionFilterDropdown.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Collections/BeatmapCollection.cs b/osu.Game/Collections/BeatmapCollection.cs index 7e4b15ecf9..1a739f824f 100644 --- a/osu.Game/Collections/BeatmapCollection.cs +++ b/osu.Game/Collections/BeatmapCollection.cs @@ -25,7 +25,7 @@ namespace osu.Game.Collections /// /// The beatmaps contained by the collection. /// - public readonly BindableList Beatmaps = new BindableList(); + public readonly BindableList Beatmaps = new BindableList(); /// /// The date when this collection was last modified. diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index 7067f82fd3..ad23874b2e 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -39,7 +39,7 @@ namespace osu.Game.Collections } private readonly IBindableList collections = new BindableList(); - private readonly IBindableList beatmaps = new BindableList(); + private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); [Resolved(CanBeNull = true)] @@ -200,7 +200,7 @@ namespace osu.Game.Collections private IBindable beatmap { get; set; } [CanBeNull] - private readonly BindableList collectionBeatmaps; + private readonly BindableList collectionBeatmaps; [NotNull] private readonly Bindable collectionName; From 1c49c4a6029942c8fa8a07efe18a2a34534597a1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:32:39 +0900 Subject: [PATCH 04/28] Fix incorrect type check --- osu.Game/Models/RealmBeatmapSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index ddf2cf48fa..3217abb419 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -55,7 +55,7 @@ namespace osu.Game.Models public bool Equals(IBeatmapSetInfo? other) { - if (other is RealmBeatmap b) + if (other is RealmBeatmapSet b) return b.ID == ID; if (OnlineID > 0 && other?.OnlineID > 0) From 63bc41556548be75ceab8fd9d1d0f5fb347d78b3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:35:42 +0900 Subject: [PATCH 05/28] Warn on suspicious types --- osu.sln.DotSettings | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.sln.DotSettings b/osu.sln.DotSettings index f35bdfce66..3fac94b243 100644 --- a/osu.sln.DotSettings +++ b/osu.sln.DotSettings @@ -209,6 +209,8 @@ WARNING SUGGESTION DO_NOT_SHOW + + True DO_NOT_SHOW WARNING WARNING From 1d962648c29bd3e06e2b7609698274f57256da80 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Nov 2021 18:48:34 +0900 Subject: [PATCH 06/28] Standardise implementations --- osu.Game/Beatmaps/BeatmapInfo.cs | 26 +++++++++++++---------- osu.Game/Beatmaps/BeatmapSetInfo.cs | 33 +++++++++++++---------------- osu.Game/Models/RealmBeatmap.cs | 22 +++++++++++++++---- osu.Game/Models/RealmBeatmapSet.cs | 32 ++++++++++++---------------- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index ea2346f060..211a5f4088 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -151,25 +151,29 @@ namespace osu.Game.Beatmaps public override string ToString() => this.GetDisplayTitle(); - public bool Equals(IBeatmapInfo other) + public bool Equals(BeatmapInfo other) { - if (other is BeatmapInfo b) - return Equals(b); + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; - if (OnlineID > 0 && other?.OnlineID > 0) - return other.OnlineID == OnlineID; + if (ID != 0 && other.ID != 0) + return ID == other.ID; return false; } - public bool Equals(BeatmapInfo other) + public bool Equals(IBeatmapInfo other) { - if (ID == 0 || other?.ID == 0) - // one of the two BeatmapInfos we are comparing isn't sourced from a database. - // fall back to reference equality. - return ReferenceEquals(this, other); + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; - return ID == other?.ID; + if (other is BeatmapInfo b && Equals(b)) + return true; + + if (OnlineID > 0 && other.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; } public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null && diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 5bdaf26471..51d049c8f9 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -66,32 +66,29 @@ namespace osu.Game.Beatmaps public bool Protected { get; set; } - public bool Equals(IBeatmapSetInfo other) - { - if (other is BeatmapSetInfo b) - return Equals(b); - - if (OnlineID > 0 && other?.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } - public bool Equals(BeatmapSetInfo other) { - if (other == null) - return false; + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; if (ID != 0 && other.ID != 0) return ID == other.ID; - if (OnlineBeatmapSetID.HasValue && other.OnlineBeatmapSetID.HasValue) - return OnlineBeatmapSetID == other.OnlineBeatmapSetID; + return false; + } - if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash)) - return Hash == other.Hash; + public bool Equals(IBeatmapSetInfo other) + { + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; - return ReferenceEquals(this, other); + if (other is BeatmapSetInfo b && Equals(b)) + return true; + + if (OnlineID > 0 && other.OnlineID > 0) + return other.OnlineID == OnlineID; + + return false; } #region Implementation of IHasOnlineID diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index d1907d3ffd..f80d1f513a 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -20,7 +20,7 @@ namespace osu.Game.Models [ExcludeFromDynamicCompile] [Serializable] [MapTo("Beatmap")] - public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo + public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo, IEquatable { [PrimaryKey] public Guid ID { get; set; } = Guid.NewGuid(); @@ -98,14 +98,28 @@ namespace osu.Game.Models #endregion + public bool Equals(RealmBeatmap? other) + { + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; + + return ID == other.ID; + } + #region Implementation of IEquatable public bool Equals(IBeatmapInfo? other) { - if (other is RealmBeatmap b) - return b.ID == ID; + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; - if (OnlineID > 0 && other?.OnlineID > 0) + if (other is RealmBeatmap b && Equals(b)) + return true; + + if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash)) + return Hash == other.Hash; + + if (OnlineID > 0 && other.OnlineID > 0) return other.OnlineID == OnlineID; return false; diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index 3217abb419..9cfa2de44d 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -53,32 +53,26 @@ namespace osu.Game.Models /// The name of the file to get the storage path of. public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.StoragePath; - public bool Equals(IBeatmapSetInfo? other) - { - if (other is RealmBeatmapSet b) - return b.ID == ID; - - if (OnlineID > 0 && other?.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } - public bool Equals(RealmBeatmapSet? other) { - if (other == null) - return false; + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; - if (IsManaged && other.IsManaged) - return ID == other.ID; + return ID == other.ID; + } + + public bool Equals(IBeatmapSetInfo? other) + { + if (ReferenceEquals(this, other)) return true; + if (other == null) return false; + + if (other is RealmBeatmapSet b && Equals(b)) + return true; if (OnlineID > 0 && other.OnlineID > 0) return OnlineID == other.OnlineID; - if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash)) - return Hash == other.Hash; - - return ReferenceEquals(this, other); + return false; } public override string ToString() => Metadata?.ToString() ?? base.ToString(); From a4c11e8813308b4bbd71489b711c9e556a7ca2f0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:34:50 +0900 Subject: [PATCH 07/28] Use extension method to compare online IDs --- osu.Game/Database/IHasOnlineID.cs | 3 +++ osu.Game/Extensions/ModelExtensions.cs | 29 ++++++++++++++++++++++++++ osu.Game/Overlays/Music/Playlist.cs | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/IHasOnlineID.cs b/osu.Game/Database/IHasOnlineID.cs index 4e83ed8876..7a720989cd 100644 --- a/osu.Game/Database/IHasOnlineID.cs +++ b/osu.Game/Database/IHasOnlineID.cs @@ -1,11 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; + #nullable enable namespace osu.Game.Database { public interface IHasOnlineID + where T : IEquatable { /// /// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID (except in special cases where autoincrement is not used, like rulesets). diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index d8e0938d46..2545045d96 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Users; @@ -57,5 +58,33 @@ namespace osu.Game.Extensions result ??= model?.ToString() ?? @"null"; return result; } + + /// + /// Check whether the online ID of two instances match. + /// + /// The instance to compare. + /// The other instance to compare against. + /// Whether online IDs match. If either instance is missing an online ID, this will return false. + public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + { + if (instance.OnlineID < 0 || other.OnlineID < 0) + return false; + + return instance.OnlineID.Equals(other.OnlineID); + } + + /// + /// Check whether the online ID of two instances match. + /// + /// The instance to compare. + /// The other instance to compare against. + /// Whether online IDs match. If either instance is missing an online ID, this will return false. + public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + { + if (instance.OnlineID < 0 || other.OnlineID < 0) + return false; + + return instance.OnlineID.Equals(other.OnlineID); + } } } diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs index 4fe338926f..5de62ebfb8 100644 --- a/osu.Game/Overlays/Music/Playlist.cs +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -7,6 +7,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Extensions; using osu.Game.Graphics.Containers; using osuTK; @@ -29,7 +30,7 @@ namespace osu.Game.Overlays.Music var items = (SearchContainer>)ListContainer; foreach (var item in items.OfType()) - item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.BeatmapSet.Equals(item.Model)) ?? true; + item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.MatchesOnlineID(item.Model)) ?? true; items.SearchTerm = criteria.SearchText; } From 0b4822b55225bb995bff04411082cc36cf42a3a6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:35:01 +0900 Subject: [PATCH 08/28] Remove newly added equality --- osu.Game/Beatmaps/BeatmapInfo.cs | 14 -------------- osu.Game/Beatmaps/BeatmapSetInfo.cs | 14 -------------- osu.Game/Beatmaps/IBeatmapInfo.cs | 3 +-- osu.Game/Beatmaps/IBeatmapSetInfo.cs | 2 +- osu.Game/Models/RealmBeatmap.cs | 21 --------------------- osu.Game/Models/RealmBeatmapSet.cs | 17 ++--------------- 6 files changed, 4 insertions(+), 67 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 0b234b3c2d..6f45f5ec71 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -163,20 +163,6 @@ namespace osu.Game.Beatmaps return false; } - public bool Equals(IBeatmapInfo other) - { - if (ReferenceEquals(this, other)) return true; - if (other == null) return false; - - if (other is BeatmapInfo b && Equals(b)) - return true; - - if (OnlineID > 0 && other.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } - public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null && BeatmapSet.Hash == other.BeatmapSet.Hash && (Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile; diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index fa314fe400..6dd8cc5ade 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -78,20 +78,6 @@ namespace osu.Game.Beatmaps return false; } - public bool Equals(IBeatmapSetInfo other) - { - if (ReferenceEquals(this, other)) return true; - if (other == null) return false; - - if (other is BeatmapSetInfo b && Equals(b)) - return true; - - if (OnlineID > 0 && other.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } - #region Implementation of IHasOnlineID int IHasOnlineID.OnlineID => OnlineID ?? -1; diff --git a/osu.Game/Beatmaps/IBeatmapInfo.cs b/osu.Game/Beatmaps/IBeatmapInfo.cs index ab096b8897..84ea6d3019 100644 --- a/osu.Game/Beatmaps/IBeatmapInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapInfo.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Game.Database; using osu.Game.Rulesets; @@ -12,7 +11,7 @@ namespace osu.Game.Beatmaps /// /// A single beatmap difficulty. /// - public interface IBeatmapInfo : IHasOnlineID, IEquatable + public interface IBeatmapInfo : IHasOnlineID { /// /// The user-specified name given to this beatmap. diff --git a/osu.Game/Beatmaps/IBeatmapSetInfo.cs b/osu.Game/Beatmaps/IBeatmapSetInfo.cs index 67f38397d4..20c46d9063 100644 --- a/osu.Game/Beatmaps/IBeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapSetInfo.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive. /// - public interface IBeatmapSetInfo : IHasOnlineID, IEquatable + public interface IBeatmapSetInfo : IHasOnlineID { /// /// The date when this beatmap was imported. diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index f80d1f513a..2a197d296a 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -106,27 +106,6 @@ namespace osu.Game.Models return ID == other.ID; } - #region Implementation of IEquatable - - public bool Equals(IBeatmapInfo? other) - { - if (ReferenceEquals(this, other)) return true; - if (other == null) return false; - - if (other is RealmBeatmap b && Equals(b)) - return true; - - if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash)) - return Hash == other.Hash; - - if (OnlineID > 0 && other.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } - - #endregion - public bool AudioEquals(RealmBeatmap? other) => other != null && BeatmapSet != null && other.BeatmapSet != null diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index 9cfa2de44d..1747cce67a 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -7,6 +7,7 @@ using System.Linq; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Extensions; using Realms; #nullable enable @@ -61,21 +62,7 @@ namespace osu.Game.Models return ID == other.ID; } - public bool Equals(IBeatmapSetInfo? other) - { - if (ReferenceEquals(this, other)) return true; - if (other == null) return false; - - if (other is RealmBeatmapSet b && Equals(b)) - return true; - - if (OnlineID > 0 && other.OnlineID > 0) - return OnlineID == other.OnlineID; - - return false; - } - - public override string ToString() => Metadata?.ToString() ?? base.ToString(); + public override string ToString() => Metadata?.GetDisplayString() ?? base.ToString(); IEnumerable IBeatmapSetInfo.Beatmaps => Beatmaps; From 18f73b985b82de1d0eb07a9e827ba53065330008 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:38:01 +0900 Subject: [PATCH 09/28] Make `ModelExtensions` nullable enabled --- osu.Game/Extensions/ModelExtensions.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index 2545045d96..48a3bac112 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -7,6 +7,8 @@ using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Users; +#nullable enable + namespace osu.Game.Extensions { public static class ModelExtensions @@ -23,9 +25,9 @@ namespace osu.Game.Extensions /// extension method type inference rules cause this method to call itself and cause a stack overflow. /// /// - public static string GetDisplayString(this object model) + public static string GetDisplayString(this object? model) { - string result = null; + string? result = null; switch (model) { @@ -65,8 +67,11 @@ namespace osu.Game.Extensions /// The instance to compare. /// The other instance to compare against. /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { + if (instance == null || other == null) + return false; + if (instance.OnlineID < 0 || other.OnlineID < 0) return false; @@ -79,8 +84,11 @@ namespace osu.Game.Extensions /// The instance to compare. /// The other instance to compare against. /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { + if (instance == null || other == null) + return false; + if (instance.OnlineID < 0 || other.OnlineID < 0) return false; From 93fe57d39970ee9c9dcc7dc0a757c2537aa10e55 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:43:31 +0900 Subject: [PATCH 10/28] Update tests to match new equality not including online ID checks --- osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs b/osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs index 938edf07c6..534983f869 100644 --- a/osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs +++ b/osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using osu.Game.Beatmaps; +using osu.Game.Extensions; namespace osu.Game.Tests.NonVisual { @@ -15,7 +16,8 @@ namespace osu.Game.Tests.NonVisual var ourInfo = new BeatmapSetInfo { OnlineID = 123 }; var otherInfo = new BeatmapSetInfo { OnlineID = 123 }; - Assert.AreEqual(ourInfo, otherInfo); + Assert.AreNotEqual(ourInfo, otherInfo); + Assert.IsTrue(ourInfo.MatchesOnlineID(otherInfo)); } [Test] @@ -33,7 +35,8 @@ namespace osu.Game.Tests.NonVisual var ourInfo = new BeatmapSetInfo { ID = 123, OnlineID = 12 }; var otherInfo = new BeatmapSetInfo { OnlineID = 12 }; - Assert.AreEqual(ourInfo, otherInfo); + Assert.AreNotEqual(ourInfo, otherInfo); + Assert.IsTrue(ourInfo.MatchesOnlineID(otherInfo)); } [Test] From 285b161da73612b3ed0f4f9c189730b6483cf024 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:38:14 +0900 Subject: [PATCH 11/28] Update other usages of online ID comparisons to use new extension method --- osu.Game/Online/API/Requests/Responses/APIBeatmap.cs | 9 ++------- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 9 ++------- osu.Game/Online/API/Requests/Responses/APIUser.cs | 3 ++- .../BeatmapListing/Panels/BeatmapPanelDownloadButton.cs | 3 ++- osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs | 3 ++- osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs | 3 ++- osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs | 3 ++- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index 33098a2919..bbffaee87b 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -4,6 +4,7 @@ using System; using Newtonsoft.Json; using osu.Game.Beatmaps; +using osu.Game.Extensions; using osu.Game.Rulesets; #nullable enable @@ -106,13 +107,7 @@ namespace osu.Game.Online.API.Requests.Responses #region Implementation of IEquatable - public bool Equals(IBeatmapInfo? other) - { - if (OnlineID > 0 && other?.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } + public bool Equals(IBeatmapInfo? other) => this.MatchesOnlineID(other); #endregion } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index f4515c4258..ab8287871f 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Extensions; #nullable enable @@ -144,13 +145,7 @@ namespace osu.Game.Online.API.Requests.Responses #region Implementation of IEquatable - public bool Equals(IBeatmapSetInfo? other) - { - if (OnlineID > 0 && other?.OnlineID > 0) - return other.OnlineID == OnlineID; - - return false; - } + public bool Equals(IBeatmapInfo? other) => this.MatchesOnlineID(other); #endregion } diff --git a/osu.Game/Online/API/Requests/Responses/APIUser.cs b/osu.Game/Online/API/Requests/Responses/APIUser.cs index 49edfd036b..50f5d67796 100644 --- a/osu.Game/Online/API/Requests/Responses/APIUser.cs +++ b/osu.Game/Online/API/Requests/Responses/APIUser.cs @@ -7,6 +7,7 @@ using System.Linq; using JetBrains.Annotations; using Newtonsoft.Json; using osu.Framework.Bindables; +using osu.Game.Extensions; using osu.Game.Users; namespace osu.Game.Online.API.Requests.Responses @@ -240,6 +241,6 @@ namespace osu.Game.Online.API.Requests.Responses public int OnlineID => Id; - public bool Equals(APIUser other) => OnlineID == other?.OnlineID; + public bool Equals(APIUser other) => this.MatchesOnlineID(other); } } diff --git a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs index 8c7846783d..1282a14c3d 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Extensions; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online; @@ -80,7 +81,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels case DownloadState.LocallyAvailable: Predicate findPredicate = null; if (SelectedBeatmap.Value != null) - findPredicate = b => b.OnlineID == SelectedBeatmap.Value.OnlineID; + findPredicate = b => b.MatchesOnlineID(SelectedBeatmap.Value); game?.PresentBeatmap(beatmapSet, findPredicate); break; diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs b/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs index b152375062..59e8e8db3c 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapPicker.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -166,7 +167,7 @@ namespace osu.Game.Overlays.BeatmapSet if (BeatmapSet != null) { Difficulties.ChildrenEnumerable = BeatmapSet.Beatmaps - .Where(b => b.Ruleset.OnlineID == ruleset.Value?.OnlineID) + .Where(b => b.Ruleset.MatchesOnlineID(ruleset.Value)) .OrderBy(b => b.StarRating) .Select(b => new DifficultySelectorButton(b) { diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs index b3b3d1980b..e8cdc6913b 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs @@ -7,6 +7,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Online.API.Requests.Responses; @@ -64,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapSet BeatmapSet.BindValueChanged(setInfo => { - int beatmapsCount = setInfo.NewValue?.Beatmaps.Count(b => b.Ruleset.OnlineID == Value.OnlineID) ?? 0; + int beatmapsCount = setInfo.NewValue?.Beatmaps.Count(b => b.Ruleset.MatchesOnlineID(Value)) ?? 0; count.Text = beatmapsCount.ToString(); countContainer.FadeTo(beatmapsCount > 0 ? 1 : 0); diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs index 22537c3ce0..56863cafad 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Screens; +using osu.Game.Extensions; using osu.Game.Online.Rooms; using osu.Game.Rulesets; using osu.Game.Scoring; @@ -32,7 +33,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists private void load(IBindable ruleset) { // Sanity checks to ensure that PlaylistsPlayer matches the settings for the current PlaylistItem - if (Beatmap.Value.BeatmapInfo.OnlineID != PlaylistItem.Beatmap.Value.OnlineID) + if (!Beatmap.Value.BeatmapInfo.MatchesOnlineID(PlaylistItem.Beatmap.Value)) throw new InvalidOperationException("Current Beatmap does not match PlaylistItem's Beatmap"); if (ruleset.Value.ID != PlaylistItem.Ruleset.Value.ID) From 611b9fe9422e5e33ae7845b911dceda44a7b6b24 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:50:09 +0900 Subject: [PATCH 12/28] Remove now unused implementations of interface equality --- osu.Game/Online/API/Requests/Responses/APIBeatmap.cs | 7 ------- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 7 ------- 2 files changed, 14 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index bbffaee87b..2560502173 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -4,7 +4,6 @@ using System; using Newtonsoft.Json; using osu.Game.Beatmaps; -using osu.Game.Extensions; using osu.Game.Rulesets; #nullable enable @@ -104,11 +103,5 @@ namespace osu.Game.Online.API.Requests.Responses public string Hash => throw new NotImplementedException(); #endregion - - #region Implementation of IEquatable - - public bool Equals(IBeatmapInfo? other) => this.MatchesOnlineID(other); - - #endregion } } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index ab8287871f..168e9d5d51 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Database; -using osu.Game.Extensions; #nullable enable @@ -142,11 +141,5 @@ namespace osu.Game.Online.API.Requests.Responses double IBeatmapSetInfo.MaxBPM => BPM; #endregion - - #region Implementation of IEquatable - - public bool Equals(IBeatmapInfo? other) => this.MatchesOnlineID(other); - - #endregion } } From 73cb80d8a44a0c69717a47acdb2adb09da341b1a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 16:00:45 +0900 Subject: [PATCH 13/28] Update one more missed usage --- osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs index 85efdcef1a..32ae7cf859 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs @@ -82,7 +82,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components { bool matchingFilter = true; - matchingFilter &= r.Room.Playlist.Count == 0 || criteria.Ruleset == null || r.Room.Playlist.Any(i => i.Ruleset.Value.Equals(criteria.Ruleset)); + matchingFilter &= r.Room.Playlist.Count == 0 || criteria.Ruleset == null || r.Room.Playlist.Any(i => i.Ruleset.Value.MatchesOnlineID(criteria.Ruleset)); if (!string.IsNullOrEmpty(criteria.SearchString)) matchingFilter &= r.FilterTerms.Any(term => term.Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase)); From 1988b263c60331f02fd973eee2da70f077ea78df Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 16:02:08 +0900 Subject: [PATCH 14/28] One more missed usage.. --- osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs index 56863cafad..35d417520e 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs @@ -36,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists if (!Beatmap.Value.BeatmapInfo.MatchesOnlineID(PlaylistItem.Beatmap.Value)) throw new InvalidOperationException("Current Beatmap does not match PlaylistItem's Beatmap"); - if (ruleset.Value.ID != PlaylistItem.Ruleset.Value.ID) + if (!ruleset.Value.MatchesOnlineID(PlaylistItem.Ruleset.Value)) throw new InvalidOperationException("Current Ruleset does not match PlaylistItem's Ruleset"); if (!PlaylistItem.RequiredMods.All(m => Mods.Value.Any(m.Equals))) From 5489b19c57f1f6d547d9d15efbdc2cd001ca062e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 16:13:03 +0900 Subject: [PATCH 15/28] Update `PlaylistItem` to use `IRulesetInfo` --- osu.Game/Online/Rooms/MultiplayerScore.cs | 5 +++-- osu.Game/Online/Rooms/PlaylistItem.cs | 4 ++-- osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs | 6 +++++- .../Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs | 6 +++++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/Rooms/MultiplayerScore.cs b/osu.Game/Online/Rooms/MultiplayerScore.cs index cfb81f0bad..7bc3377ad9 100644 --- a/osu.Game/Online/Rooms/MultiplayerScore.cs +++ b/osu.Game/Online/Rooms/MultiplayerScore.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json.Converters; using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -62,7 +63,7 @@ namespace osu.Game.Online.Rooms [CanBeNull] public MultiplayerScoresAround ScoresAround { get; set; } - public ScoreInfo CreateScoreInfo(PlaylistItem playlistItem, [NotNull] BeatmapInfo beatmap) + public ScoreInfo CreateScoreInfo(RulesetStore rulesets, PlaylistItem playlistItem, [NotNull] BeatmapInfo beatmap) { var rulesetInstance = playlistItem.Ruleset.Value.CreateInstance(); @@ -73,7 +74,7 @@ namespace osu.Game.Online.Rooms MaxCombo = MaxCombo, BeatmapInfo = beatmap, BeatmapInfoID = playlistItem.BeatmapID, - Ruleset = playlistItem.Ruleset.Value, + Ruleset = rulesets.GetRuleset(playlistItem.RulesetID), RulesetID = playlistItem.RulesetID, Statistics = Statistics, User = User, diff --git a/osu.Game/Online/Rooms/PlaylistItem.cs b/osu.Game/Online/Rooms/PlaylistItem.cs index cb550281a9..6f3d13b224 100644 --- a/osu.Game/Online/Rooms/PlaylistItem.cs +++ b/osu.Game/Online/Rooms/PlaylistItem.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online.Rooms public readonly Bindable Beatmap = new Bindable(); [JsonIgnore] - public readonly Bindable Ruleset = new Bindable(); + public readonly Bindable Ruleset = new Bindable(); [JsonIgnore] public readonly BindableList AllowedMods = new BindableList(); @@ -66,7 +66,7 @@ namespace osu.Game.Online.Rooms public PlaylistItem() { Beatmap.BindValueChanged(beatmap => BeatmapID = beatmap.NewValue?.OnlineID ?? -1); - Ruleset.BindValueChanged(ruleset => RulesetID = ruleset.NewValue?.ID ?? 0); + Ruleset.BindValueChanged(ruleset => RulesetID = ruleset.NewValue?.OnlineID ?? 0); } public void MapObjects(RulesetStore rulesets) diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 85cee46a29..817fb07d4b 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -46,7 +46,7 @@ namespace osu.Game.Screens.OnlinePlay private ModDisplay modDisplay; private readonly Bindable beatmap = new Bindable(); - private readonly Bindable ruleset = new Bindable(); + private readonly Bindable ruleset = new Bindable(); private readonly BindableList requiredMods = new BindableList(); public readonly PlaylistItem Item; diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index dc928d90e9..323d38c881 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -18,6 +18,7 @@ using osu.Game.Beatmaps; using osu.Game.Online.Rooms; using osu.Game.Overlays; using osu.Game.Overlays.Mods; +using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Screens.OnlinePlay.Match.Components; @@ -59,6 +60,9 @@ namespace osu.Game.Screens.OnlinePlay.Match [Resolved] private BeatmapManager beatmapManager { get; set; } + [Resolved] + private RulesetStore rulesets { get; set; } + [Resolved(canBeNull: true)] protected OnlinePlayScreen ParentScreen { get; private set; } @@ -344,7 +348,7 @@ namespace osu.Game.Screens.OnlinePlay.Match UpdateMods(); - Ruleset.Value = selected.Ruleset.Value; + Ruleset.Value = rulesets.GetRuleset(selected.RulesetID); if (!selected.AllowedMods.Any()) { diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs index 34698fccab..aed3635cbc 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs @@ -12,6 +12,7 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.Rooms; +using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Screens.Ranking; @@ -35,6 +36,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists [Resolved] private ScoreManager scoreManager { get; set; } + [Resolved] + private RulesetStore rulesets { get; set; } + public PlaylistsResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, bool allowRetry, bool allowWatchingReplay = true) : base(score, allowRetry, allowWatchingReplay) { @@ -169,7 +173,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// An optional pivot around which the scores were retrieved. private void performSuccessCallback([NotNull] Action> callback, [NotNull] List scores, [CanBeNull] MultiplayerScores pivot = null) { - var scoreInfos = scores.Select(s => s.CreateScoreInfo(playlistItem, Beatmap.Value.BeatmapInfo)).ToArray(); + var scoreInfos = scores.Select(s => s.CreateScoreInfo(rulesets, playlistItem, Beatmap.Value.BeatmapInfo)).ToArray(); // Score panels calculate total score before displaying, which can take some time. In order to count that calculation as part of the loading spinner display duration, // calculate the total scores locally before invoking the success callback. From 62d670a3cac537459ebe3cfdcaf66a4df3cfc328 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 18:19:23 +0900 Subject: [PATCH 16/28] Update `DifficultyCalculator` to take an `IWorkingBeatmap` --- .../EmptyFreeformDifficultyCalculator.cs | 2 +- .../EmptyFreeformRuleset.cs | 2 +- .../PippidonDifficultyCalculator.cs | 2 +- .../osu.Game.Rulesets.Pippidon/PippidonRuleset.cs | 2 +- .../EmptyScrollingDifficultyCalculator.cs | 2 +- .../EmptyScrollingRuleset.cs | 2 +- .../PippidonDifficultyCalculator.cs | 2 +- .../osu.Game.Rulesets.Pippidon/PippidonRuleset.cs | 2 +- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../Difficulty/CatchDifficultyCalculator.cs | 2 +- .../Difficulty/ManiaDifficultyCalculator.cs | 7 ++++--- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- .../Difficulty/OsuDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- .../Difficulty/TaikoDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 +- osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs | 2 +- osu.Game.Tests/Online/TestAPIModJsonSerialization.cs | 2 +- .../Online/TestAPIModMessagePackSerialization.cs | 2 +- osu.Game.Tests/Testing/TestSceneRulesetDependencies.cs | 2 +- .../Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs | 2 +- osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs | 2 +- osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs | 2 +- .../Visual/UserInterface/TestSceneModSettings.cs | 2 +- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 +- osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs | 4 ++-- osu.Game/Rulesets/Ruleset.cs | 4 ++-- 27 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs index a80f1178b6..34124a022d 100644 --- a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.EmptyFreeform { public class EmptyFreeformDifficultyCalculator : DifficultyCalculator { - public EmptyFreeformDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public EmptyFreeformDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs index 96675e3e99..bd928404d5 100644 --- a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs +++ b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs @@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.EmptyFreeform public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new EmptyFreeformBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new EmptyFreeformDifficultyCalculator(this, beatmap); public override IEnumerable GetModsFor(ModType type) diff --git a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs index 290148d14b..ef484e27bc 100644 --- a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Pippidon { public class PippidonDifficultyCalculator : DifficultyCalculator { - public PippidonDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public PippidonDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs index 89fed791cd..5f463e71f8 100644 --- a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs +++ b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Pippidon public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new PippidonBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new PippidonDifficultyCalculator(this, beatmap); public override IEnumerable GetModsFor(ModType type) diff --git a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs index f557a4c754..37c2b9f1eb 100644 --- a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.EmptyScrolling { public class EmptyScrollingDifficultyCalculator : DifficultyCalculator { - public EmptyScrollingDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public EmptyScrollingDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs index c1d4de52b7..940eaa1a55 100644 --- a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs +++ b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.EmptyScrolling public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new EmptyScrollingBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new EmptyScrollingDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new EmptyScrollingDifficultyCalculator(this, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs index 290148d14b..ef484e27bc 100644 --- a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Pippidon { public class PippidonDifficultyCalculator : DifficultyCalculator { - public PippidonDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public PippidonDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs index ede00f1510..4b1ef7c9a8 100644 --- a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs +++ b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Pippidon public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new PippidonBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new PippidonDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new PippidonDifficultyCalculator(this, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 93240d312b..c879398d23 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -178,7 +178,7 @@ namespace osu.Game.Rulesets.Catch return base.GetDisplayNameForHitResult(result); } - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new CatchDifficultyCalculator(this, beatmap); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new CatchLegacySkinTransformer(skin); diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs index 03a76f10ef..50ddbaba71 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty private float halfCatcherWidth; - public CatchDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public CatchDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs index aee3268544..640fdac225 100644 --- a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Game.Beatmaps; +using osu.Game.Extensions; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Skills; @@ -28,11 +29,11 @@ namespace osu.Game.Rulesets.Mania.Difficulty private readonly bool isForCurrentRuleset; private readonly double originalOverallDifficulty; - public ManiaDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public ManiaDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { - isForCurrentRuleset = beatmap.BeatmapInfo.Ruleset.Equals(ruleset.RulesetInfo); - originalOverallDifficulty = beatmap.BeatmapInfo.BaseDifficulty.OverallDifficulty; + isForCurrentRuleset = beatmap.BeatmapInfo.Ruleset.MatchesOnlineID(ruleset); + originalOverallDifficulty = beatmap.BeatmapInfo.Difficulty.OverallDifficulty; } protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index a9b16c61d4..d7d0fed846 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -272,7 +272,7 @@ namespace osu.Game.Rulesets.Mania public override Drawable CreateIcon() => new SpriteIcon { Icon = OsuIcon.RulesetMania }; - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new ManiaDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new ManiaDifficultyCalculator(this, beatmap); public int LegacyID => 3; diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs index 558ddc16ef..892b8da527 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty private const double difficulty_multiplier = 0.0675; private double hitWindowGreat; - public OsuDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public OsuDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index ee4712c3b8..6d50dc0a06 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Osu public override Drawable CreateIcon() => new SpriteIcon { Icon = OsuIcon.RulesetOsu }; - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new OsuDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new OsuDifficultyCalculator(this, beatmap); public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new OsuPerformanceCalculator(this, attributes, score); diff --git a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs index 7dd47e804b..31d7304184 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty private const double colour_skill_multiplier = 0.01; private const double stamina_skill_multiplier = 0.02; - public TaikoDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + public TaikoDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index adc924ba38..e4dea77377 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -168,7 +168,7 @@ namespace osu.Game.Rulesets.Taiko public override HitObjectComposer CreateHitObjectComposer() => new TaikoHitObjectComposer(this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new TaikoDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new TaikoDifficultyCalculator(this, beatmap); public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new TaikoPerformanceCalculator(this, attributes, score); diff --git a/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs b/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs index fd620a0e95..85b4688eb9 100644 --- a/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs +++ b/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs @@ -156,7 +156,7 @@ namespace osu.Game.Tests.Mods throw new System.NotImplementedException(); } - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) { throw new System.NotImplementedException(); } diff --git a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs index 656e333073..8378b33b3d 100644 --- a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs +++ b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs @@ -128,7 +128,7 @@ namespace osu.Game.Tests.Online public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException(); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException(); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); public override string Description { get; } = string.Empty; public override string ShortName { get; } = string.Empty; diff --git a/osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs b/osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs index 0462e9feb5..69e19826fd 100644 --- a/osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs +++ b/osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs @@ -90,7 +90,7 @@ namespace osu.Game.Tests.Online public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new System.NotImplementedException(); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new System.NotImplementedException(); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new System.NotImplementedException(); public override string Description { get; } = string.Empty; public override string ShortName { get; } = string.Empty; diff --git a/osu.Game.Tests/Testing/TestSceneRulesetDependencies.cs b/osu.Game.Tests/Testing/TestSceneRulesetDependencies.cs index 8c6932e792..bb9b705c7e 100644 --- a/osu.Game.Tests/Testing/TestSceneRulesetDependencies.cs +++ b/osu.Game.Tests/Testing/TestSceneRulesetDependencies.cs @@ -79,7 +79,7 @@ namespace osu.Game.Tests.Testing public override IEnumerable GetModsFor(ModType type) => Array.Empty(); public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) => null; public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => null; - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => null; + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null; } private class TestRulesetConfigManager : IRulesetConfigManager diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs index 3f10d7892d..e1755b8fc3 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs @@ -293,7 +293,7 @@ namespace osu.Game.Tests.Visual.Gameplay public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TestBeatmapConverter(beatmap, null); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException(); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); public override string Description { get; } = string.Empty; diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs index 0a39d94027..883b8a1ae0 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs @@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.Gameplay public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new System.NotImplementedException(); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new System.NotImplementedException(); public override IEnumerable GetDefaultKeyBindings(int variant = 0) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs index 17a009a2ce..911fffbe7f 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs @@ -182,7 +182,7 @@ namespace osu.Game.Tests.Visual.Gameplay public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TestBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException(); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); public override string Description { get; } = string.Empty; diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs index da0fa5d76d..4bb5e29589 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs @@ -199,7 +199,7 @@ namespace osu.Game.Tests.Visual.UserInterface public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException(); - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException(); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); public override string Description { get; } = "test"; public override string ShortName { get; } = "tst"; diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index acfd01a3c8..fcb44c462d 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -69,7 +69,7 @@ namespace osu.Game.Beatmaps public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new DummyBeatmapConverter { Beatmap = beatmap }; - public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => null; + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null; public override string Description => "dummy"; diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 5b4284dc2f..f9855a819f 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -27,9 +27,9 @@ namespace osu.Game.Rulesets.Difficulty private double clockRate; private readonly Ruleset ruleset; - private readonly WorkingBeatmap beatmap; + private readonly IWorkingBeatmap beatmap; - protected DifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) + protected DifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) { this.ruleset = ruleset; this.beatmap = beatmap; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b0c3836774..ade763eed8 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -222,7 +222,7 @@ namespace osu.Game.Rulesets /// The . public virtual IBeatmapProcessor CreateBeatmapProcessor(IBeatmap beatmap) => null; - public abstract DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap); + public abstract DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap); /// /// Optionally creates a to generate performance data from the provided score. @@ -240,7 +240,7 @@ namespace osu.Game.Rulesets /// The score to be processed. /// A performance calculator instance for the provided score. [CanBeNull] - public PerformanceCalculator CreatePerformanceCalculator(WorkingBeatmap beatmap, ScoreInfo score) + public PerformanceCalculator CreatePerformanceCalculator(IWorkingBeatmap beatmap, ScoreInfo score) { var difficultyCalculator = CreateDifficultyCalculator(beatmap); var difficultyAttributes = difficultyCalculator.Calculate(score.Mods); From 369b4ba789be41026c54979b24872284fb536e13 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 18:23:03 +0900 Subject: [PATCH 17/28] Update `DifficultyCalculator` to take an `IRulesetInfo` --- .../EmptyFreeformDifficultyCalculator.cs | 2 +- .../osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs | 2 +- .../PippidonDifficultyCalculator.cs | 2 +- .../osu.Game.Rulesets.Pippidon/PippidonRuleset.cs | 2 +- .../EmptyScrollingDifficultyCalculator.cs | 2 +- .../EmptyScrollingRuleset.cs | 2 +- .../PippidonDifficultyCalculator.cs | 2 +- .../osu.Game.Rulesets.Pippidon/PippidonRuleset.cs | 2 +- .../CatchDifficultyCalculatorTest.cs | 2 +- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../Difficulty/CatchDifficultyCalculator.cs | 2 +- .../ManiaDifficultyCalculatorTest.cs | 2 +- .../Difficulty/ManiaDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs | 2 +- osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- .../TaikoDifficultyCalculatorTest.cs | 2 +- .../Difficulty/TaikoDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 +- osu.Game/Beatmaps/IWorkingBeatmap.cs | 2 +- osu.Game/Beatmaps/WorkingBeatmap.cs | 2 +- osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs | 6 +++--- osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs | 2 +- 24 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs index 34124a022d..79be2b27da 100644 --- a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.EmptyFreeform { public class EmptyFreeformDifficultyCalculator : DifficultyCalculator { - public EmptyFreeformDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public EmptyFreeformDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs index bd928404d5..baf503085d 100644 --- a/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs +++ b/Templates/Rulesets/ruleset-empty/osu.Game.Rulesets.EmptyFreeform/EmptyFreeformRuleset.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.EmptyFreeform new EmptyFreeformBeatmapConverter(beatmap, this); public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => - new EmptyFreeformDifficultyCalculator(this, beatmap); + new EmptyFreeformDifficultyCalculator(RulesetInfo, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs index ef484e27bc..c612512938 100644 --- a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Pippidon { public class PippidonDifficultyCalculator : DifficultyCalculator { - public PippidonDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public PippidonDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs index 5f463e71f8..15e988f466 100644 --- a/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs +++ b/Templates/Rulesets/ruleset-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs @@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Pippidon new PippidonBeatmapConverter(beatmap, this); public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => - new PippidonDifficultyCalculator(this, beatmap); + new PippidonDifficultyCalculator(RulesetInfo, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs index 37c2b9f1eb..4628e6696b 100644 --- a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.EmptyScrolling { public class EmptyScrollingDifficultyCalculator : DifficultyCalculator { - public EmptyScrollingDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public EmptyScrollingDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs index 940eaa1a55..b9bed74c88 100644 --- a/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs +++ b/Templates/Rulesets/ruleset-scrolling-empty/osu.Game.Rulesets.EmptyScrolling/EmptyScrollingRuleset.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.EmptyScrolling public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new EmptyScrollingBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new EmptyScrollingDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new EmptyScrollingDifficultyCalculator(RulesetInfo, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs index ef484e27bc..c612512938 100644 --- a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs +++ b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonDifficultyCalculator.cs @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Pippidon { public class PippidonDifficultyCalculator : DifficultyCalculator { - public PippidonDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public PippidonDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs index 4b1ef7c9a8..ea94ceb4b5 100644 --- a/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs +++ b/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/PippidonRuleset.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Pippidon public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new PippidonBeatmapConverter(beatmap, this); - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new PippidonDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new PippidonDifficultyCalculator(RulesetInfo, beatmap); public override IEnumerable GetModsFor(ModType type) { diff --git a/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs index 2fab47f857..971c47a3b1 100644 --- a/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Catch.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new CatchModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(new CatchRuleset(), beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(new CatchRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new CatchRuleset(); } diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index c879398d23..70d11c42e5 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -178,7 +178,7 @@ namespace osu.Game.Rulesets.Catch return base.GetDisplayNameForHitResult(result); } - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new CatchDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new CatchDifficultyCalculator(RulesetInfo, beatmap); public override ISkin CreateLegacySkinProvider(ISkin skin, IBeatmap beatmap) => new CatchLegacySkinTransformer(skin); diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs index 50ddbaba71..77a783a10d 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty private float halfCatcherWidth; - public CatchDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public CatchDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs index 6e6500a339..a1cae855cf 100644 --- a/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Mania.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new ManiaModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new ManiaDifficultyCalculator(new ManiaRuleset(), beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new ManiaRuleset(); } diff --git a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs index 640fdac225..0040df72aa 100644 --- a/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Mania/Difficulty/ManiaDifficultyCalculator.cs @@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty private readonly bool isForCurrentRuleset; private readonly double originalOverallDifficulty; - public ManiaDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public ManiaDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { isForCurrentRuleset = beatmap.BeatmapInfo.Ruleset.MatchesOnlineID(ruleset); diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index d7d0fed846..b0e7545d3e 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -272,7 +272,7 @@ namespace osu.Game.Rulesets.Mania public override Drawable CreateIcon() => new SpriteIcon { Icon = OsuIcon.RulesetMania }; - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new ManiaDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new ManiaDifficultyCalculator(RulesetInfo, beatmap); public int LegacyID => 3; diff --git a/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs index 9148f0715c..6150927826 100644 --- a/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs @@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Osu.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new OsuModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new OsuDifficultyCalculator(new OsuRuleset(), beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new OsuDifficultyCalculator(new OsuRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new OsuRuleset(); } diff --git a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs index 892b8da527..3b4e85d0d3 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty private const double difficulty_multiplier = 0.0675; private double hitWindowGreat; - public OsuDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public OsuDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 6d50dc0a06..18e4bb259c 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Osu public override Drawable CreateIcon() => new SpriteIcon { Icon = OsuIcon.RulesetOsu }; - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new OsuDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new OsuDifficultyCalculator(RulesetInfo, beatmap); public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new OsuPerformanceCalculator(this, attributes, score); diff --git a/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs index 4b0b74ad27..a44c6a1ded 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Taiko.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new TaikoModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new TaikoDifficultyCalculator(new TaikoRuleset(), beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new TaikoDifficultyCalculator(new TaikoRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new TaikoRuleset(); } diff --git a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs index 31d7304184..606afdbabc 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/TaikoDifficultyCalculator.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty private const double colour_skill_multiplier = 0.01; private const double stamina_skill_multiplier = 0.02; - public TaikoDifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + public TaikoDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) : base(ruleset, beatmap) { } diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index e4dea77377..ca860f24c3 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -168,7 +168,7 @@ namespace osu.Game.Rulesets.Taiko public override HitObjectComposer CreateHitObjectComposer() => new TaikoHitObjectComposer(this); - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new TaikoDifficultyCalculator(this, beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new TaikoDifficultyCalculator(RulesetInfo, beatmap); public override PerformanceCalculator CreatePerformanceCalculator(DifficultyAttributes attributes, ScoreInfo score) => new TaikoPerformanceCalculator(this, attributes, score); diff --git a/osu.Game/Beatmaps/IWorkingBeatmap.cs b/osu.Game/Beatmaps/IWorkingBeatmap.cs index 22a922db59..27082916cb 100644 --- a/osu.Game/Beatmaps/IWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/IWorkingBeatmap.cs @@ -95,7 +95,7 @@ namespace osu.Game.Beatmaps /// The maximum length in milliseconds to wait for load to complete. Defaults to 10,000ms. /// The converted . /// If could not be converted to . - IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null); + IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null); /// /// Load a new audio track instance for this beatmap. This should be called once before accessing . diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 51eea94d3a..2ce1de380b 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -83,7 +83,7 @@ namespace osu.Game.Beatmaps /// The applicable . protected virtual IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap, Ruleset ruleset) => ruleset.CreateBeatmapConverter(beatmap); - public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) + public virtual IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) { using (var cancellationSource = createCancellationTokenSource(timeout)) { diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index f9855a819f..5e431d54de 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -26,10 +26,10 @@ namespace osu.Game.Rulesets.Difficulty private Mod[] playableMods; private double clockRate; - private readonly Ruleset ruleset; + private readonly IRulesetInfo ruleset; private readonly IWorkingBeatmap beatmap; - protected DifficultyCalculator(Ruleset ruleset, IWorkingBeatmap beatmap) + protected DifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) { this.ruleset = ruleset; this.beatmap = beatmap; @@ -116,7 +116,7 @@ namespace osu.Game.Rulesets.Difficulty { playableMods = mods.Select(m => m.DeepClone()).ToArray(); - Beatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, playableMods); + Beatmap = beatmap.GetPlayableBeatmap(ruleset, playableMods); var track = new TrackVirtual(10000); playableMods.OfType().ForEach(m => m.ApplyToTrack(track)); diff --git a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs index b4359fe518..e6c549c7a9 100644 --- a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs +++ b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs @@ -216,7 +216,7 @@ namespace osu.Game.Screens.Play.HUD this.gameplayBeatmap = gameplayBeatmap; } - public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) + public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) => gameplayBeatmap; protected override IBeatmap GetBeatmap() => gameplayBeatmap; From fabf253381a3b4b7ebf5ea84789e257d08f20e7e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 18:42:47 +0900 Subject: [PATCH 18/28] Update difficulty calculator tests to also use `IWorkingBeatmap` --- .../CatchDifficultyCalculatorTest.cs | 2 +- .../ManiaDifficultyCalculatorTest.cs | 2 +- osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs | 2 +- .../TaikoDifficultyCalculatorTest.cs | 2 +- osu.Game/Tests/Beatmaps/DifficultyCalculatorTest.cs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs index 971c47a3b1..7e8d567fbe 100644 --- a/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Catch.Tests/CatchDifficultyCalculatorTest.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Catch.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new CatchModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new CatchDifficultyCalculator(new CatchRuleset().RulesetInfo, beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new CatchDifficultyCalculator(new CatchRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new CatchRuleset(); } diff --git a/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs index a1cae855cf..6ec49d7634 100644 --- a/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Mania.Tests/ManiaDifficultyCalculatorTest.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Mania.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new ManiaModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new ManiaRuleset(); } diff --git a/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs index 6150927826..b7984e6995 100644 --- a/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Osu.Tests/OsuDifficultyCalculatorTest.cs @@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Osu.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new OsuModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new OsuDifficultyCalculator(new OsuRuleset().RulesetInfo, beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new OsuDifficultyCalculator(new OsuRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new OsuRuleset(); } diff --git a/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs b/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs index a44c6a1ded..2b1cbc580e 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TaikoDifficultyCalculatorTest.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Taiko.Tests public void TestClockRateAdjusted(double expected, string name) => Test(expected, name, new TaikoModDoubleTime()); - protected override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => new TaikoDifficultyCalculator(new TaikoRuleset().RulesetInfo, beatmap); + protected override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => new TaikoDifficultyCalculator(new TaikoRuleset().RulesetInfo, beatmap); protected override Ruleset CreateRuleset() => new TaikoRuleset(); } diff --git a/osu.Game/Tests/Beatmaps/DifficultyCalculatorTest.cs b/osu.Game/Tests/Beatmaps/DifficultyCalculatorTest.cs index e5b641b606..9f8811c7f9 100644 --- a/osu.Game/Tests/Beatmaps/DifficultyCalculatorTest.cs +++ b/osu.Game/Tests/Beatmaps/DifficultyCalculatorTest.cs @@ -28,7 +28,7 @@ namespace osu.Game.Tests.Beatmaps Assert.That(CreateDifficultyCalculator(getBeatmap(name)).Calculate(mods).StarRating, Is.EqualTo(expected).Within(0.00001)); } - private WorkingBeatmap getBeatmap(string name) + private IWorkingBeatmap getBeatmap(string name) { using (var resStream = openResource($"{resource_namespace}.{name}.osu")) using (var stream = new LineBufferedReader(resStream)) @@ -53,7 +53,7 @@ namespace osu.Game.Tests.Beatmaps return Assembly.LoadFrom(Path.Combine(localPath, $"{ResourceAssembly}.dll")).GetManifestResourceStream($@"{ResourceAssembly}.Resources.{name}"); } - protected abstract DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap); + protected abstract DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap); protected abstract Ruleset CreateRuleset(); } From 86b8fd37207850d0e611d6622590b4fd22603d4b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 18:05:10 +0900 Subject: [PATCH 19/28] Fix `TestSceneBeatmapRecommendations` testing with an online ID of 0 --- .../TestSceneBeatmapRecommendations.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs index a0742b862b..41e824a513 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs @@ -102,8 +102,8 @@ namespace osu.Game.Tests.Visual.SongSelect { BeatmapSetInfo catchSet = null, mixedSet = null; - AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(0, new[] { new CatchRuleset().RulesetInfo })); - AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1, + AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(1, new[] { new CatchRuleset().RulesetInfo })); + AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { catchSet, mixedSet })); @@ -120,8 +120,8 @@ namespace osu.Game.Tests.Visual.SongSelect { BeatmapSetInfo osuSet = null, mixedSet = null; - AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo })); - AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1, + AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); + AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet })); @@ -138,8 +138,8 @@ namespace osu.Game.Tests.Visual.SongSelect { BeatmapSetInfo osuSet = null, mixedSet = null; - AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo })); - AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1, + AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); + AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new TaikoRuleset().RulesetInfo })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet })); @@ -156,8 +156,8 @@ namespace osu.Game.Tests.Visual.SongSelect { BeatmapSetInfo osuSet = null, maniaSet = null; - AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo })); - AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(1, Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10))); + AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); + AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(2, Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10))); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, maniaSet })); From 485618091249455a7a6aa2b7472c877d2df1fc63 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 18:06:56 +0900 Subject: [PATCH 20/28] Use new helper method --- .../Visual/SongSelect/TestSceneBeatmapRecommendations.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs index 41e824a513..c9ec53cfd5 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs @@ -7,6 +7,7 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Testing; using osu.Game.Beatmaps; +using osu.Game.Extensions; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; @@ -203,11 +204,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("present beatmap", () => Game.PresentBeatmap(getImport())); AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect); - AddUntilStep("recommended beatmap displayed", () => - { - int? expectedID = getImport().Beatmaps[expectedDiff - 1].OnlineID; - return Game.Beatmap.Value.BeatmapInfo.OnlineID == expectedID; - }); + AddUntilStep("recommended beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.MatchesOnlineID(getImport().Beatmaps[expectedDiff - 1])); } } } From 3fe89293affaec4a0aae564e767341bcff2d0bca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:11:11 +0900 Subject: [PATCH 21/28] Add update manager which performs no update action This is to be used in cases where updates are handled by an external means. See https://github.com/flathub/flathub/pull/2619#issuecomment-969731305 for initial usage. --- osu.Desktop/OsuGameDesktop.cs | 5 ++ osu.Game/Updater/GitHubAsset.cs | 16 ++++++ osu.Game/Updater/GitHubRelease.cs | 20 +++++++ osu.Game/Updater/NoActionUpdateManager.cs | 67 +++++++++++++++++++++++ osu.Game/Updater/SimpleUpdateManager.cs | 23 -------- 5 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 osu.Game/Updater/GitHubAsset.cs create mode 100644 osu.Game/Updater/GitHubRelease.cs create mode 100644 osu.Game/Updater/NoActionUpdateManager.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 19e1252a4d..645ea66654 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -93,6 +93,11 @@ namespace osu.Desktop protected override UpdateManager CreateUpdateManager() { + string packageManaged = Environment.GetEnvironmentVariable("OSU_EXTERNAL_UPDATE_PROVIDER"); + + if (!string.IsNullOrEmpty(packageManaged)) + return new NoActionUpdateManager(); + switch (RuntimeInfo.OS) { case RuntimeInfo.Platform.Windows: diff --git a/osu.Game/Updater/GitHubAsset.cs b/osu.Game/Updater/GitHubAsset.cs new file mode 100644 index 0000000000..4783161859 --- /dev/null +++ b/osu.Game/Updater/GitHubAsset.cs @@ -0,0 +1,16 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Updater +{ + public class GitHubAsset + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("browser_download_url")] + public string BrowserDownloadUrl { get; set; } + } +} diff --git a/osu.Game/Updater/GitHubRelease.cs b/osu.Game/Updater/GitHubRelease.cs new file mode 100644 index 0000000000..363b2b628f --- /dev/null +++ b/osu.Game/Updater/GitHubRelease.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace osu.Game.Updater +{ + public class GitHubRelease + { + [JsonProperty("html_url")] + public string HtmlUrl { get; set; } + + [JsonProperty("tag_name")] + public string TagName { get; set; } + + [JsonProperty("assets")] + public List Assets { get; set; } + } +} diff --git a/osu.Game/Updater/NoActionUpdateManager.cs b/osu.Game/Updater/NoActionUpdateManager.cs new file mode 100644 index 0000000000..641263ed0f --- /dev/null +++ b/osu.Game/Updater/NoActionUpdateManager.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Linq; +using System.Threading.Tasks; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Platform; +using osu.Game.Online.API; +using osu.Game.Overlays.Notifications; + +namespace osu.Game.Updater +{ + /// + /// An update manager that shows notifications if a newer release is detected. + /// This is a case where updates are handled externally by a package manager or other means, so no action is performed on clicking the notification. + /// + public class NoActionUpdateManager : UpdateManager + { + private string version; + + [Resolved] + private GameHost host { get; set; } + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + version = game.Version; + } + + protected override async Task PerformUpdateCheck() + { + try + { + var releases = new OsuJsonWebRequest("https://api.github.com/repos/ppy/osu/releases/latest"); + + await releases.PerformAsync().ConfigureAwait(false); + + var latest = releases.ResponseObject; + + // avoid any discrepancies due to build suffixes for now. + // eventually we will want to support release streams and consider these. + version = version.Split('-').First(); + string latestTagName = latest.TagName.Split('-').First(); + + if (latestTagName != version) + { + Notifications.Post(new SimpleNotification + { + Text = $"A newer release of osu! has been found ({version} → {latestTagName}).\n\n" + + "Check with your package manager / provider to bring osu! up-to-date!", + Icon = FontAwesome.Solid.Upload, + }); + + return true; + } + } + catch + { + // we shouldn't crash on a web failure. or any failure for the matter. + return true; + } + + return false; + } + } +} diff --git a/osu.Game/Updater/SimpleUpdateManager.cs b/osu.Game/Updater/SimpleUpdateManager.cs index 5e466cc57f..61ca68a1ab 100644 --- a/osu.Game/Updater/SimpleUpdateManager.cs +++ b/osu.Game/Updater/SimpleUpdateManager.cs @@ -2,10 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Newtonsoft.Json; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; @@ -104,26 +102,5 @@ namespace osu.Game.Updater return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl; } - - public class GitHubRelease - { - [JsonProperty("html_url")] - public string HtmlUrl { get; set; } - - [JsonProperty("tag_name")] - public string TagName { get; set; } - - [JsonProperty("assets")] - public List Assets { get; set; } - } - - public class GitHubAsset - { - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("browser_download_url")] - public string BrowserDownloadUrl { get; set; } - } } } From 9207b87b7686ccef1ec9b17492b353ae51fb720d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:25:37 +0900 Subject: [PATCH 22/28] Add back interface equality but limit to only matching types --- osu.Game/Beatmaps/BeatmapInfo.cs | 2 ++ osu.Game/Beatmaps/BeatmapSetInfo.cs | 2 ++ osu.Game/Beatmaps/IBeatmapInfo.cs | 3 ++- osu.Game/Beatmaps/IBeatmapSetInfo.cs | 2 +- osu.Game/Models/RealmBeatmap.cs | 2 ++ osu.Game/Models/RealmBeatmapSet.cs | 2 ++ osu.Game/Online/API/Requests/Responses/APIBeatmap.cs | 2 ++ osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 2 ++ 8 files changed, 15 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 6f45f5ec71..d2b322a843 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -163,6 +163,8 @@ namespace osu.Game.Beatmaps return false; } + public bool Equals(IBeatmapInfo other) => other is BeatmapInfo b && Equals(b); + public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null && BeatmapSet.Hash == other.BeatmapSet.Hash && (Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile; diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 6dd8cc5ade..a0de50a311 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -78,6 +78,8 @@ namespace osu.Game.Beatmaps return false; } + public bool Equals(IBeatmapSetInfo other) => other is BeatmapSetInfo b && Equals(b); + #region Implementation of IHasOnlineID int IHasOnlineID.OnlineID => OnlineID ?? -1; diff --git a/osu.Game/Beatmaps/IBeatmapInfo.cs b/osu.Game/Beatmaps/IBeatmapInfo.cs index 84ea6d3019..ab096b8897 100644 --- a/osu.Game/Beatmaps/IBeatmapInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapInfo.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Game.Database; using osu.Game.Rulesets; @@ -11,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A single beatmap difficulty. /// - public interface IBeatmapInfo : IHasOnlineID + public interface IBeatmapInfo : IHasOnlineID, IEquatable { /// /// The user-specified name given to this beatmap. diff --git a/osu.Game/Beatmaps/IBeatmapSetInfo.cs b/osu.Game/Beatmaps/IBeatmapSetInfo.cs index 20c46d9063..67f38397d4 100644 --- a/osu.Game/Beatmaps/IBeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapSetInfo.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive. /// - public interface IBeatmapSetInfo : IHasOnlineID + public interface IBeatmapSetInfo : IHasOnlineID, IEquatable { /// /// The date when this beatmap was imported. diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index 2a197d296a..1a25d55d04 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -106,6 +106,8 @@ namespace osu.Game.Models return ID == other.ID; } + public bool Equals(IBeatmapInfo? other) => other is RealmBeatmap b && Equals(b); + public bool AudioEquals(RealmBeatmap? other) => other != null && BeatmapSet != null && other.BeatmapSet != null diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index 1747cce67a..b9b47b697c 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -64,6 +64,8 @@ namespace osu.Game.Models public override string ToString() => Metadata?.GetDisplayString() ?? base.ToString(); + public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b); + IEnumerable IBeatmapSetInfo.Beatmaps => Beatmaps; IEnumerable IBeatmapSetInfo.Files => Files; diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index 2560502173..e90de5bdb7 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -103,5 +103,7 @@ namespace osu.Game.Online.API.Requests.Responses public string Hash => throw new NotImplementedException(); #endregion + + public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && Equals(b); } } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index 168e9d5d51..2628880588 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -141,5 +141,7 @@ namespace osu.Game.Online.API.Requests.Responses double IBeatmapSetInfo.MaxBPM => BPM; #endregion + + public bool Equals(IBeatmapSetInfo? other) => other is APIBeatmapSet b && Equals(b); } } From 68e269904377205b62661aac719c886be9ba320d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:28:57 +0900 Subject: [PATCH 23/28] Fix oversight in playlist matching logic --- osu.Game/Overlays/Music/Playlist.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs index 5de62ebfb8..0b15a3a1bc 100644 --- a/osu.Game/Overlays/Music/Playlist.cs +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -7,7 +7,6 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; -using osu.Game.Extensions; using osu.Game.Graphics.Containers; using osuTK; @@ -30,7 +29,7 @@ namespace osu.Game.Overlays.Music var items = (SearchContainer>)ListContainer; foreach (var item in items.OfType()) - item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.MatchesOnlineID(item.Model)) ?? true; + item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => item.Model.Equals(b.BeatmapSet)) ?? true; items.SearchTerm = criteria.SearchText; } From fbc46941fa1beab0c846176c113b9a360936dd8b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:37:47 +0900 Subject: [PATCH 24/28] Add type safety to `MatchesOnlineID` extension methods --- osu.Game/Extensions/ModelExtensions.cs | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index 48a3bac112..c8561ecdb3 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -62,12 +62,30 @@ namespace osu.Game.Extensions } /// - /// Check whether the online ID of two instances match. + /// Check whether the online ID of two s match. /// /// The instance to compare. /// The other instance to compare against. /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) + public static bool MatchesOnlineID(this IBeatmapSetInfo? instance, IBeatmapSetInfo? other) => matchesOnlineID(instance, other); + + /// + /// Check whether the online ID of two s match. + /// + /// The instance to compare. + /// The other instance to compare against. + /// Whether online IDs match. If either instance is missing an online ID, this will return false. + public static bool MatchesOnlineID(this IBeatmapInfo? instance, IBeatmapInfo? other) => matchesOnlineID(instance, other); + + /// + /// Check whether the online ID of two s match. + /// + /// The instance to compare. + /// The other instance to compare against. + /// Whether online IDs match. If either instance is missing an online ID, this will return false. + public static bool MatchesOnlineID(this IRulesetInfo? instance, IRulesetInfo? other) => matchesOnlineID(instance, other); + + private static bool matchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { if (instance == null || other == null) return false; @@ -78,13 +96,7 @@ namespace osu.Game.Extensions return instance.OnlineID.Equals(other.OnlineID); } - /// - /// Check whether the online ID of two instances match. - /// - /// The instance to compare. - /// The other instance to compare against. - /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) + private static bool matchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { if (instance == null || other == null) return false; From 2cbdac91ad02b84e9ec7c04685d6d55f2c574d92 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:44:20 +0900 Subject: [PATCH 25/28] Add missing `APIUser` comparison method --- osu.Game/Extensions/ModelExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index c8561ecdb3..3426484c14 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -3,6 +3,7 @@ using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Users; @@ -85,6 +86,14 @@ namespace osu.Game.Extensions /// Whether online IDs match. If either instance is missing an online ID, this will return false. public static bool MatchesOnlineID(this IRulesetInfo? instance, IRulesetInfo? other) => matchesOnlineID(instance, other); + /// + /// Check whether the online ID of two s match. + /// + /// The instance to compare. + /// The other instance to compare against. + /// Whether online IDs match. If either instance is missing an online ID, this will return false. + public static bool MatchesOnlineID(this APIUser? instance, APIUser? other) => matchesOnlineID(instance, other); + private static bool matchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { if (instance == null || other == null) From 71fef241dff90f4d9e9979396596bd15022e9c1c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 14:13:47 +0900 Subject: [PATCH 26/28] Fix recursive equality call on `APIBeatmap` and `APIBeatmapSet` --- osu.Game/Online/API/Requests/Responses/APIBeatmap.cs | 3 ++- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index e90de5bdb7..3fb9335629 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -4,6 +4,7 @@ using System; using Newtonsoft.Json; using osu.Game.Beatmaps; +using osu.Game.Extensions; using osu.Game.Rulesets; #nullable enable @@ -104,6 +105,6 @@ namespace osu.Game.Online.API.Requests.Responses #endregion - public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && Equals(b); + public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && this.MatchesOnlineID(b); } } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index 2628880588..8d50f3d7dd 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Extensions; #nullable enable @@ -142,6 +143,6 @@ namespace osu.Game.Online.API.Requests.Responses #endregion - public bool Equals(IBeatmapSetInfo? other) => other is APIBeatmapSet b && Equals(b); + public bool Equals(IBeatmapSetInfo? other) => other is APIBeatmapSet b && this.MatchesOnlineID(b); } } From 2dd721f7609480d212051bc80f214b3fc5068b3c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 17:41:16 +0900 Subject: [PATCH 27/28] Fix incorrect `CancellationToken` being used for inner check during leaderboard updates --- .../Screens/Select/Leaderboards/BeatmapLeaderboard.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 9c8ccee99b..03da930c5c 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -116,6 +116,8 @@ namespace osu.Game.Screens.Select.Leaderboards loadCancellationSource?.Cancel(); loadCancellationSource = new CancellationTokenSource(); + var cancellationToken = loadCancellationSource.Token; + if (BeatmapInfo == null) { PlaceholderState = PlaceholderState.NoneSelected; @@ -140,7 +142,7 @@ namespace osu.Game.Screens.Select.Leaderboards scores = scores.Where(s => s.Mods.Any(m => selectedMods.Contains(m.Acronym))); } - scoreManager.OrderByTotalScoreAsync(scores.ToArray(), loadCancellationSource.Token) + scoreManager.OrderByTotalScoreAsync(scores.ToArray(), cancellationToken) .ContinueWith(ordered => scoresCallback?.Invoke(ordered.Result), TaskContinuationOptions.OnlyOnRanToCompletion); return null; @@ -176,10 +178,10 @@ namespace osu.Game.Screens.Select.Leaderboards req.Success += r => { - scoreManager.OrderByTotalScoreAsync(r.Scores.Select(s => s.CreateScoreInfo(rulesets, BeatmapInfo)).ToArray(), loadCancellationSource.Token) + scoreManager.OrderByTotalScoreAsync(r.Scores.Select(s => s.CreateScoreInfo(rulesets, BeatmapInfo)).ToArray(), cancellationToken) .ContinueWith(ordered => Schedule(() => { - if (loadCancellationSource.IsCancellationRequested) + if (cancellationToken.IsCancellationRequested) return; scoresCallback?.Invoke(ordered.Result); From f74afb48fdc424ecf1c08c1e60a33de0b75623ff Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 17:50:51 +0900 Subject: [PATCH 28/28] Fix `StandAloneChatDisplay`'s `TextBox` having different corner radius --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index ede76235b1..1f8d05fcd1 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -41,8 +41,10 @@ namespace osu.Game.Online.Chat /// Whether a textbox for posting new messages should be displayed. public StandAloneChatDisplay(bool postingTextbox = false) { + const float corner_radius = 10; + this.postingTextbox = postingTextbox; - CornerRadius = 10; + CornerRadius = corner_radius; Masking = true; InternalChildren = new Drawable[] @@ -62,6 +64,7 @@ namespace osu.Game.Online.Chat RelativeSizeAxes = Axes.X, Height = textbox_height, PlaceholderText = "type your message", + CornerRadius = corner_radius, ReleaseFocusOnCommit = false, HoldFocus = true, Anchor = Anchor.BottomLeft,