Skip to content

Commit

Permalink
Merge branch 'master' into singletap-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jul 13, 2022
2 parents e2f2d5f + 7ed0527 commit 732d86b
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 20 deletions.
44 changes: 44 additions & 0 deletions osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Models;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.NonVisual
{
Expand All @@ -23,6 +26,47 @@ public void TestOnlineWithOnline()
Assert.IsTrue(ourInfo.MatchesOnlineID(otherInfo));
}

[Test]
public void TestAudioEqualityNoFile()
{
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);

Assert.AreNotEqual(beatmapSetA, beatmapSetB);
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
}

[Test]
public void TestAudioEqualitySameHash()
{
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);

addAudioFile(beatmapSetA, "abc");
addAudioFile(beatmapSetB, "abc");

Assert.AreNotEqual(beatmapSetA, beatmapSetB);
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
}

[Test]
public void TestAudioEqualityDifferentHash()
{
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);

addAudioFile(beatmapSetA);
addAudioFile(beatmapSetB);

Assert.AreNotEqual(beatmapSetA, beatmapSetB);
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
}

private static void addAudioFile(BeatmapSetInfo beatmapSetInfo, string hash = null)
{
beatmapSetInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = hash ?? Guid.NewGuid().ToString() }, "audio.mp3"));
}

[Test]
public void TestDatabasedWithDatabased()
{
Expand Down
1 change: 1 addition & 0 deletions osu.Game.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ IEnumerable<BeatmapInfo> getBeatmaps(int count)
DifficultyName = $"{version} {beatmapId} (length {TimeSpan.FromMilliseconds(length):m\\:ss}, bpm {bpm:0.#})",
StarRating = diff,
Length = length,
BeatmapSet = beatmapSet,
BPM = bpm,
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
Ruleset = rulesetInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Screens;
Expand Down Expand Up @@ -103,6 +104,8 @@ public void TestExitWithoutSave()
*/
public void TestAddAudioTrack()
{
AddAssert("track is virtual", () => Beatmap.Value.Track is TrackVirtual);

AddAssert("switch track to real track", () =>
{
var setup = Editor.ChildrenOfType<SetupScreen>().First();
Expand Down Expand Up @@ -131,6 +134,7 @@ public void TestAddAudioTrack()
}
});

AddAssert("track is not virtual", () => Beatmap.Value.Track is not TrackVirtual);
AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000);
}

Expand Down
15 changes: 15 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -59,6 +60,20 @@ public override void SetUpSteps()

protected override bool AllowFail => false;

[Test]
public void TestLastPlayedUpdated()
{
DateTimeOffset? getLastPlayed() => Realm.Run(r => r.Find<BeatmapInfo>(Beatmap.Value.BeatmapInfo.ID)?.LastPlayed);

AddStep("set no custom ruleset", () => customRuleset = null);
AddAssert("last played is null", () => getLastPlayed() == null);

CreateTest();

AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
AddUntilStep("wait for last played to update", () => getLastPlayed() != null);
}

[Test]
public void TestScoreStoredLocally()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace osu.Game.Tournament.Components
{
public class TournamentSpriteTextWithBackground : CompositeDrawable
{
protected readonly TournamentSpriteText Text;
public readonly TournamentSpriteText Text;

protected readonly Box Background;

public TournamentSpriteTextWithBackground(string text = "")
Expand Down
4 changes: 1 addition & 3 deletions osu.Game.Tournament/Models/SeedingBeatmap.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using Newtonsoft.Json;
using osu.Framework.Bindables;

Expand All @@ -13,7 +11,7 @@ public class SeedingBeatmap
public int ID;

[JsonProperty("BeatmapInfo")]
public TournamentBeatmap Beatmap;
public TournamentBeatmap? Beatmap;

public long Score;

Expand Down
11 changes: 10 additions & 1 deletion osu.Game.Tournament/Screens/Gameplay/Components/TeamDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class TeamDisplay : DrawableTournamentTeam
{
private readonly TeamScore score;

private readonly TournamentSpriteTextWithBackground teamText;

private readonly Bindable<string> teamName = new Bindable<string>("???");

private bool showScore;

public bool ShowScore
Expand Down Expand Up @@ -93,7 +97,7 @@ public TeamDisplay(TournamentTeam team, TeamColour colour, Bindable<int?> curren
}
}
},
new TournamentSpriteTextWithBackground(team?.FullName.Value ?? "???")
teamText = new TournamentSpriteTextWithBackground
{
Scale = new Vector2(0.5f),
Origin = anchor,
Expand All @@ -113,6 +117,11 @@ protected override void LoadComplete()

updateDisplay();
FinishTransforms(true);

if (Team != null)
teamName.BindTo(Team.FullName);

teamName.BindValueChanged(name => teamText.Text.Text = name.NewValue, true);
}

private void updateDisplay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private void load(LadderInfo ladder)
currentMatch.BindTo(ladder.CurrentMatch);
currentMatch.BindValueChanged(matchChanged);

currentTeam.BindValueChanged(teamChanged);

updateMatch();
}

