mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge branch 'master' into multi-queueing-modes
This commit is contained in:
@ -9,8 +9,11 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Drawables.Cards;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK;
|
||||
@ -20,6 +23,8 @@ namespace osu.Game.Tests.Visual.Beatmaps
|
||||
{
|
||||
public class TestSceneBeatmapCard : OsuTestScene
|
||||
{
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
|
||||
private APIBeatmapSet[] testCases;
|
||||
|
||||
#region Test case generation
|
||||
@ -164,6 +169,19 @@ namespace osu.Game.Tests.Visual.Beatmaps
|
||||
|
||||
#endregion
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("register request handling", () => dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (!(request is PostBeatmapFavouriteRequest))
|
||||
return false;
|
||||
|
||||
request.TriggerSuccess();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private Drawable createContent(OverlayColourScheme colourScheme, Func<APIBeatmapSet, Drawable> creationFunc)
|
||||
{
|
||||
var colourProvider = new OverlayColourProvider(colourScheme);
|
||||
|
@ -0,0 +1,86 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Beatmaps
|
||||
{
|
||||
public class TestSceneBeatmapCardFavouriteButton : OsuManualInputManagerTestScene
|
||||
{
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||
|
||||
[Test]
|
||||
public void TestInitialState([Values] bool favourited)
|
||||
{
|
||||
APIBeatmapSet beatmapSetInfo = null;
|
||||
FavouriteButton button = null;
|
||||
|
||||
AddStep("create beatmap set", () =>
|
||||
{
|
||||
beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value);
|
||||
beatmapSetInfo.HasFavourited = favourited;
|
||||
});
|
||||
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) });
|
||||
|
||||
assertCorrectIcon(favourited);
|
||||
AddAssert("correct tooltip text", () => button.TooltipText == (favourited ? BeatmapsetsStrings.ShowDetailsUnfavourite : BeatmapsetsStrings.ShowDetailsFavourite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRequestHandling()
|
||||
{
|
||||
APIBeatmapSet beatmapSetInfo = null;
|
||||
FavouriteButton button = null;
|
||||
BeatmapFavouriteAction? lastRequestAction = null;
|
||||
|
||||
AddStep("create beatmap set", () => beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value));
|
||||
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) });
|
||||
|
||||
assertCorrectIcon(false);
|
||||
|
||||
AddStep("register request handling", () => dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (!(request is PostBeatmapFavouriteRequest favouriteRequest))
|
||||
return false;
|
||||
|
||||
lastRequestAction = favouriteRequest.Action;
|
||||
request.TriggerSuccess();
|
||||
return true;
|
||||
});
|
||||
|
||||
AddStep("click icon", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(button);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddUntilStep("favourite request sent", () => lastRequestAction == BeatmapFavouriteAction.Favourite);
|
||||
assertCorrectIcon(true);
|
||||
|
||||
AddStep("click icon", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(button);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddUntilStep("unfavourite request sent", () => lastRequestAction == BeatmapFavouriteAction.UnFavourite);
|
||||
assertCorrectIcon(false);
|
||||
}
|
||||
|
||||
private void assertCorrectIcon(bool favourited) => AddAssert("icon correct",
|
||||
() => this.ChildrenOfType<SpriteIcon>().Single().Icon.Equals(favourited ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart));
|
||||
}
|
||||
}
|
@ -13,10 +13,17 @@ namespace osu.Game.Tests.Visual.Components
|
||||
{
|
||||
public class TestScenePreviewTrackManager : OsuTestScene, IPreviewTrackOwner
|
||||
{
|
||||
private readonly TestPreviewTrackManager trackManager = new TestPreviewTrackManager();
|
||||
private readonly IAdjustableAudioComponent gameTrackAudio = new AudioAdjustments();
|
||||
|
||||
private readonly TestPreviewTrackManager trackManager;
|
||||
|
||||
private AudioManager audio;
|
||||
|
||||
public TestScenePreviewTrackManager()
|
||||
{
|
||||
trackManager = new TestPreviewTrackManager(gameTrackAudio);
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
@ -151,19 +158,19 @@ namespace osu.Game.Tests.Visual.Components
|
||||
audio.VolumeTrack.Value = 1;
|
||||
});
|
||||
|
||||
AddAssert("game not muted", () => audio.Tracks.AggregateVolume.Value != 0);
|
||||
AddAssert("game not muted", () => gameTrackAudio.AggregateVolume.Value != 0);
|
||||
|
||||
AddStep("get track", () => Add(owner = new TestTrackOwner(track = getTrack())));
|
||||
AddUntilStep("wait loaded", () => track.IsLoaded);
|
||||
AddStep("start track", () => track.Start());
|
||||
AddAssert("game is muted", () => audio.Tracks.AggregateVolume.Value == 0);
|
||||
AddAssert("game is muted", () => gameTrackAudio.AggregateVolume.Value == 0);
|
||||
|
||||
if (stopAnyPlaying)
|
||||
AddStep("stop any playing", () => trackManager.StopAnyPlaying(owner));
|
||||
else
|
||||
AddStep("stop track", () => track.Stop());
|
||||
|
||||
AddAssert("game not muted", () => audio.Tracks.AggregateVolume.Value != 0);
|
||||
AddAssert("game not muted", () => gameTrackAudio.AggregateVolume.Value != 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -224,6 +231,11 @@ namespace osu.Game.Tests.Visual.Components
|
||||
|
||||
public new PreviewTrack CurrentTrack => base.CurrentTrack;
|
||||
|
||||
public TestPreviewTrackManager(IAdjustableAudioComponent mainTrackAdjustments)
|
||||
: base(mainTrackAdjustments)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TrackManagerPreviewTrack CreatePreviewTrack(IBeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) => new TestPreviewTrack(beatmapSetInfo, trackStore);
|
||||
|
||||
public override bool UpdateSubTree()
|
||||
|
@ -0,0 +1,98 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Scoring;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
public class TestSceneUnstableRateCounter : OsuTestScene
|
||||
{
|
||||
[Cached(typeof(ScoreProcessor))]
|
||||
private TestScoreProcessor scoreProcessor = new TestScoreProcessor();
|
||||
|
||||
private readonly OsuHitWindows hitWindows = new OsuHitWindows();
|
||||
|
||||
private UnstableRateCounter counter;
|
||||
|
||||
private double prev;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUp()
|
||||
{
|
||||
AddStep("Reset Score Processor", () => scoreProcessor.Reset());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
AddStep("Create Display", recreateDisplay);
|
||||
|
||||
// Needs multiples 2 by the nature of UR, and went for 4 to be safe.
|
||||
// Creates a 250 UR by placing a +25ms then a -25ms judgement, which then results in a 250 UR
|
||||
AddRepeatStep("Set UR to 250", () => applyJudgement(25, true), 4);
|
||||
|
||||
AddUntilStep("UR = 250", () => counter.Current.Value == 250.0);
|
||||
|
||||
AddRepeatStep("Revert UR", () =>
|
||||
{
|
||||
scoreProcessor.RevertResult(
|
||||
new JudgementResult(new HitCircle { HitWindows = hitWindows }, new Judgement())
|
||||
{
|
||||
TimeOffset = 25,
|
||||
Type = HitResult.Perfect,
|
||||
});
|
||||
}, 4);
|
||||
|
||||
AddUntilStep("UR is 0", () => counter.Current.Value == 0.0);
|
||||
AddUntilStep("Counter is invalid", () => counter.Child.Alpha == 0.3f);
|
||||
|
||||
//Sets a UR of 0 by creating 10 10ms offset judgements. Since average = offset, UR = 0
|
||||
AddRepeatStep("Set UR to 0", () => applyJudgement(10, false), 10);
|
||||
//Applies a UR of 100 by creating 10 -10ms offset judgements. At the 10th judgement, offset should be 100.
|
||||
AddRepeatStep("Bring UR to 100", () => applyJudgement(-10, false), 10);
|
||||
}
|
||||
|
||||
private void recreateDisplay()
|
||||
{
|
||||
Clear();
|
||||
|
||||
Add(counter = new UnstableRateCounter
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Scale = new Vector2(5),
|
||||
});
|
||||
}
|
||||
|
||||
private void applyJudgement(double offsetMs, bool alt)
|
||||
{
|
||||
double placement = offsetMs;
|
||||
|
||||
if (alt)
|
||||
{
|
||||
placement = prev > 0 ? -offsetMs : offsetMs;
|
||||
prev = placement;
|
||||
}
|
||||
|
||||
scoreProcessor.ApplyResult(new JudgementResult(new HitCircle { HitWindows = hitWindows }, new Judgement())
|
||||
{
|
||||
TimeOffset = placement,
|
||||
Type = HitResult.Perfect,
|
||||
});
|
||||
}
|
||||
|
||||
private class TestScoreProcessor : ScoreProcessor
|
||||
{
|
||||
public void Reset() => base.Reset(false);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user