1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 21:02:54 +08:00

Add handling of beatmap links on startup

This commit is contained in:
Dean Herbert 2022-02-18 16:06:38 +09:00
parent 98aaf83177
commit 29c5683ba3
3 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,22 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Overlays;
namespace osu.Game.Tests.Visual.Navigation
{
public class TestSceneStartupBeatmapDisplay : OsuGameTestScene
{
protected override TestOsuGame CreateTestGame() => new TestOsuGame(LocalStorage, API, new[] { "osu://b/75" });
[Test]
public void TestBeatmapLink()
{
AddUntilStep("Beatmap overlay displayed", () => Game.ChildrenOfType<BeatmapSetOverlay>().FirstOrDefault()?.State.Value == Visibility.Visible);
}
}
}

View File

@ -0,0 +1,22 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Overlays;
namespace osu.Game.Tests.Visual.Navigation
{
public class TestSceneStartupBeatmapSetDisplay : OsuGameTestScene
{
protected override TestOsuGame CreateTestGame() => new TestOsuGame(LocalStorage, API, new[] { "osu://s/1" });
[Test]
public void TestBeatmapSetLink()
{
AddUntilStep("Beatmap overlay displayed", () => Game.ChildrenOfType<BeatmapSetOverlay>().FirstOrDefault()?.State.Value == Visibility.Visible);
}
}
}

View File

@ -150,6 +150,7 @@ namespace osu.Game
protected SettingsOverlay Settings;
private VolumeOverlay volume;
private OsuLogo osuLogo;
private MainMenu menuScreen;
@ -898,10 +899,43 @@ namespace osu.Game
if (args?.Length > 0)
{
string[] paths = args.Where(a => !a.StartsWith('-')).ToArray();
if (paths.Length > 0)
{
string firstPath = paths.First();
if (firstPath.StartsWith(OSU_PROTOCOL, StringComparison.Ordinal))
{
handleOsuProtocolUrl(firstPath);
}
else
{
Task.Run(() => Import(paths));
}
}
}
}
private void handleOsuProtocolUrl(string url)
{
if (!url.StartsWith(OSU_PROTOCOL, StringComparison.Ordinal))
throw new ArgumentException("Invalid osu URL provided.", nameof(url));
string[] pieces = url.Split('/');
switch (pieces[2])
{
case "s":
if (int.TryParse(pieces[3], out int beatmapSetId))
ShowBeatmapSet(beatmapSetId);
break;
case "b":
if (int.TryParse(pieces[3], out int beatmapId))
ShowBeatmap(beatmapId);
break;
}
}
private void showOverlayAboveOthers(OverlayContainer overlay, OverlayContainer[] otherOverlays)
{