mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 02:23:21 +08:00
Merge pull request #22539 from Cootz/BitmapUpdatesOnScore
Fix local scores set against a different version of a beatmap still showing in leaderboards
This commit is contained in:
commit
7d5a74b281
@ -176,6 +176,7 @@ namespace osu.Game.Tests.Resources
|
||||
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
||||
},
|
||||
BeatmapInfo = beatmap,
|
||||
BeatmapHash = beatmap.Hash,
|
||||
Ruleset = beatmap.Ruleset,
|
||||
Mods = new Mod[] { new TestModHardRock(), new TestModDoubleTime() },
|
||||
TotalScore = 2845370,
|
||||
|
@ -84,16 +84,80 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
});
|
||||
|
||||
clearScores();
|
||||
checkCount(0);
|
||||
checkDisplayedCount(0);
|
||||
|
||||
loadMoreScores(() => beatmapInfo);
|
||||
checkCount(10);
|
||||
importMoreScores(() => beatmapInfo);
|
||||
checkDisplayedCount(10);
|
||||
|
||||
loadMoreScores(() => beatmapInfo);
|
||||
checkCount(20);
|
||||
importMoreScores(() => beatmapInfo);
|
||||
checkDisplayedCount(20);
|
||||
|
||||
clearScores();
|
||||
checkCount(0);
|
||||
checkDisplayedCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLocalScoresDisplayOnBeatmapEdit()
|
||||
{
|
||||
BeatmapInfo beatmapInfo = null!;
|
||||
string originalHash = string.Empty;
|
||||
|
||||
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
|
||||
|
||||
AddStep(@"Import beatmap", () =>
|
||||
{
|
||||
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
||||
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
|
||||
|
||||
leaderboard.BeatmapInfo = beatmapInfo;
|
||||
});
|
||||
|
||||
clearScores();
|
||||
checkDisplayedCount(0);
|
||||
|
||||
AddStep(@"Perform initial save to guarantee stable hash", () =>
|
||||
{
|
||||
IBeatmap beatmap = beatmapManager.GetWorkingBeatmap(beatmapInfo).Beatmap;
|
||||
beatmapManager.Save(beatmapInfo, beatmap);
|
||||
|
||||
originalHash = beatmapInfo.Hash;
|
||||
});
|
||||
|
||||
importMoreScores(() => beatmapInfo);
|
||||
|
||||
checkDisplayedCount(10);
|
||||
checkStoredCount(10);
|
||||
|
||||
AddStep(@"Save with changes", () =>
|
||||
{
|
||||
IBeatmap beatmap = beatmapManager.GetWorkingBeatmap(beatmapInfo).Beatmap;
|
||||
beatmap.Difficulty.ApproachRate = 12;
|
||||
beatmapManager.Save(beatmapInfo, beatmap);
|
||||
});
|
||||
|
||||
AddAssert("Hash changed", () => beatmapInfo.Hash, () => Is.Not.EqualTo(originalHash));
|
||||
checkDisplayedCount(0);
|
||||
checkStoredCount(10);
|
||||
|
||||
importMoreScores(() => beatmapInfo);
|
||||
importMoreScores(() => beatmapInfo);
|
||||
checkDisplayedCount(20);
|
||||
checkStoredCount(30);
|
||||
|
||||
AddStep(@"Revert changes", () =>
|
||||
{
|
||||
IBeatmap beatmap = beatmapManager.GetWorkingBeatmap(beatmapInfo).Beatmap;
|
||||
beatmap.Difficulty.ApproachRate = 8;
|
||||
beatmapManager.Save(beatmapInfo, beatmap);
|
||||
});
|
||||
|
||||
AddAssert("Hash restored", () => beatmapInfo.Hash, () => Is.EqualTo(originalHash));
|
||||
checkDisplayedCount(10);
|
||||
checkStoredCount(30);
|
||||
|
||||
clearScores();
|
||||
checkDisplayedCount(0);
|
||||
checkStoredCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -162,9 +226,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
});
|
||||
}
|
||||
|
||||
private void loadMoreScores(Func<BeatmapInfo> beatmapInfo)
|
||||
private void importMoreScores(Func<BeatmapInfo> beatmapInfo)
|
||||
{
|
||||
AddStep(@"Load new scores via manager", () =>
|
||||
AddStep(@"Import new scores", () =>
|
||||
{
|
||||
foreach (var score in generateSampleScores(beatmapInfo()))
|
||||
scoreManager.Import(score);
|
||||
@ -176,8 +240,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
AddStep("Clear all scores", () => scoreManager.Delete());
|
||||
}
|
||||
|
||||
private void checkCount(int expected) =>
|
||||
AddUntilStep("Correct count displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count() == expected);
|
||||
private void checkDisplayedCount(int expected) =>
|
||||
AddUntilStep($"{expected} scores displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count(), () => Is.EqualTo(expected));
|
||||
|
||||
private void checkStoredCount(int expected) =>
|
||||
AddUntilStep($"Total scores stored is {expected}", () => Realm.Run(r => r.All<ScoreInfo>().Count(s => !s.DeletePending)), () => Is.EqualTo(expected));
|
||||
|
||||
private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
@ -210,6 +277,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
},
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
User = new APIUser
|
||||
{
|
||||
Id = 6602580,
|
||||
@ -226,6 +294,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddSeconds(-30),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
User = new APIUser
|
||||
{
|
||||
@ -243,6 +312,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddSeconds(-70),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -261,6 +331,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddMinutes(-40),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -279,6 +350,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddHours(-2),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -297,6 +369,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddHours(-25),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -315,6 +388,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddHours(-50),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -333,6 +407,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddHours(-72),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -351,6 +426,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddMonths(-3),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
@ -369,6 +445,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Date = DateTime.Now.AddYears(-2),
|
||||
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
|
||||
User = new APIUser
|
||||
|
@ -94,6 +94,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
OnlineID = i,
|
||||
BeatmapInfo = beatmapInfo,
|
||||
BeatmapHash = beatmapInfo.Hash,
|
||||
Accuracy = RNG.NextDouble(),
|
||||
TotalScore = RNG.Next(1, 1000000),
|
||||
MaxCombo = RNG.Next(1, 1000),
|
||||
|
@ -70,8 +70,9 @@ namespace osu.Game.Database
|
||||
/// 23 2022-08-01 Added LastLocalUpdate to BeatmapInfo.
|
||||
/// 24 2022-08-22 Added MaximumStatistics to ScoreInfo.
|
||||
/// 25 2022-09-18 Remove skins to add with new naming.
|
||||
/// 26 2023-02-05 Added BeatmapHash to ScoreInfo.
|
||||
/// </summary>
|
||||
private const int schema_version = 25;
|
||||
private const int schema_version = 26;
|
||||
|
||||
/// <summary>
|
||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
|
||||
@ -866,6 +867,15 @@ namespace osu.Game.Database
|
||||
// Remove the default skins so they can be added back by SkinManager with updated naming.
|
||||
migration.NewRealm.RemoveRange(migration.NewRealm.All<SkinInfo>().Where(s => s.Protected));
|
||||
break;
|
||||
|
||||
case 26:
|
||||
// Add ScoreInfo.BeatmapHash property to ensure scores correspond to the correct version of beatmap.
|
||||
var scores = migration.NewRealm.All<ScoreInfo>();
|
||||
|
||||
foreach (var score in scores)
|
||||
score.BeatmapHash = score.BeatmapInfo.Hash;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
// before returning for database import, we must restore the database-sourced BeatmapInfo.
|
||||
// if not, the clone operation in GetPlayableBeatmap will cause a dereference and subsequent database exception.
|
||||
score.ScoreInfo.BeatmapInfo = workingBeatmap.BeatmapInfo;
|
||||
score.ScoreInfo.BeatmapHash = workingBeatmap.BeatmapInfo.Hash;
|
||||
|
||||
return score;
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ using Realms;
|
||||
|
||||
namespace osu.Game.Scoring
|
||||
{
|
||||
/// <summary>
|
||||
/// A realm model containing metadata for a single score.
|
||||
/// </summary>
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("Score")]
|
||||
public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<ScoreInfo>, IScoreInfo
|
||||
@ -29,8 +32,19 @@ namespace osu.Game.Scoring
|
||||
[PrimaryKey]
|
||||
public Guid ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="BeatmapInfo"/> this score was made against.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When setting this, make sure to also set <see cref="BeatmapHash"/> to allow relational consistency when a beatmap is potentially changed.
|
||||
/// </remarks>
|
||||
public BeatmapInfo BeatmapInfo { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="osu.Game.Beatmaps.BeatmapInfo.Hash"/> at the point in time when the score was set.
|
||||
/// </summary>
|
||||
public string BeatmapHash { get; set; } = string.Empty;
|
||||
|
||||
public RulesetInfo Ruleset { get; set; } = null!;
|
||||
|
||||
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
||||
|
@ -248,6 +248,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
// ensure the score is in a consistent state with the current player.
|
||||
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
|
||||
Score.ScoreInfo.BeatmapHash = Beatmap.Value.BeatmapInfo.Hash;
|
||||
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
|
||||
Score.ScoreInfo.Mods = gameplayMods;
|
||||
|
||||
|
@ -65,6 +65,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
r.All<ScoreInfo>()
|
||||
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
|
||||
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
|
||||
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.Hash)} == {nameof(ScoreInfo.BeatmapHash)}"
|
||||
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
|
||||
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName),
|
||||
localScoresChanged);
|
||||
|
@ -191,6 +191,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
|
||||
scoreSubscription = realm.RegisterForNotifications(r =>
|
||||
r.All<ScoreInfo>().Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $0"
|
||||
+ $" AND {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.Hash)} == {nameof(ScoreInfo.BeatmapHash)}"
|
||||
+ $" AND {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $1"
|
||||
+ $" AND {nameof(ScoreInfo.DeletePending)} == false"
|
||||
, beatmapInfo.ID, ruleset.Value.ShortName), localScoresChanged);
|
||||
|
Loading…
Reference in New Issue
Block a user