mirror of
https://github.com/ppy/osu
synced 2024-12-26 08:53:10 +00:00
Use isolated storage/api
This commit is contained in:
parent
654b815b36
commit
c83db94eb7
@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
{
|
||||
private const float click_padding = 25;
|
||||
|
||||
private GameHost gameHost;
|
||||
private GameHost host;
|
||||
private TestOsuGame osuGame;
|
||||
|
||||
private Vector2 backButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, osuGame.LayoutRectangle.Bottom - click_padding));
|
||||
@ -36,9 +36,9 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
private Vector2 optionsButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, click_padding));
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost gameHost)
|
||||
private void load(GameHost host)
|
||||
{
|
||||
this.gameHost = gameHost;
|
||||
this.host = host;
|
||||
|
||||
Child = new Box
|
||||
{
|
||||
@ -58,8 +58,8 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
osuGame.Dispose();
|
||||
}
|
||||
|
||||
osuGame = new TestOsuGame();
|
||||
osuGame.SetHost(gameHost);
|
||||
osuGame = new TestOsuGame(LocalStorage, API);
|
||||
osuGame.SetHost(host);
|
||||
|
||||
Add(osuGame);
|
||||
});
|
||||
@ -163,19 +163,16 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
|
||||
protected override Loader CreateLoader() => new TestLoader();
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
private DummyAPIAccess dummyAPI;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
||||
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
public TestOsuGame(Storage storage, IAPIProvider api)
|
||||
{
|
||||
Storage = storage;
|
||||
API = api;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
dependencies.CacheAs<IAPIProvider>(dummyAPI = new DummyAPIAccess());
|
||||
|
||||
dummyAPI.Login("Rhythm Champion", "osu!");
|
||||
API.Login("Rhythm Champion", "osu!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,10 @@ namespace osu.Game.Online.API
|
||||
public void Perform(IAPIProvider api)
|
||||
{
|
||||
if (!(api is APIAccess apiAccess))
|
||||
throw new NotSupportedException($"A {nameof(APIAccess)} is required to perform requests.");
|
||||
{
|
||||
Fail(new NotSupportedException($"A {nameof(APIAccess)} is required to perform requests."));
|
||||
return;
|
||||
}
|
||||
|
||||
API = apiAccess;
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace osu.Game
|
||||
|
||||
protected RulesetConfigCache RulesetConfigCache;
|
||||
|
||||
protected APIAccess API;
|
||||
protected IAPIProvider API;
|
||||
|
||||
protected MenuCursorContainer MenuCursorContainer;
|
||||
|
||||
@ -73,6 +73,8 @@ namespace osu.Game
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
protected Storage Storage { get; set; }
|
||||
|
||||
private Bindable<WorkingBeatmap> beatmap; // cached via load() method
|
||||
|
||||
[Cached]
|
||||
@ -123,7 +125,7 @@ namespace osu.Game
|
||||
{
|
||||
Resources.AddStore(new DllResourceStore(@"osu.Game.Resources.dll"));
|
||||
|
||||
dependencies.Cache(contextFactory = new DatabaseContextFactory(Host.Storage));
|
||||
dependencies.Cache(contextFactory = new DatabaseContextFactory(Storage));
|
||||
|
||||
var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
|
||||
largeStore.AddStore(Host.CreateTextureLoaderStore(new OnlineStore()));
|
||||
@ -158,21 +160,21 @@ namespace osu.Game
|
||||
|
||||
runMigrations();
|
||||
|
||||
dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio, new NamespacedResourceStore<byte[]>(Resources, "Skins/Legacy")));
|
||||
dependencies.Cache(SkinManager = new SkinManager(Storage, contextFactory, Host, Audio, new NamespacedResourceStore<byte[]>(Resources, "Skins/Legacy")));
|
||||
dependencies.CacheAs<ISkinSource>(SkinManager);
|
||||
|
||||
API = new APIAccess(LocalConfig);
|
||||
if (API == null) API = new APIAccess(LocalConfig);
|
||||
|
||||
dependencies.CacheAs<IAPIProvider>(API);
|
||||
dependencies.CacheAs(API);
|
||||
|
||||
var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures);
|
||||
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
|
||||
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
|
||||
dependencies.Cache(FileStore = new FileStore(contextFactory, Storage));
|
||||
|
||||
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
|
||||
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Host.Storage, API, contextFactory, Host));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, API, Audio, Host, defaultBeatmap));
|
||||
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Host));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, contextFactory, RulesetStore, API, Audio, Host, defaultBeatmap));
|
||||
|
||||
// this should likely be moved to ArchiveModelManager when another case appers where it is necessary
|
||||
// to have inter-dependent model managers. this could be obtained with an IHasForeign<T> interface to
|
||||
@ -206,7 +208,8 @@ namespace osu.Game
|
||||
|
||||
FileStore.Cleanup();
|
||||
|
||||
AddInternal(API);
|
||||
if (API is APIAccess apiAcces)
|
||||
AddInternal(apiAcces);
|
||||
AddInternal(RulesetConfigCache);
|
||||
|
||||
GlobalActionContainer globalBinding;
|
||||
@ -266,9 +269,13 @@ namespace osu.Game
|
||||
|
||||
public override void SetHost(GameHost host)
|
||||
{
|
||||
if (LocalConfig == null)
|
||||
LocalConfig = new OsuConfigManager(host.Storage);
|
||||
base.SetHost(host);
|
||||
|
||||
if (Storage == null)
|
||||
Storage = host.Storage;
|
||||
|
||||
if (LocalConfig == null)
|
||||
LocalConfig = new OsuConfigManager(Storage);
|
||||
}
|
||||
|
||||
private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>();
|
||||
|
Loading…
Reference in New Issue
Block a user