1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +08:00

Use actual song select for test case with beatmap import

This commit is contained in:
David Zhao 2019-02-27 14:15:45 +09:00
parent 59fca568c9
commit ebec944bb8

View File

@ -3,28 +3,30 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Linq;
using System.Threading; using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Logging; using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Screens.Play.PlayerSettings; using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Tests.Beatmaps; using osu.Game.Screens.Select;
using osu.Game.Tests.Resources;
using osu.Game.Users; using osu.Game.Users;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -44,9 +46,36 @@ namespace osu.Game.Tests.Visual
private DummySongSelect songSelect; private DummySongSelect songSelect;
private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayerLoader playerLoader;
private DimAccessiblePlayer player; private DimAccessiblePlayer player;
private DatabaseContextFactory factory;
private BeatmapManager manager;
private RulesetStore rulesets;
private ScreenStackCacheContainer screenStackContainer; private ScreenStackCacheContainer screenStackContainer;
[BackgroundDependencyLoader]
private void load(GameHost host)
{
factory = new DatabaseContextFactory(LocalStorage);
factory.ResetDatabase();
using (var usage = factory.Get())
usage.Migrate();
factory.ResetDatabase();
using (var usage = factory.Get())
usage.Migrate();
Dependencies.Cache(rulesets = new RulesetStore(factory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, null, host, Beatmap.Default));
Beatmap.SetDefault();
}
[SetUp]
public virtual void SetUp() =>
Schedule(() => { manager?.Delete(manager.GetAllUsableBeatmapSets()); });
/// <summary> /// <summary>
/// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. /// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel.
/// </summary> /// </summary>
@ -215,54 +244,37 @@ namespace osu.Game.Tests.Visual
{ {
createSongSelect(); createSongSelect();
AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer
{ {
Ready = true,
AllowLeadIn = false, AllowLeadIn = false,
AllowResults = false, AllowResults = false,
})); Ready = true,
})); });
AddUntilStep(() => playerLoader.IsLoaded, "Wait for Player Loader to load");
AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos));
AddUntilStep(() => player.IsLoaded, "Wait for player to load"); AddUntilStep(() => player.IsLoaded, "Wait for player to load");
} }
private void createSongSelect() private void createSongSelect()
{ {
AddStep("Create new screen stack", () => AddStep("Create new screen stack", () => Child = screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both });
{ AddUntilStep(() => screenStackContainer.IsLoaded,"Wait for screen stack creation");
screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both }; AddStep("create new song select", () => screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect()));
Child = screenStackContainer;
});
AddStep("Create song select", () =>
{
songSelect = new DummySongSelect();
screenStackContainer.ScreenStack.Push(songSelect);
});
AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load"); AddUntilStep(() => songSelect.IsLoaded, "Wait for song select to load");
AddStep("Create beatmap", () => AddStep("Add map", () =>
{ {
Beatmap.Value = new TestWorkingBeatmap(new Beatmap<OsuHitObject> var temp = TestResources.GetTestBeatmapForImport();
{ manager.Import(temp);
HitObjects = Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() });
{
new HitCircle
{
StartTime = 3000,
Position = new Vector2(0, 0),
},
new HitCircle
{
StartTime = 15000,
Position = new Vector2(0, 0),
}
},
});
}); });
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "has selection");
} }
private class DummySongSelect : OsuScreen private class DummySongSelect : PlaySongSelect
{ {
protected override BackgroundScreen CreateBackground() protected override BackgroundScreen CreateBackground()
{ {
FadeAccessibleBackground background = new FadeAccessibleBackground(); FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value);
DimEnabled.BindTo(background.EnableUserDim); DimEnabled.BindTo(background.EnableUserDim);
return background; return background;
} }
@ -270,11 +282,12 @@ namespace osu.Game.Tests.Visual
public readonly Bindable<bool> DimEnabled = new Bindable<bool>(); public readonly Bindable<bool> DimEnabled = new Bindable<bool>();
private readonly Bindable<double> dimLevel = new Bindable<double>(); private readonly Bindable<double> dimLevel = new Bindable<double>();
public new BeatmapCarousel Carousel => base.Carousel;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
config.BindWith(OsuSetting.DimLevel, dimLevel); config.BindWith(OsuSetting.DimLevel, dimLevel);
Logger.Log(dimLevel.Value.ToString(CultureInfo.InvariantCulture));
} }
public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value); public bool IsBackgroundDimmed() => ((FadeAccessibleBackground)Background).CurrentColour == OsuColour.Gray(1 - (float)dimLevel.Value);
@ -299,12 +312,12 @@ namespace osu.Game.Tests.Visual
{ {
} }
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
} }
private class DimAccessiblePlayer : Player private class DimAccessiblePlayer : Player
{ {
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
// Whether or not the player should be allowed to load. // Whether or not the player should be allowed to load.
public bool Ready; public bool Ready;
@ -348,7 +361,7 @@ namespace osu.Game.Tests.Visual
{ {
} }
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
} }
private class FadeAccessibleBackground : BackgroundScreenBeatmap private class FadeAccessibleBackground : BackgroundScreenBeatmap
@ -358,6 +371,11 @@ namespace osu.Game.Tests.Visual
public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour;
public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha;
public FadeAccessibleBackground(WorkingBeatmap beatmap)
: base(beatmap)
{
}
private class TestUserDimContainer : UserDimContainer private class TestUserDimContainer : UserDimContainer
{ {
public Color4 CurrentColour => DimContainer.Colour; public Color4 CurrentColour => DimContainer.Colour;