mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 02:32:55 +08:00
Add handling of beatmap links on startup
This commit is contained in:
parent
98aaf83177
commit
29c5683ba3
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -150,6 +150,7 @@ namespace osu.Game
|
|||||||
protected SettingsOverlay Settings;
|
protected SettingsOverlay Settings;
|
||||||
|
|
||||||
private VolumeOverlay volume;
|
private VolumeOverlay volume;
|
||||||
|
|
||||||
private OsuLogo osuLogo;
|
private OsuLogo osuLogo;
|
||||||
|
|
||||||
private MainMenu menuScreen;
|
private MainMenu menuScreen;
|
||||||
@ -898,10 +899,43 @@ namespace osu.Game
|
|||||||
if (args?.Length > 0)
|
if (args?.Length > 0)
|
||||||
{
|
{
|
||||||
string[] paths = args.Where(a => !a.StartsWith('-')).ToArray();
|
string[] paths = args.Where(a => !a.StartsWith('-')).ToArray();
|
||||||
|
|
||||||
if (paths.Length > 0)
|
if (paths.Length > 0)
|
||||||
|
{
|
||||||
|
string firstPath = paths.First();
|
||||||
|
|
||||||
|
if (firstPath.StartsWith(OSU_PROTOCOL, StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
handleOsuProtocolUrl(firstPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Task.Run(() => Import(paths));
|
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)
|
private void showOverlayAboveOthers(OverlayContainer overlay, OverlayContainer[] otherOverlays)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user