Expand All @@ -67,7 +69,7 @@ private void updateMatch()

// team may change to same team, which means score is not in a good state.
// thus we handle this manually.
teamChanged(currentTeam.Value);
currentTeam.TriggerChange();
}

protected override bool OnMouseDown(MouseDownEvent e)
Expand All @@ -88,11 +90,11 @@ protected override bool OnMouseDown(MouseDownEvent e)
return base.OnMouseDown(e);
}

private void teamChanged(TournamentTeam team)
private void teamChanged(ValueChangedEvent<TournamentTeam> team)
{
InternalChildren = new Drawable[]
{
teamDisplay = new TeamDisplay(team, teamColour, currentTeamScore, currentMatch.Value?.PointsToWin ?? 0),
teamDisplay = new TeamDisplay(team.NewValue, teamColour, currentTeamScore, currentMatch.Value?.PointsToWin ?? 0),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private void load()

editorInfo.Selected.ValueChanged += selection =>
{
// ensure any ongoing edits are committed out to the *current* selection before changing to a new one.
GetContainingInputManager().TriggerFocusContention(null);

roundDropdown.Current = selection.NewValue?.Round;
losersCheckbox.Current = selection.NewValue?.Losers;
dateTimeBox.Current = selection.NewValue?.Date;
Expand Down
16 changes: 13 additions & 3 deletions osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable disable

using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -69,7 +70,7 @@ private void load()
currentTeam.BindValueChanged(teamChanged, true);
}

private void teamChanged(ValueChangedEvent<TournamentTeam> team)
private void teamChanged(ValueChangedEvent<TournamentTeam> team) => Scheduler.AddOnce(() =>
{
if (team.NewValue == null)
{
Expand All @@ -78,7 +79,7 @@ private void teamChanged(ValueChangedEvent<TournamentTeam> team)
}

showTeam(team.NewValue);
}
});

protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
Expand Down Expand Up @@ -120,15 +121,23 @@ public RightInfo(TournamentTeam team)
foreach (var seeding in team.SeedingResults)
{
fill.Add(new ModRow(seeding.Mod.Value, seeding.Seed.Value));

foreach (var beatmap in seeding.Beatmaps)
{
if (beatmap.Beatmap == null)
continue;

fill.Add(new BeatmapScoreRow(beatmap));
}
}
}

