1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:20:04 +08:00

Replace Add/Reset methods with single Set method

This commit is contained in:
Dean Herbert 2021-10-12 11:55:04 +09:00
parent df83f0db08
commit 39a3482458
3 changed files with 14 additions and 24 deletions

View File

@ -6,7 +6,6 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
@ -67,8 +66,7 @@ namespace osu.Game.Tests.Skins
protected override void OnSourceChanged()
{
ResetSources();
sources.ForEach(AddSource);
SetSources(sources);
}
}

View File

@ -60,8 +60,6 @@ namespace osu.Game.Skinning
protected override void OnSourceChanged()
{
ResetSources();
// Populate a local list first so we can adjust the returned order as we go.
var sources = new List<ISkin>();
@ -91,8 +89,7 @@ namespace osu.Game.Skinning
else
sources.Add(rulesetResourcesSkin);
foreach (var skin in sources)
AddSource(skin);
SetSources(sources);
}
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)

View File

@ -53,7 +53,7 @@ namespace osu.Game.Skinning
: this()
{
if (skin != null)
AddSource(skin);
SetSources(new[] { skin });
}
/// <summary>
@ -169,21 +169,10 @@ namespace osu.Game.Skinning
}
/// <summary>
/// Add a new skin to this provider. Will be added to the end of the lookup order precedence.
/// Replace the sources used for lookups in this container.
/// </summary>
/// <param name="skin">The skin to add.</param>
protected void AddSource(ISkin skin)
{
skinSources = skinSources.Append((skin, new DisableableSkinSource(skin, this))).ToArray();
if (skin is ISkinSource source)
source.SourceChanged += TriggerSourceChanged;
}
/// <summary>
/// Clears all skin sources.
/// </summary>
protected void ResetSources()
/// <param name="sources">The new sources.</param>
protected void SetSources(IEnumerable<ISkin> sources)
{
foreach (var skin in skinSources)
{
@ -191,11 +180,17 @@ namespace osu.Game.Skinning
source.SourceChanged -= TriggerSourceChanged;
}
skinSources = Array.Empty<(ISkin skin, DisableableSkinSource wrapped)>();
skinSources = sources.Select(skin => (skin, new DisableableSkinSource(skin, this))).ToArray();
foreach (var skin in skinSources)
{
if (skin.skin is ISkinSource source)
source.SourceChanged += TriggerSourceChanged;
}
}
/// <summary>
/// Invoked when any source has changed (either <see cref="ParentSource"/> or a source registered via <see cref="AddSource"/>).
/// Invoked when any source has changed (either <see cref="ParentSource"/> or sources replaced via <see cref="SetSources"/>).
/// This is also invoked once initially during <see cref="CreateChildDependencies"/> to ensure sources are ready for children consumption.
/// </summary>
protected virtual void OnSourceChanged() { }