// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Online.Rooms; using osu.Game.Overlays; using osu.Game.Screens.OnlinePlay; namespace osu.Game.Tests.Visual.OnlinePlay { /// /// Contains the basic dependencies of online play test scenes. /// public class OnlinePlayTestSceneDependencies : IReadOnlyDependencyContainer, IOnlinePlayTestSceneDependencies { public Bindable SelectedRoom { get; } public IRoomManager RoomManager { get; } public OngoingOperationTracker OngoingOperationTracker { get; } public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker { get; } public TestRoomRequestsHandler RequestsHandler { get; } /// /// All cached dependencies which are also components. /// public IReadOnlyList DrawableComponents => drawableComponents; private readonly List drawableComponents = new List(); private readonly DependencyContainer dependencies; public OnlinePlayTestSceneDependencies() { SelectedRoom = new Bindable(); RoomManager = CreateRoomManager(); OngoingOperationTracker = new OngoingOperationTracker(); AvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker(); RequestsHandler = new TestRoomRequestsHandler(); dependencies = new DependencyContainer(new CachedModelDependencyContainer(null) { Model = { BindTarget = SelectedRoom } }); CacheAs(RequestsHandler); CacheAs(SelectedRoom); CacheAs(RoomManager); CacheAs(OngoingOperationTracker); CacheAs(AvailabilityTracker); CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum)); } public object Get(Type type) => dependencies.Get(type); public object Get(Type type, CacheInfo info) => dependencies.Get(type, info); public void Inject(T instance) where T : class => dependencies.Inject(instance); protected void Cache(object instance) { dependencies.Cache(instance); if (instance is Drawable drawable) drawableComponents.Add(drawable); } protected void CacheAs(T instance) where T : class { dependencies.CacheAs(instance); if (instance is Drawable drawable) drawableComponents.Add(drawable); } protected virtual IRoomManager CreateRoomManager() => new TestRoomManager(); } }