Add xmldoc and remove any question of how the intitial flow is being run

This commit is contained in:
Dean Herbert 2021-07-06 17:18:45 +09:00
parent 032c285ede
commit cd4885e450
2 changed files with 27 additions and 22 deletions

View File

@ -55,25 +55,15 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources) if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>()); rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
var dependencies = base.CreateChildDependencies(parent); return base.CreateChildDependencies(parent);
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
UpdateSkinSources();
return dependencies;
} }
protected override void OnSourceChanged() protected override void OnSourceChanged()
{
UpdateSkinSources();
base.OnSourceChanged();
}
protected virtual void UpdateSkinSources()
{ {
ResetSources(); ResetSources();
var skinSources = new List<ISkin>(); // Populate a local list first so we can adjust the returned order as we go.
var sources = new List<ISkin>();
Debug.Assert(ParentSource != null); Debug.Assert(ParentSource != null);
@ -82,26 +72,26 @@ protected virtual void UpdateSkinSources()
switch (skin) switch (skin)
{ {
case LegacySkin legacySkin: case LegacySkin legacySkin:
skinSources.Add(GetLegacyRulesetTransformedSkin(legacySkin)); sources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
break; break;
default: default:
skinSources.Add(skin); sources.Add(skin);
break; break;
} }
} }
int lastDefaultSkinIndex = skinSources.IndexOf(skinSources.OfType<DefaultSkin>().LastOrDefault()); int lastDefaultSkinIndex = sources.IndexOf(sources.OfType<DefaultSkin>().LastOrDefault());
// Ruleset resources should be given the ability to override game-wide defaults // Ruleset resources should be given the ability to override game-wide defaults
// This is achieved by placing them before the last instance of DefaultSkin. // This is achieved by placing them before the last instance of DefaultSkin.
// Note that DefaultSkin may not be present in some test scenes. // Note that DefaultSkin may not be present in some test scenes.
if (lastDefaultSkinIndex >= 0) if (lastDefaultSkinIndex >= 0)
skinSources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin); sources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
else else
skinSources.Add(rulesetResourcesSkin); sources.Add(rulesetResourcesSkin);
foreach (var skin in skinSources) foreach (var skin in sources)
AddSource(skin); AddSource(skin);
} }

View File

@ -64,6 +64,10 @@ protected SkinProvidingContainer()
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
/// <summary>
/// Add a new skin to this provider. Will be added to the end of the lookup order precedence.
/// </summary>
/// <param name="skin">The skin to add.</param>
protected void AddSource(ISkin skin) protected void AddSource(ISkin skin)
{ {
skinSources.Add(skin, new DisableableSkinSource(skin, this)); skinSources.Add(skin, new DisableableSkinSource(skin, this));
@ -72,14 +76,22 @@ protected void AddSource(ISkin skin)
source.SourceChanged += anySourceChanged; source.SourceChanged += anySourceChanged;
} }
/// <summary>
/// Remove a skin from this provider.
/// </summary>
/// <param name="skin">The skin to remove.</param>
protected void RemoveSource(ISkin skin) protected void RemoveSource(ISkin skin)
{ {
skinSources.Remove(skin); if (!skinSources.Remove(skin))
return;
if (skin is ISkinSource source) if (skin is ISkinSource source)
source.SourceChanged += anySourceChanged; source.SourceChanged -= anySourceChanged;
} }
/// <summary>
/// Clears all skin sources.
/// </summary>
protected void ResetSources() protected void ResetSources()
{ {
foreach (var skin in AllSources.ToArray()) foreach (var skin in AllSources.ToArray())
@ -176,7 +188,8 @@ public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
} }
/// <summary> /// <summary>
/// Invoked when any source has changed (either <see cref="ParentSource"/> or <see cref="AllSources"/> /// Invoked when any source has changed (either <see cref="ParentSource"/> or a source registered via <see cref="AddSource"/>).
/// 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() { }
@ -190,6 +203,8 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
dependencies.CacheAs<ISkinSource>(this); dependencies.CacheAs<ISkinSource>(this);
anySourceChanged();
return dependencies; return dependencies;
} }