2021-07-05 18:05:49 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-05 18:05:49 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A <see cref="Container"/> which providing ad-hoc dependencies to the child drawables.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
2021-07-19 13:37:19 +08:00
|
|
|
/// The <see cref="CachedDependencies"/> must be set while this <see cref="DependencyProvidingContainer"/> is not loaded.
|
2021-07-05 18:05:49 +08:00
|
|
|
/// </remarks>
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class DependencyProvidingContainer : Container
|
2021-07-05 18:05:49 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2021-07-19 13:37:19 +08:00
|
|
|
/// The dependencies provided to the children.
|
2021-07-05 18:05:49 +08:00
|
|
|
/// </summary>
|
2023-02-09 09:51:28 +08:00
|
|
|
public (Type, object)[] CachedDependencies { get; init; } = Array.Empty<(Type, object)>();
|
2021-07-05 18:05:49 +08:00
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencyContainer = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
foreach ((var type, object value) in CachedDependencies)
|
2021-07-05 18:05:49 +08:00
|
|
|
dependencyContainer.CacheAs(type, value);
|
|
|
|
|
|
|
|
return dependencyContainer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|