mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Privatise the OsuGame beatmap, add local beatmap to OsuTestCase
This commit is contained in:
@ -25,24 +25,20 @@ namespace osu.Game.Tests.Visual
|
||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
||||
=> dependencies = new DependencyContainer(parent);
|
||||
|
||||
private OsuGameBase osuGame;
|
||||
|
||||
protected EditorClockTestCase()
|
||||
{
|
||||
Clock = new EditorClock(new ControlPointInfo(), BeatDivisor) { IsCoupled = false };
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
private void load()
|
||||
{
|
||||
this.osuGame = osuGame;
|
||||
|
||||
dependencies.Cache(BeatDivisor);
|
||||
dependencies.CacheAs<IFrameBasedClock>(Clock);
|
||||
dependencies.CacheAs<IAdjustableClock>(Clock);
|
||||
|
||||
osuGame.Beatmap.ValueChanged += beatmapChanged;
|
||||
beatmapChanged(osuGame.Beatmap.Value);
|
||||
Beatmap.ValueChanged += beatmapChanged;
|
||||
beatmapChanged(Beatmap.Value);
|
||||
}
|
||||
|
||||
private void beatmapChanged(WorkingBeatmap working)
|
||||
@ -68,12 +64,5 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
osuGame.Beatmap.ValueChanged -= beatmapChanged;
|
||||
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
private void load()
|
||||
{
|
||||
osuGame.Beatmap.Value = new TestWorkingBeatmap(ruleset.RulesetInfo);
|
||||
Beatmap.Value = new TestWorkingBeatmap(ruleset.RulesetInfo);
|
||||
|
||||
LoadComponentAsync(new Editor(), LoadScreen);
|
||||
}
|
||||
|
@ -3,12 +3,28 @@
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public abstract class OsuTestCase : TestCase
|
||||
{
|
||||
protected readonly GameBeatmap Beatmap = new GameBeatmap(new DummyWorkingBeatmap());
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
||||
=> dependencies = new DependencyContainer(parent);
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
dependencies.CacheAs<IGameBeatmap>(Beatmap);
|
||||
dependencies.Cache(Beatmap);
|
||||
}
|
||||
|
||||
protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();
|
||||
|
||||
public class OsuTestCaseTestRunner : OsuGameBase, ITestCaseTestRunner
|
||||
|
@ -50,7 +50,7 @@ namespace osu.Game.Tests.Visual
|
||||
new ScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new BeatmapList(ruleset)
|
||||
Child = new BeatmapList(ruleset, Beatmap)
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -108,10 +108,12 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
private readonly Container<BeatmapDisplay> beatmapDisplays;
|
||||
private readonly Ruleset ruleset;
|
||||
private readonly GameBeatmap beatmapBindable;
|
||||
|
||||
public BeatmapList(Ruleset ruleset)
|
||||
public BeatmapList(Ruleset ruleset, GameBeatmap beatmapBindable)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
this.beatmapBindable = beatmapBindable;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
@ -130,7 +132,7 @@ namespace osu.Game.Tests.Visual
|
||||
var sets = beatmaps.GetAllUsableBeatmapSets();
|
||||
var allBeatmaps = sets.SelectMany(s => s.Beatmaps).Where(b => ruleset.LegacyID == null || b.RulesetID == ruleset.LegacyID);
|
||||
|
||||
allBeatmaps.ForEach(b => beatmapDisplays.Add(new BeatmapDisplay(b)));
|
||||
allBeatmaps.ForEach(b => beatmapDisplays.Add(new BeatmapDisplay(b, beatmapBindable)));
|
||||
}
|
||||
|
||||
private class BeatmapDisplay : CompositeDrawable, IHasTooltip
|
||||
@ -138,27 +140,47 @@ namespace osu.Game.Tests.Visual
|
||||
private readonly OsuSpriteText text;
|
||||
private readonly BeatmapInfo beatmap;
|
||||
|
||||
private readonly GameBeatmap beatmapBindable;
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private OsuGameBase osuGame;
|
||||
|
||||
private bool isSelected;
|
||||
|
||||
public string TooltipText => text.Text;
|
||||
|
||||
public BeatmapDisplay(BeatmapInfo beatmap)
|
||||
public BeatmapDisplay(BeatmapInfo beatmap, GameBeatmap beatmapBindable)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
this.beatmapBindable = beatmapBindable;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
InternalChild = text = new OsuSpriteText();
|
||||
|
||||
this.beatmapBindable.ValueChanged += beatmapChanged;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BeatmapManager beatmaps)
|
||||
{
|
||||
this.beatmaps = beatmaps;
|
||||
|
||||
var working = beatmaps.GetWorkingBeatmap(beatmap);
|
||||
text.Text = $"{working.Metadata.Artist} - {working.Metadata.Title} ({working.Metadata.AuthorString}) [{working.BeatmapInfo.Version}]";
|
||||
}
|
||||
|
||||
private void beatmapChanged(WorkingBeatmap newBeatmap)
|
||||
{
|
||||
if (isSelected)
|
||||
this.FadeColour(Color4.White, 100);
|
||||
isSelected = false;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
if (osuGame.Beatmap.Value.BeatmapInfo.ID == beatmap.ID)
|
||||
if (beatmapBindable.Value.BeatmapInfo.ID == beatmap.ID)
|
||||
return false;
|
||||
|
||||
osuGame.Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap);
|
||||
beatmapBindable.Value = beatmaps.GetWorkingBeatmap(beatmap);
|
||||
isSelected = true;
|
||||
return true;
|
||||
}
|
||||
@ -177,25 +199,6 @@ namespace osu.Game.Tests.Visual
|
||||
return;
|
||||
this.FadeColour(Color4.White, 100);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame, BeatmapManager beatmaps)
|
||||
{
|
||||
this.osuGame = osuGame;
|
||||
this.beatmaps = beatmaps;
|
||||
|
||||
var working = beatmaps.GetWorkingBeatmap(beatmap);
|
||||
text.Text = $"{working.Metadata.Artist} - {working.Metadata.Title} ({working.Metadata.AuthorString}) [{working.BeatmapInfo.Version}]";
|
||||
|
||||
osuGame.Beatmap.ValueChanged += beatmapChanged;
|
||||
}
|
||||
|
||||
private void beatmapChanged(WorkingBeatmap newBeatmap)
|
||||
{
|
||||
if (isSelected)
|
||||
this.FadeColour(Color4.White, 100);
|
||||
isSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +207,7 @@ namespace osu.Game.Tests.Visual
|
||||
private readonly FillFlowContainer<PerformanceDisplay> scores;
|
||||
private APIAccess api;
|
||||
|
||||
private readonly Bindable<WorkingBeatmap> currentBeatmap = new Bindable<WorkingBeatmap>();
|
||||
private readonly IBindable<WorkingBeatmap> currentBeatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
public PerformanceList()
|
||||
{
|
||||
@ -220,7 +223,7 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame, APIAccess api)
|
||||
private void load(IGameBeatmap beatmap, APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
|
||||
@ -235,7 +238,7 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
currentBeatmap.ValueChanged += beatmapChanged;
|
||||
currentBeatmap.BindTo(osuGame.Beatmap);
|
||||
currentBeatmap.BindTo(beatmap);
|
||||
}
|
||||
|
||||
private GetScoresRequest lastRequest;
|
||||
@ -333,9 +336,9 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
private void load(IGameBeatmap beatmap)
|
||||
{
|
||||
osuGame.Beatmap.ValueChanged += beatmapChanged;
|
||||
beatmap.ValueChanged += beatmapChanged;
|
||||
}
|
||||
|
||||
private Cached informationCache = new Cached();
|
||||
|
@ -19,8 +19,6 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
protected Player Player;
|
||||
|
||||
private TestWorkingBeatmap working;
|
||||
|
||||
protected TestCasePlayer(Ruleset ruleset)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
@ -65,13 +63,13 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
var beatmap = CreateBeatmap(r);
|
||||
|
||||
working = new TestWorkingBeatmap(beatmap);
|
||||
working.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
||||
Beatmap.Value = new TestWorkingBeatmap(beatmap);
|
||||
Beatmap.Value.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
||||
|
||||
if (Player != null)
|
||||
Remove(Player);
|
||||
|
||||
var player = CreatePlayer(working, r);
|
||||
var player = CreatePlayer(Beatmap, r);
|
||||
|
||||
LoadComponentAsync(player, LoadScreen);
|
||||
|
||||
@ -82,14 +80,12 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (working != null)
|
||||
// note that this will override any mod rate application
|
||||
working.Track.Rate = Clock.Rate;
|
||||
// note that this will override any mod rate application
|
||||
Beatmap.Value.Track.Rate = Clock.Rate;
|
||||
}
|
||||
|
||||
protected virtual Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset) => new Player
|
||||
{
|
||||
InitialBeatmap = beatmap,
|
||||
AllowPause = false,
|
||||
AllowLeadIn = false,
|
||||
AllowResults = false,
|
||||
|
Reference in New Issue
Block a user