1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 10:22:56 +08:00

Maintain ruleset resources skin across multiple source changes

This commit is contained in:
Salman Ahmed 2021-06-28 09:11:28 +03:00
parent f777741ca7
commit 692f24437e

View File

@ -46,21 +46,20 @@ namespace osu.Game.Skinning
}; };
} }
[Resolved]
private GameHost host { get; set; }
[Resolved]
private AudioManager audio { get; set; }
[Resolved] [Resolved]
private SkinManager skinManager { get; set; } private SkinManager skinManager { get; set; }
[Resolved] [Resolved]
private ISkinSource skinSource { get; set; } private ISkinSource skinSource { get; set; }
private ResourcesSkin rulesetResourcesSkin;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(GameHost host, AudioManager audio)
{ {
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
rulesetResourcesSkin = new ResourcesSkin(resources, host, audio);
UpdateSkins(); UpdateSkins();
skinSource.SourceChanged += OnSourceChanged; skinSource.SourceChanged += OnSourceChanged;
} }
@ -73,9 +72,6 @@ namespace osu.Game.Skinning
protected virtual void UpdateSkins() protected virtual void UpdateSkins()
{ {
foreach (var resourcesSkin in SkinSources.OfType<ResourcesSkin>())
resourcesSkin.Dispose();
SkinSources.Clear(); SkinSources.Clear();
foreach (var skin in skinSource.AllSources) foreach (var skin in skinSource.AllSources)
@ -92,20 +88,12 @@ namespace osu.Game.Skinning
} }
} }
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources) int defaultSkinIndex = SkinSources.IndexOf(skinManager.DefaultSkin);
{
int defaultSkinIndex = SkinSources.IndexOf(skinManager.DefaultSkin);
var rulesetResources = new ResourcesSkin(resources, host, audio); if (defaultSkinIndex >= 0)
SkinSources.Insert(defaultSkinIndex, rulesetResourcesSkin);
if (defaultSkinIndex >= 0) else
SkinSources.Insert(defaultSkinIndex, rulesetResources); SkinSources.Add(rulesetResourcesSkin);
else
{
// Tests may potentially override the SkinManager with another source that doesn't include it in AllSources.
SkinSources.Add(rulesetResources);
}
}
} }
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin) protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)
@ -126,6 +114,8 @@ namespace osu.Game.Skinning
if (skinSource != null) if (skinSource != null)
skinSource.SourceChanged -= OnSourceChanged; skinSource.SourceChanged -= OnSourceChanged;
rulesetResourcesSkin?.Dispose();
} }
} }
} }