From 39a3482458b586787e0612503f55a77463a57d7f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 12 Oct 2021 11:55:04 +0900 Subject: [PATCH] Replace Add/Reset methods with single `Set` method --- .../Skins/TestSceneSkinProvidingContainer.cs | 4 +-- .../Skinning/RulesetSkinProvidingContainer.cs | 5 +--- osu.Game/Skinning/SkinProvidingContainer.cs | 29 ++++++++----------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs b/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs index ab47067411..2247f685e2 100644 --- a/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs +++ b/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs @@ -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); } } diff --git a/osu.Game/Skinning/RulesetSkinProvidingContainer.cs b/osu.Game/Skinning/RulesetSkinProvidingContainer.cs index f5a7788359..e63af0dfbd 100644 --- a/osu.Game/Skinning/RulesetSkinProvidingContainer.cs +++ b/osu.Game/Skinning/RulesetSkinProvidingContainer.cs @@ -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(); @@ -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) diff --git a/osu.Game/Skinning/SkinProvidingContainer.cs b/osu.Game/Skinning/SkinProvidingContainer.cs index d2c3a6e837..b769332e37 100644 --- a/osu.Game/Skinning/SkinProvidingContainer.cs +++ b/osu.Game/Skinning/SkinProvidingContainer.cs @@ -53,7 +53,7 @@ namespace osu.Game.Skinning : this() { if (skin != null) - AddSource(skin); + SetSources(new[] { skin }); } /// @@ -169,21 +169,10 @@ namespace osu.Game.Skinning } /// - /// 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. /// - /// The skin to add. - protected void AddSource(ISkin skin) - { - skinSources = skinSources.Append((skin, new DisableableSkinSource(skin, this))).ToArray(); - - if (skin is ISkinSource source) - source.SourceChanged += TriggerSourceChanged; - } - - /// - /// Clears all skin sources. - /// - protected void ResetSources() + /// The new sources. + protected void SetSources(IEnumerable 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; + } } /// - /// Invoked when any source has changed (either or a source registered via ). + /// Invoked when any source has changed (either or sources replaced via ). /// This is also invoked once initially during to ensure sources are ready for children consumption. /// protected virtual void OnSourceChanged() { }