2021-06-25 04:02:19 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2022-02-15 11:56:46 +00:00
|
|
|
using osu.Game.Database;
|
2021-06-25 04:02:19 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-08-12 11:08:14 +00:00
|
|
|
using osu.Game.Overlays;
|
2021-06-25 04:02:19 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.OnlinePlay
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-06-25 09:07:47 +00:00
|
|
|
/// Contains the basic dependencies of online play test scenes.
|
2021-06-25 04:02:19 +00:00
|
|
|
/// </summary>
|
2021-06-25 11:15:30 +00:00
|
|
|
public class OnlinePlayTestSceneDependencies : IReadOnlyDependencyContainer, IOnlinePlayTestSceneDependencies
|
2021-06-25 04:02:19 +00:00
|
|
|
{
|
|
|
|
public Bindable<Room> SelectedRoom { get; }
|
|
|
|
public IRoomManager RoomManager { get; }
|
|
|
|
public OngoingOperationTracker OngoingOperationTracker { get; }
|
|
|
|
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker { get; }
|
2021-10-27 07:10:22 +00:00
|
|
|
public TestRoomRequestsHandler RequestsHandler { get; }
|
2022-02-15 11:56:46 +00:00
|
|
|
public TestUserLookupCache UserLookupCache { get; }
|
2022-02-15 12:05:05 +00:00
|
|
|
public BeatmapLookupCache BeatmapLookupCache { get; }
|
2021-06-25 04:02:19 +00:00
|
|
|
|
|
|
|
/// <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 11:11:38 +00:00
|
|
|
public OnlinePlayTestSceneDependencies()
|
2021-06-25 04:02:19 +00:00
|
|
|
{
|
|
|
|
SelectedRoom = new Bindable<Room>();
|
2021-10-28 05:29:49 +00:00
|
|
|
RequestsHandler = new TestRoomRequestsHandler();
|
2021-06-25 04:02:19 +00:00
|
|
|
OngoingOperationTracker = new OngoingOperationTracker();
|
|
|
|
AvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
|
2021-10-28 05:29:49 +00:00
|
|
|
RoomManager = CreateRoomManager();
|
2022-02-15 11:56:46 +00:00
|
|
|
UserLookupCache = new TestUserLookupCache();
|
2022-02-15 12:05:05 +00:00
|
|
|
BeatmapLookupCache = new BeatmapLookupCache();
|
2021-06-25 04:02:19 +00:00
|
|
|
|
|
|
|
dependencies = new DependencyContainer(new CachedModelDependencyContainer<Room>(null) { Model = { BindTarget = SelectedRoom } });
|
|
|
|
|
2021-10-27 07:10:22 +00:00
|
|
|
CacheAs(RequestsHandler);
|
2021-06-25 04:02:19 +00:00
|
|
|
CacheAs(SelectedRoom);
|
|
|
|
CacheAs(RoomManager);
|
|
|
|
CacheAs(OngoingOperationTracker);
|
|
|
|
CacheAs(AvailabilityTracker);
|
2021-08-12 11:08:14 +00:00
|
|
|
CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum));
|
2022-02-15 11:56:46 +00:00
|
|
|
CacheAs<UserLookupCache>(UserLookupCache);
|
2022-02-15 12:05:05 +00:00
|
|
|
CacheAs(BeatmapLookupCache);
|
2021-06-25 04:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 07:10:22 +00:00
|
|
|
protected virtual IRoomManager CreateRoomManager() => new TestRoomManager();
|
2021-06-25 04:02:19 +00:00
|
|
|
}
|
|
|
|
}
|