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)
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
var dependencies = base.CreateChildDependencies(parent);
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
UpdateSkinSources();
return dependencies;
return base.CreateChildDependencies(parent);
}
protected override void OnSourceChanged()
{
UpdateSkinSources();
base.OnSourceChanged();
}
protected virtual void UpdateSkinSources()
{
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);
@ -82,26 +72,26 @@ protected virtual void UpdateSkinSources()
switch (skin)
{
case LegacySkin legacySkin:
skinSources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
sources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
break;
default:
skinSources.Add(skin);
sources.Add(skin);
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
// This is achieved by placing them before the last instance of DefaultSkin.
// Note that DefaultSkin may not be present in some test scenes.
if (lastDefaultSkinIndex >= 0)
skinSources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
sources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
else
skinSources.Add(rulesetResourcesSkin);
sources.Add(rulesetResourcesSkin);
foreach (var skin in skinSources)
foreach (var skin in sources)
AddSource(skin);
}

View File

@ -64,6 +64,10 @@ protected SkinProvidingContainer()
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)
{
skinSources.Add(skin, new DisableableSkinSource(skin, this));
@ -72,14 +76,22 @@ protected void AddSource(ISkin skin)
source.SourceChanged += anySourceChanged;
}
/// <summary>
/// Remove a skin from this provider.
/// </summary>
/// <param name="skin">The skin to remove.</param>
protected void RemoveSource(ISkin skin)
{
skinSources.Remove(skin);
if (!skinSources.Remove(skin))
return;
if (skin is ISkinSource source)
source.SourceChanged += anySourceChanged;
source.SourceChanged -= anySourceChanged;
}
/// <summary>
/// Clears all skin sources.
/// </summary>
protected void ResetSources()
{
foreach (var skin in AllSources.ToArray())
@ -176,7 +188,8 @@ public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
}
/// <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>
protected virtual void OnSourceChanged() { }
@ -190,6 +203,8 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
dependencies.CacheAs<ISkinSource>(this);
anySourceChanged();
return dependencies;
}