1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +08:00

Use DI for Player

This commit is contained in:
Drew DeVault 2016-11-04 18:18:08 -04:00
parent 19fd6fe249
commit dc03f36793
4 changed files with 26 additions and 10 deletions

@ -1 +1 @@
Subproject commit 25b8c3c6cfead49acf5659a750c7e604289d5b81
Subproject commit eb16219058e87210c9ad90b1e214ccc2c1556058

View File

@ -11,6 +11,7 @@ using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.GameModes.Play;
using OpenTK;
using osu.Framework;
namespace osu.Desktop.VisualTests.Tests
{
@ -24,6 +25,14 @@ namespace osu.Desktop.VisualTests.Tests
protected override IFrameBasedClock Clock => localClock;
private BaseGame game;
protected override void Load(BaseGame game)
{
base.Load(game);
this.game = game;
}
public override void Reset()
{
base.Reset();
@ -55,10 +64,9 @@ namespace osu.Desktop.VisualTests.Tests
decoder.Process(b);
Add(new Player
{
Beatmap = new WorkingBeatmap(b)
});
var player = game.Dependencies.Get<Player>();
player.Beatmap = new WorkingBeatmap(b);
Add(player);
}
protected override void Update()

View File

@ -113,10 +113,13 @@ namespace osu.Game.GameModes.Play
Width = 100,
Text = "Play",
Colour = new Color4(238, 51, 153, 255),
Action = () => Push(new Player {
BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap,
PreferredPlayMode = playMode.Value
}),
Action = () =>
{
var player = Game.Dependencies.Get<Player>();
player.BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap;
player.PreferredPlayMode = playMode.Value;
Push(player);
}
},
}
}

View File

@ -30,6 +30,12 @@ namespace osu.Game.GameModes.Play
private InterpolatingFramedClock playerClock;
private IAdjustableClock sourceClock;
private BeatmapDatabase beatmaps;
public Player(BeatmapDatabase beatmaps)
{
this.beatmaps = beatmaps;
}
protected override void Load(BaseGame game)
{
@ -37,7 +43,6 @@ namespace osu.Game.GameModes.Play
try
{
var beatmaps = Game.Dependencies.Get<BeatmapDatabase>();
if (Beatmap == null)
Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo);
}