1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 22:22:55 +08:00
osu-lazer/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs

89 lines
3.2 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Database;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Screens.OnlinePlay;
namespace osu.Game.Tests.Visual.OnlinePlay
{
/// <summary>
/// Contains the basic dependencies of online play test scenes.
/// </summary>
2021-06-25 19:15:30 +08:00
public class OnlinePlayTestSceneDependencies : IReadOnlyDependencyContainer, IOnlinePlayTestSceneDependencies
{
public Bindable<Room> SelectedRoom { get; }
public IRoomManager RoomManager { get; }
public OngoingOperationTracker OngoingOperationTracker { get; }
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker { get; }
2021-10-27 15:10:22 +08:00
public TestRoomRequestsHandler RequestsHandler { get; }
public TestUserLookupCache UserLookupCache { get; }
public BeatmapLookupCache BeatmapLookupCache { get; }
/// <summary>
/// All cached dependencies which are also <see cref="Drawable"/> components.
/// </summary>
public IReadOnlyList<Drawable> DrawableComponents => drawableComponents;
private readonly List<Drawable> drawableComponents = new List<Drawable>();
private readonly DependencyContainer dependencies;
2021-06-25 19:11:38 +08:00
public OnlinePlayTestSceneDependencies()
{
SelectedRoom = new Bindable<Room>();
RequestsHandler = new TestRoomRequestsHandler();
OngoingOperationTracker = new OngoingOperationTracker();
AvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
RoomManager = CreateRoomManager();
UserLookupCache = new TestUserLookupCache();
BeatmapLookupCache = new BeatmapLookupCache();
dependencies = new DependencyContainer(new CachedModelDependencyContainer<Room>(null) { Model = { BindTarget = SelectedRoom } });
2021-10-27 15:10:22 +08:00
CacheAs(RequestsHandler);
CacheAs(SelectedRoom);
CacheAs(RoomManager);
CacheAs(OngoingOperationTracker);
CacheAs(AvailabilityTracker);
CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum));
CacheAs<UserLookupCache>(UserLookupCache);
CacheAs(BeatmapLookupCache);
}
public object Get(Type type)
=> dependencies.Get(type);
public object Get(Type type, CacheInfo info)
=> dependencies.Get(type, info);
public void Inject<T>(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>(T instance)
where T : class
{
dependencies.CacheAs(instance);
if (instance is Drawable drawable)
drawableComponents.Add(drawable);
}
2021-10-27 15:10:22 +08:00
protected virtual IRoomManager CreateRoomManager() => new TestRoomManager();
}
}