private class BeatmapScoreRow : CompositeDrawable
{
public BeatmapScoreRow(SeedingBeatmap beatmap)
{
Debug.Assert(beatmap.Beatmap != null);

RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;

Expand Down Expand Up @@ -157,7 +166,8 @@ public BeatmapScoreRow(SeedingBeatmap beatmap)
Children = new Drawable[]
{
new TournamentSpriteText { Text = beatmap.Score.ToString("#,0"), Colour = TournamentGame.TEXT_COLOUR, Width = 80 },
new TournamentSpriteText { Text = "#" + beatmap.Seed.Value.ToString("#,0"), Colour = TournamentGame.TEXT_COLOUR, Font = OsuFont.Torus.With(weight: FontWeight.Regular) },
new TournamentSpriteText
{ Text = "#" + beatmap.Seed.Value.ToString("#,0"), Colour = TournamentGame.TEXT_COLOUR, Font = OsuFont.Torus.With(weight: FontWeight.Regular) },
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tournament/Screens/TeamWin/TeamWinScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> m

private bool firstDisplay = true;

private void update() => Schedule(() =>
private void update() => Scheduler.AddOnce(() =>
{
var match = CurrentMatch.Value;

Expand Down
23 changes: 19 additions & 4 deletions osu.Game/Beatmaps/BeatmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
Expand Down Expand Up @@ -110,6 +111,11 @@ public BeatmapOnlineStatus Status

public bool SamplesMatchPlaybackRate { get; set; } = true;

/// <summary>
/// The time at which this beatmap was last played by the local user.
/// </summary>
public DateTimeOffset? LastPlayed { get; set; }

/// <summary>
/// The ratio of distance travelled per time unit.
/// Generally used to decouple the spacing between hit objects from the enforced "velocity" of the beatmap (see <see cref="DifficultyControlPoint.SliderVelocity"/>).
Expand Down Expand Up @@ -151,14 +157,23 @@ public bool Equals(BeatmapInfo? other)
public bool AudioEquals(BeatmapInfo? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null
&& BeatmapSet.Hash == other.BeatmapSet.Hash
&& Metadata.AudioFile == other.Metadata.AudioFile;
&& compareFiles(this, other, m => m.AudioFile);

public bool BackgroundEquals(BeatmapInfo? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null
&& BeatmapSet.Hash == other.BeatmapSet.Hash
&& Metadata.BackgroundFile == other.Metadata.BackgroundFile;
&& compareFiles(this, other, m => m.BackgroundFile);

private static bool compareFiles(BeatmapInfo x, BeatmapInfo y, Func<IBeatmapMetadataInfo, string> getFilename)
{
Debug.Assert(x.BeatmapSet != null);
Debug.Assert(y.BeatmapSet != null);

string? fileHashX = x.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(x.BeatmapSet.Metadata))?.File.Hash;
string? fileHashY = y.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(y.BeatmapSet.Metadata))?.File.Hash;

return fileHashX == fileHashY;
}

IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata;
IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet;
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public class RealmAccess : IDisposable
/// 12 2021-11-24 Add Status to RealmBeatmapSet.
/// 13 2022-01-13 Final migration of beatmaps and scores to realm (multiple new storage fields).
/// 14 2022-03-01 Added BeatmapUserSettings to BeatmapInfo.
/// 15 2022-07-13 Added LastPlayed to BeatmapInfo.
/// </summary>
private const int schema_version = 14;
private const int schema_version = 15;

/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/IO/OsuStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public bool TryChangeToCustomStorage(out OsuStorageError error)
error = OsuStorageError.None;
Storage lastStorage = UnderlyingStorage;

Logger.Log($"Attempting to use custom storage location {CustomStoragePath}");

try
{
Storage userStorage = host.GetStorage(CustomStoragePath);
Expand All @@ -102,13 +104,17 @@ public bool TryChangeToCustomStorage(out OsuStorageError error)
error = OsuStorageError.AccessibleButEmpty;

ChangeTargetStorage(userStorage);
Logger.Log($"Storage successfully changed to {CustomStoragePath}.");
}
catch
{
error = OsuStorageError.NotAccessible;
ChangeTargetStorage(lastStorage);
}

if (error != OsuStorageError.None)
Logger.Log($"Custom storage location could not be used ({error}).");

return error == OsuStorageError.None;
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void load(OsuConfigManager config)
loadableBeatmap = beatmapManager.CreateNew(Ruleset.Value, api.LocalUser.Value);

// required so we can get the track length in EditorClock.
// this is safe as nothing has yet got a reference to this new beatmap.
// this is ONLY safe because the track being provided is a `TrackVirtual` which we don't really care about disposing.
loadableBeatmap.LoadTrack();

// this is a bit haphazard, but guards against setting the lease Beatmap bindable if
Expand Down
Loading

0 comments on commit 732d86b

Please sign in to comment.