1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00

Introduce dependency injection

This commit is contained in:
Drew DeVault 2016-11-04 18:06:58 -04:00
parent 788c11de10
commit 19fd6fe249
5 changed files with 17 additions and 11 deletions

View File

@ -29,7 +29,7 @@ namespace osu.Game.Tests.Beatmaps.IO
HeadlessGameHost host = new HeadlessGameHost();
var osu = loadOsu(host);
osu.Beatmaps.Import(osz_path);
osu.Dependencies.Get<BeatmapDatabase>().Import(osz_path);
ensureLoaded(osu);
}
@ -60,7 +60,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Thread.Sleep(1);
//reset beatmap database (sqlite and storage backing)
osu.Beatmaps.Reset();
osu.Dependencies.Get<BeatmapDatabase>().Reset();
return osu;
}
@ -71,7 +71,8 @@ namespace osu.Game.Tests.Beatmaps.IO
Action waitAction = () =>
{
while ((resultSets = osu.Beatmaps.Query<BeatmapSetInfo>().Where(s => s.BeatmapSetID == 241526)).Count() != 1)
while ((resultSets = osu.Dependencies.Get<BeatmapDatabase>()
.Query<BeatmapSetInfo>().Where(s => s.BeatmapSetID == 241526)).Count() != 1)
Thread.Sleep(1);
};
@ -87,7 +88,8 @@ namespace osu.Game.Tests.Beatmaps.IO
//if we don't re-check here, the set will be inserted but the beatmaps won't be present yet.
waitAction = () =>
{
while ((resultBeatmaps = osu.Beatmaps.Query<BeatmapInfo>().Where(s => s.BeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
while ((resultBeatmaps = osu.Dependencies.Get<BeatmapDatabase>()
.Query<BeatmapInfo>().Where(s => s.BeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
Thread.Sleep(1);
};
@ -95,7 +97,7 @@ namespace osu.Game.Tests.Beatmaps.IO
@"Beatmaps did not import to the database");
//fetch children and check we can load from the post-storage path...
var set = osu.Beatmaps.GetChildren(resultSets.First());
var set = osu.Dependencies.Get<BeatmapDatabase>().GetChildren(resultSets.First());
Assert.IsTrue(set.Beatmaps.Count == resultBeatmaps.Count());
@ -104,7 +106,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Assert.IsTrue(set.Beatmaps.Count > 0);
var beatmap = osu.Beatmaps.GetBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu));
var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu));
Assert.IsTrue(beatmap.HitObjects.Count > 0);
}

View File

@ -137,7 +137,7 @@ namespace osu.Game.GameModes.Play
}
if (database == null)
database = (game as OsuGameBase).Beatmaps;
database = game.Dependencies.Get<BeatmapDatabase>();
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));

View File

@ -37,8 +37,9 @@ namespace osu.Game.GameModes.Play
try
{
var beatmaps = Game.Dependencies.Get<BeatmapDatabase>();
if (Beatmap == null)
Beatmap = ((OsuGame)game).Beatmaps.GetWorkingBeatmap(BeatmapInfo);
Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo);
}
catch
{

View File

@ -19,6 +19,7 @@ using osu.Game.Input;
using OpenTK.Input;
using osu.Framework.Logging;
using osu.Game.Graphics.UserInterface.Volume;
using osu.Game.Database;
namespace osu.Game
{
@ -61,7 +62,7 @@ namespace osu.Game
base.Load(game);
if (args?.Length > 0)
Schedule(delegate { Beatmaps.Import(args); });
Schedule(delegate { Dependencies.Get<BeatmapDatabase>().Import(args); });
//attach our bindables to the audio subsystem.
Audio.Volume.Weld(Config.GetBindable<double>(OsuConfig.VolumeUniversal));

View File

@ -23,7 +23,6 @@ namespace osu.Game
public class OsuGameBase : BaseGame
{
internal OsuConfigManager Config;
public BeatmapDatabase Beatmaps { get; private set; }
protected override string MainResourceFile => @"osu.Game.Resources.dll";
@ -57,8 +56,11 @@ namespace osu.Game
{
base.Load(game);
Dependencies.Cache(this);
Dependencies.Cache<OsuConfigManager>();
Dependencies.Cache(new BeatmapDatabase(Host.Storage, Host));
OszArchiveReader.Register();
Beatmaps = new BeatmapDatabase(Host.Storage, Host);
//this completely overrides the framework default. will need to change once we make a proper FontStore.
Fonts = new TextureStore() { ScaleAdjust = 0.01f };