mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 16:13:34 +08:00
Add LegacyOnlineID
handling to places that definitely need it
Mostly places that can interact with imported replays. There are other places that use the online ID as a sort tiebreaker, or to check presence of a score on results screens, but they should probably still continue to only use `OnlineID`, since all scores with a legacy online ID should have an online ID, but the converse is not generally true.
This commit is contained in:
parent
c53f4c144c
commit
b144cfd55c
@ -114,8 +114,24 @@ namespace osu.Game.Extensions
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to compare.</param>
|
||||
/// <param name="other">The other instance to compare against.</param>
|
||||
/// <returns>Whether online IDs match. If either instance is missing an online ID, this will return false.</returns>
|
||||
public static bool MatchesOnlineID(this IScoreInfo? instance, IScoreInfo? other) => matchesOnlineID(instance, other);
|
||||
/// <returns>
|
||||
/// Whether online IDs match.
|
||||
/// Both <see cref="IHasOnlineID{T}.OnlineID"/> and <see cref="IScoreInfo.LegacyOnlineID"/> are checked, in that order.
|
||||
/// If either instance is missing an online ID, this will return false.
|
||||
/// </returns>
|
||||
public static bool MatchesOnlineID(this IScoreInfo? instance, IScoreInfo? other)
|
||||
{
|
||||
if (matchesOnlineID(instance, other))
|
||||
return true;
|
||||
|
||||
if (instance == null || other == null)
|
||||
return false;
|
||||
|
||||
if (instance.LegacyOnlineID < 0 || other.LegacyOnlineID < 0)
|
||||
return false;
|
||||
|
||||
return instance.LegacyOnlineID.Equals(other.LegacyOnlineID);
|
||||
}
|
||||
|
||||
private static bool matchesOnlineID(this IHasOnlineID<long>? instance, IHasOnlineID<long>? other)
|
||||
{
|
||||
|
@ -39,7 +39,8 @@ namespace osu.Game.Online
|
||||
var scoreInfo = new ScoreInfo
|
||||
{
|
||||
ID = TrackedItem.ID,
|
||||
OnlineID = TrackedItem.OnlineID
|
||||
OnlineID = TrackedItem.OnlineID,
|
||||
LegacyOnlineID = TrackedItem.LegacyOnlineID
|
||||
};
|
||||
|
||||
Downloader.DownloadBegan += downloadBegan;
|
||||
@ -47,6 +48,7 @@ namespace osu.Game.Online
|
||||
|
||||
realmSubscription = realm.RegisterForNotifications(r => r.All<ScoreInfo>().Where(s =>
|
||||
((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID)
|
||||
|| (s.LegacyOnlineID > 0 && s.LegacyOnlineID == TrackedItem.LegacyOnlineID)
|
||||
|| (!string.IsNullOrEmpty(s.Hash) && s.Hash == TrackedItem.Hash))
|
||||
&& !s.DeletePending), (items, _) =>
|
||||
{
|
||||
|
@ -678,6 +678,9 @@ namespace osu.Game
|
||||
if (score.OnlineID > 0)
|
||||
databasedScoreInfo = ScoreManager.Query(s => s.OnlineID == score.OnlineID);
|
||||
|
||||
if (score.LegacyOnlineID > 0)
|
||||
databasedScoreInfo ??= ScoreManager.Query(s => s.LegacyOnlineID == score.LegacyOnlineID);
|
||||
|
||||
if (score is ScoreInfo scoreInfo)
|
||||
databasedScoreInfo ??= ScoreManager.Query(s => s.Hash == scoreInfo.Hash);
|
||||
|
||||
|
@ -24,6 +24,8 @@ namespace osu.Game.Scoring
|
||||
|
||||
bool HasReplay { get; }
|
||||
|
||||
long LegacyOnlineID { get; }
|
||||
|
||||
DateTimeOffset Date { get; }
|
||||
|
||||
double? PP { get; }
|
||||
|
@ -150,7 +150,11 @@ namespace osu.Game.Scoring
|
||||
|
||||
public Task Import(ImportTask[] imports, ImportParameters parameters = default) => scoreImporter.Import(imports, parameters);
|
||||
|
||||
public override bool IsAvailableLocally(ScoreInfo model) => Realm.Run(realm => realm.All<ScoreInfo>().Any(s => s.OnlineID == model.OnlineID));
|
||||
public override bool IsAvailableLocally(ScoreInfo model)
|
||||
=> Realm.Run(realm => realm.All<ScoreInfo>()
|
||||
// this basically inlines `ModelExtension.MatchesOnlineID(IScoreInfo, IScoreInfo)`,
|
||||
// because that method can't be used here, as realm can't translate it to its query language.
|
||||
.Any(s => s.OnlineID == model.OnlineID || s.LegacyOnlineID == model.LegacyOnlineID));
|
||||
|
||||
public IEnumerable<string> HandledExtensions => scoreImporter.HandledExtensions;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user