mirror of
https://github.com/ppy/osu.git
synced 2025-01-09 03:02:56 +08:00
Update the last played date of a beatmap when importing a replay by the local user
This commit is contained in:
parent
5ab20f5db7
commit
96dd7b3333
@ -9,6 +9,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
namespace osu.Game.Tests
|
namespace osu.Game.Tests
|
||||||
@ -46,12 +47,15 @@ namespace osu.Game.Tests
|
|||||||
public partial class TestOsuGameBase : OsuGameBase
|
public partial class TestOsuGameBase : OsuGameBase
|
||||||
{
|
{
|
||||||
public RealmAccess Realm => Dependencies.Get<RealmAccess>();
|
public RealmAccess Realm => Dependencies.Get<RealmAccess>();
|
||||||
|
public new IAPIProvider API => base.API;
|
||||||
|
|
||||||
private readonly bool withBeatmap;
|
private readonly bool withBeatmap;
|
||||||
|
|
||||||
public TestOsuGameBase(bool withBeatmap)
|
public TestOsuGameBase(bool withBeatmap)
|
||||||
{
|
{
|
||||||
this.withBeatmap = withBeatmap;
|
this.withBeatmap = withBeatmap;
|
||||||
|
|
||||||
|
base.API = new DummyAPIAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -12,6 +12,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
@ -67,6 +68,64 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(false)]
|
||||||
|
[TestCase(true)]
|
||||||
|
public void TestLastPlayedUpdate(bool isLocalUser)
|
||||||
|
{
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
|
if (!isLocalUser)
|
||||||
|
osu.API.Logout();
|
||||||
|
|
||||||
|
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
|
||||||
|
var beatmapInfo = beatmap.Beatmaps.First();
|
||||||
|
|
||||||
|
DateTimeOffset replayDate = DateTimeOffset.Now;
|
||||||
|
|
||||||
|
var toImport = new ScoreInfo
|
||||||
|
{
|
||||||
|
Rank = ScoreRank.B,
|
||||||
|
TotalScore = 987654,
|
||||||
|
Accuracy = 0.8,
|
||||||
|
MaxCombo = 500,
|
||||||
|
Combo = 250,
|
||||||
|
User = new APIUser
|
||||||
|
{
|
||||||
|
Username = "Test user",
|
||||||
|
Id = DummyAPIAccess.DUMMY_USER_ID,
|
||||||
|
},
|
||||||
|
Date = replayDate,
|
||||||
|
OnlineID = 12345,
|
||||||
|
Ruleset = new OsuRuleset().RulesetInfo,
|
||||||
|
BeatmapInfo = beatmapInfo
|
||||||
|
};
|
||||||
|
|
||||||
|
var imported = LoadScoreIntoOsu(osu, toImport);
|
||||||
|
|
||||||
|
Assert.AreEqual(toImport.Rank, imported.Rank);
|
||||||
|
Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
|
||||||
|
Assert.AreEqual(toImport.Accuracy, imported.Accuracy);
|
||||||
|
Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo);
|
||||||
|
Assert.AreEqual(toImport.User.Username, imported.User.Username);
|
||||||
|
Assert.AreEqual(toImport.Date, imported.Date);
|
||||||
|
Assert.AreEqual(toImport.OnlineID, imported.OnlineID);
|
||||||
|
|
||||||
|
if (isLocalUser)
|
||||||
|
Assert.That(imported.BeatmapInfo!.LastPlayed, Is.EqualTo(replayDate));
|
||||||
|
else
|
||||||
|
Assert.That(imported.BeatmapInfo!.LastPlayed, Is.Null);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestImportMods()
|
public void TestImportMods()
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,7 @@ namespace osu.Game.Online.API
|
|||||||
LocalUser.Value = new APIUser
|
LocalUser.Value = new APIUser
|
||||||
{
|
{
|
||||||
Username = username,
|
Username = username,
|
||||||
Id = 1001,
|
Id = DUMMY_USER_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
state.Value = APIState.Online;
|
state.Value = APIState.Online;
|
||||||
|
@ -87,6 +87,9 @@ namespace osu.Game.Scoring
|
|||||||
if (!model.Ruleset.IsManaged)
|
if (!model.Ruleset.IsManaged)
|
||||||
model.Ruleset = realm.Find<RulesetInfo>(model.Ruleset.ShortName)!;
|
model.Ruleset = realm.Find<RulesetInfo>(model.Ruleset.ShortName)!;
|
||||||
|
|
||||||
|
if (api.IsLoggedIn && api.LocalUser.Value.OnlineID == model.UserID && (model.BeatmapInfo.LastPlayed == null || model.Date > model.BeatmapInfo.LastPlayed))
|
||||||
|
model.BeatmapInfo.LastPlayed = model.Date;
|
||||||
|
|
||||||
// These properties are known to be non-null, but these final checks ensure a null hasn't come from somewhere (or the refetch has failed).
|
// These properties are known to be non-null, but these final checks ensure a null hasn't come from somewhere (or the refetch has failed).
|
||||||
// Under no circumstance do we want these to be written to realm as null.
|
// Under no circumstance do we want these to be written to realm as null.
|
||||||
ArgumentNullException.ThrowIfNull(model.BeatmapInfo);
|
ArgumentNullException.ThrowIfNull(model.BeatmapInfo);
|
||||||
|
Loading…
Reference in New Issue
Block a user