protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { // This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures var working = new DummyWorkingBeatmap(parent.Get <AudioManager>(), parent.Get <TextureStore>()); beatmap = new NonNullableBindable <WorkingBeatmap>(working) { Default = working }; beatmap.BindValueChanged(b => ScheduleAfterChildren(() => { // compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo) if (b.OldValue?.TrackLoaded == true && b.OldValue?.Track != b.NewValue?.Track) { b.OldValue.RecycleTrack(); } })); Dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); Add(dummyAPI); } return(Dependencies); }
public object Get(Type type) { if (isolatedTypes.Contains(type)) { return(null); } return(parentDependencies.Get(type)); }
public object Get(Type type) { if (type == typeof(ISkinSource)) { return(SkinSource); } return(fallback.Get(type)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { if (!UseFreshStoragePerRun) { isolatedHostStorage = (parent.Get <GameHost>() as HeadlessGameHost)?.Storage; } Resources = parent.Get <OsuGameBase>().Resources; contextFactory = new Lazy <DatabaseContextFactory>(() => { var factory = new DatabaseContextFactory(LocalStorage); // only reset the database if not using the host storage. // if we reset the host storage, it will delete global key bindings. if (isolatedHostStorage == null) { factory.ResetDatabase(); } using (var usage = factory.Get()) usage.Migrate(); return(factory); }); RecycleLocalStorage(); var baseDependencies = base.CreateChildDependencies(parent); var providedRuleset = CreateRuleset(); if (providedRuleset != null) { baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies); } Dependencies = new OsuScreenDependencies(false, baseDependencies); Beatmap = Dependencies.Beatmap; Beatmap.SetDefault(); Ruleset = Dependencies.Ruleset; Ruleset.SetDefault(); SelectedMods = Dependencies.Mods; SelectedMods.SetDefault(); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); base.Content.Add(dummyAPI); } return(Dependencies); }
/// <summary> /// Retrieves a cached dependency of type <typeparamref name="T"/> if it exists, and default(<typeparamref name="T"/>) otherwise. /// </summary> /// <typeparam name="T">The dependency type to query for.</typeparam> /// <param name="container">The <see cref="IReadOnlyDependencyContainer"/> to query.</param> /// <returns>The requested dependency, or default(<typeparamref name="T"/>) if not found.</returns> internal static T GetValue <T>(this IReadOnlyDependencyContainer container) { var result = container.Get(typeof(T)); if (result == null) { return(default(T)); } return((T)container.Get(typeof(T))); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var game = parent.Get <Game>(); var host = parent.Get <GameHost>(); BlockingOnlineStore = new BlockingResourceStore(new NamespacedResourceStore <byte[]>(game.Resources, "Textures")); NormalStore = new TextureStore(host.CreateTextureLoaderStore(BlockingOnlineStore)); LargeStore = new LargeTextureStore(host.CreateTextureLoaderStore(BlockingOnlineStore)); return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { headlessHostStorage = (parent.Get <GameHost>() as HeadlessGameHost)?.Storage; Resources = parent.Get <OsuGameBase>().Resources; contextFactory = new Lazy <DatabaseContextFactory>(() => { var factory = new DatabaseContextFactory(LocalStorage); using (var usage = factory.Get()) usage.Migrate(); return(factory); }); RecycleLocalStorage(false); var baseDependencies = base.CreateChildDependencies(parent); // to isolate ruleset configs in tests from the actual database and avoid state pollution problems, // as well as problems due to the implementation details of the "real" implementation (the configs only being available at `LoadComplete()`), // cache a test implementation of the ruleset config cache over the "real" one. var isolatedBaseDependencies = new DependencyContainer(baseDependencies); isolatedBaseDependencies.CacheAs(RulesetConfigs = new TestRulesetConfigCache()); baseDependencies = isolatedBaseDependencies; var providedRuleset = CreateRuleset(); if (providedRuleset != null) { baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies); } Dependencies = new OsuScreenDependencies(false, baseDependencies); Beatmap = Dependencies.Beatmap; Beatmap.SetDefault(); Ruleset = Dependencies.Ruleset; Ruleset.SetDefault(); SelectedMods = Dependencies.Mods; SelectedMods.SetDefault(); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); base.Content.Add(dummyAPI); } return(Dependencies); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { // This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures var working = new DummyWorkingBeatmap(parent.Get <AudioManager>(), parent.Get <TextureStore>()); beatmap = new OsuTestBeatmap(working) { Default = working }; return(Dependencies = new DependencyContainer(base.CreateChildDependencies(parent))); }
public object Get(Type type, CacheInfo info) { if (info.Parent == null) { return(type == typeof(TModel) ? createChildShadowModel() : parent?.Get(type, info)); } if (info.Parent == typeof(TModel)) { return(shadowDependencies.Get(type, info) ?? parent?.Get(type, info)); } return(parent?.Get(type, info)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { parentSource = parent.Get <ISkinSource>(); parentSource.SourceChanged += OnSourceChanged; if (Ruleset.CreateResourceStore() is IResourceStore <byte[]> resources) { rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get <GameHost>(), parent.Get <AudioManager>()); } // ensure sources are populated and ready for use before childrens' asynchronous load flow. UpdateSkinSources(); return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { if (!UseFreshStoragePerRun) { isolatedHostStorage = (parent.Get <GameHost>() as HeadlessGameHost)?.Storage; } contextFactory = new Lazy <DatabaseContextFactory>(() => { var factory = new DatabaseContextFactory(LocalStorage); // only reset the database if not using the host storage. // if we reset the host storage, it will delete global key bindings. if (isolatedHostStorage == null) { factory.ResetDatabase(); } using (var usage = factory.Get()) usage.Migrate(); return(factory); }); RecycleLocalStorage(); return(dependencies = new DependencyContainer(base.CreateChildDependencies(parent))); }
/// <summary> /// Retrieves a cached dependency of type <typeparamref name="T"/> if it exists, and default(<typeparamref name="T"/>) otherwise. /// </summary> /// <typeparam name="T">The dependency type to query for.</typeparam> /// <param name="container">The <see cref="IReadOnlyDependencyContainer"/> to query.</param> /// <param name="info">Extra information that identifies the cached dependency.</param> /// <returns>The requested dependency, or default(<typeparamref name="T"/>) if not found.</returns> internal static T GetValue <T>(this IReadOnlyDependencyContainer container, CacheInfo info) { var result = container.Get(typeof(T), info); if (result == null) { return(default);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { // This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures beatmap.Default = new DummyWorkingBeatmap(parent.Get <OsuGameBase>()); return(Dependencies = new DependencyContainer(base.CreateChildDependencies(parent))); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var host = parent.Get <GameHost>(); headlessHostStorage = (host as HeadlessGameHost)?.Storage; Resources = parent.Get <OsuGameBase>().Resources; realm = new Lazy <RealmAccess>(() => new RealmAccess(LocalStorage, OsuGameBase.CLIENT_DATABASE_FILENAME, host.UpdateThread)); RecycleLocalStorage(false); var baseDependencies = base.CreateChildDependencies(parent); // to isolate ruleset configs in tests from the actual database and avoid state pollution problems, // as well as problems due to the implementation details of the "real" implementation (the configs only being available at `LoadComplete()`), // cache a test implementation of the ruleset config cache over the "real" one. var isolatedBaseDependencies = new DependencyContainer(baseDependencies); isolatedBaseDependencies.CacheAs(RulesetConfigs = new TestRulesetConfigCache()); baseDependencies = isolatedBaseDependencies; var providedRuleset = CreateRuleset(); if (providedRuleset != null) { isolatedBaseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies); } Dependencies = isolatedBaseDependencies; Beatmap.Default = parent.Get <Bindable <WorkingBeatmap> >().Default; Beatmap.SetDefault(); Ruleset.Value = CreateRuleset()?.RulesetInfo ?? parent.Get <RulesetStore>().AvailableRulesets.First(); SelectedMods.SetDefault(); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); base.Content.Add(dummyAPI); } return(Dependencies); }
/// <summary> /// Retrieves a cached dependency of <paramref name="type"/> if it exists. If not, then the parent /// <see cref="IReadOnlyDependencyContainer"/> is recursively queried. If no parent contains /// <paramref name="type"/>, then null is returned. /// </summary> /// <param name="type">The dependency type to query for.</param> /// <returns>The requested dependency, or null if not found.</returns> public object Get(Type type) { if (cache.TryGetValue(type, out object ret)) { return(ret); } return(parentContainer?.Get(type)); }
/// <summary> /// Retrieves a cached dependency of type <typeparamref name="T"/> if it exists, and default(<typeparamref name="T"/>) otherwise. /// </summary> /// <typeparam name="T">The dependency type to query for.</typeparam> /// <param name="container">The <see cref="IReadOnlyDependencyContainer"/> to query.</param> /// <param name="info">Extra information that identifies the cached dependency.</param> /// <returns>The requested dependency, or default(<typeparamref name="T"/>) if not found.</returns> internal static T GetValue <T>(this IReadOnlyDependencyContainer container, CacheInfo info) { if (container.Get(typeof(T), info) is T value) { return(value); } return(default);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { headlessHostStorage = (parent.Get <GameHost>() as HeadlessGameHost)?.Storage; Resources = parent.Get <OsuGameBase>().Resources; contextFactory = new Lazy <DatabaseContextFactory>(() => { var factory = new DatabaseContextFactory(LocalStorage); using (var usage = factory.Get()) usage.Migrate(); return(factory); }); RecycleLocalStorage(false); var baseDependencies = base.CreateChildDependencies(parent); var providedRuleset = CreateRuleset(); if (providedRuleset != null) { baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies); } Dependencies = new OsuScreenDependencies(false, baseDependencies); Beatmap = Dependencies.Beatmap; Beatmap.SetDefault(); Ruleset = Dependencies.Ruleset; Ruleset.SetDefault(); SelectedMods = Dependencies.Mods; SelectedMods.SetDefault(); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); base.Content.Add(dummyAPI); } return(Dependencies); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var deps = new DependencyContainer(base.CreateChildDependencies(parent)); deps.Cache(new RomStore(LocalStorage)); deps.Cache(new GamebosuConfigManager(parent.Get <SettingsStore>(), new GamebosuRuleset().RulesetInfo)); return(deps); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var config = parent.Get <OsuConfigManager>(); beatmapSkins = config.GetBindable <bool>(OsuSetting.BeatmapSkins); beatmapHitsounds = config.GetBindable <bool>(OsuSetting.BeatmapHitsounds); return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var dependencies = new DependencyContainer(parent); configManager = parent.Get <FrameworkConfigManager>(); dependencies.Cache(manager = new LocalisationManager(configManager)); return(dependencies); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var api = parent.Get <IAPIProvider>(); // needs to be set before the base BDL call executes to avoid invalidating any already populated markdown content. DocumentUrl = api.WebsiteRootUrl; return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var host = parent.Get <GameHost>(); normalStore = new TextureStore(host.CreateTextureLoaderStore(new OnlineStore())); largeStore = new LargeTextureStore(host.CreateTextureLoaderStore(new OnlineStore())); return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { if (Ruleset.CreateResourceStore() is IResourceStore <byte[]> resources) { rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get <GameHost>(), parent.Get <AudioManager>()); } return(base.CreateChildDependencies(parent)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var configCache = parent.Get <RulesetConfigCache>(); var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(new KaraokeRuleset()); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.Cache(new KaraokeSessionStatics(config, null)); return(dependencies); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { Add(channelManager = new ChannelManager(parent.Get <IAPIProvider>())); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.Cache(channelManager); return(dependencies); }
/// <summary> /// Retrieves a cached dependency of <paramref name="type"/> if it exists. If not, then the parent /// <see cref="IReadOnlyDependencyContainer"/> is recursively queried. If no parent contains /// <paramref name="type"/>, then null is returned. /// </summary> /// <param name="type">The dependency type to query for.</param> /// <returns>The requested dependency, or null if not found.</returns> public object Get(Type type) { type = Nullable.GetUnderlyingType(type) ?? type; if (cache.TryGetValue(type, out object ret)) { return(ret); } return(parentContainer?.Get(type)); }
public object Get(Type type, CacheInfo info) { info = info.WithType(Nullable.GetUnderlyingType(type) ?? type); if (cache.TryGetValue(info, out var existing)) { return(existing); } return(parentContainer?.Get(type, info)); }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { // This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures var working = new DummyWorkingBeatmap(parent.Get <AudioManager>(), parent.Get <TextureStore>()); beatmap = new OsuTestBeatmap(working) { Default = working }; Dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); if (!UseOnlineAPI) { dummyAPI = new DummyAPIAccess(); Dependencies.CacheAs <IAPIProvider>(dummyAPI); Add(dummyAPI); } return(Dependencies); }
public DrawableRulesetDependencies(Ruleset ruleset, IReadOnlyDependencyContainer parent) : base(parent) { var resources = ruleset.CreateResourceStore(); if (resources != null) { TextureStore = new TextureStore(parent.Get <GameHost>().CreateTextureLoaderStore(new NamespacedResourceStore <byte[]>(resources, @"Textures"))); CacheAs(TextureStore = new FallbackTextureStore(TextureStore, parent.Get <TextureStore>())); SampleStore = parent.Get <AudioManager>().GetSampleStore(new NamespacedResourceStore <byte[]>(resources, @"Samples")); SampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY; CacheAs(SampleStore = new FallbackSampleStore(SampleStore, parent.Get <ISampleStore>())); } RulesetConfigManager = parent.Get <RulesetConfigCache>().GetConfigFor(ruleset); if (RulesetConfigManager != null) { Cache(RulesetConfigManager); } }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); ruleset = parent.Get <IBindable <WorkingBeatmap> >().Value.BeatmapInfo.Ruleset?.CreateInstance(); composer = ruleset?.CreateHitObjectComposer(); // make the composer available to the timeline and other components in this screen. dependencies.CacheAs(composer); return(dependencies); }