Use isolated storage/api

This commit is contained in:
Dean Herbert 2019-09-25 15:00:08 +09:00
parent 654b815b36
commit c83db94eb7
3 changed files with 33 additions and 26 deletions

View File

@ -28,7 +28,7 @@ public class TestSceneScreenNavigation : ManualInputManagerTestScene
{
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 @@ public class TestSceneScreenNavigation : ManualInputManagerTestScene
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 @@ public void SetUpSteps()
osuGame.Dispose();
}
osuGame = new TestOsuGame();
osuGame.SetHost(gameHost);
osuGame = new TestOsuGame(LocalStorage, API);
osuGame.SetHost(host);
Add(osuGame);
});
@ -163,19 +163,16 @@ private class TestOsuGame : OsuGame
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!");
}
}

View File

@ -64,7 +64,10 @@ public abstract class APIRequest
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;

View File

@ -65,7 +65,7 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles
protected RulesetConfigCache RulesetConfigCache;
protected APIAccess API;
protected IAPIProvider API;
protected MenuCursorContainer MenuCursorContainer;
@ -73,6 +73,8 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles
protected override Container<Drawable> Content => content;
protected Storage Storage { get; set; }
private Bindable<WorkingBeatmap> beatmap; // cached via load() method
[Cached]
@ -123,7 +125,7 @@ private void load()
{
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 @@ private void load()
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 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
FileStore.Cleanup();
AddInternal(API);
if (API is APIAccess apiAcces)
AddInternal(apiAcces);
AddInternal(RulesetConfigCache);
GlobalActionContainer globalBinding;
@ -266,9 +269,13 @@ private void runMigrations()
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>();