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

View File

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

View File

@ -53,7 +53,7 @@ namespace osu.Game.Skinning
: this() : this()
{ {
if (skin != null) if (skin != null)
AddSource(skin); SetSources(new[] { skin });
} }
/// <summary> /// <summary>
@ -169,21 +169,10 @@ namespace osu.Game.Skinning
} }
/// <summary> /// <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> /// </summary>
/// <param name="skin">The skin to add.</param> /// <param name="sources">The new sources.</param>
protected void AddSource(ISkin skin) protected void SetSources(IEnumerable<ISkin> sources)
{
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()
{ {
foreach (var skin in skinSources) foreach (var skin in skinSources)
{ {
@ -191,11 +180,17 @@ namespace osu.Game.Skinning
source.SourceChanged -= TriggerSourceChanged; 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> /// <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. /// This is also invoked once initially during <see cref="CreateChildDependencies"/> to ensure sources are ready for children consumption.
/// </summary> /// </summary>
protected virtual void OnSourceChanged() { } protected virtual void OnSourceChanged() { }