From 35d2f973a39b533ed1cb7392d31d1d8299e9b0c9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 22 Mar 2022 19:07:05 +0900 Subject: [PATCH] Prefer provided resource store over realm backed to keep tests working --- osu.Game/Skinning/LegacySkin.cs | 2 +- osu.Game/Skinning/Skin.cs | 39 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 5533615568..84844c4502 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -69,7 +69,7 @@ protected LegacySkin(SkinInfo skin, [CanBeNull] IResourceStore storage, /// Access to raw game resources. /// An optional stream containing the contents of a skin.ini file. protected LegacySkin(SkinInfo skin, [CanBeNull] IResourceStore storage, [CanBeNull] IStorageResourceProvider resources, [CanBeNull] Stream configurationStream) - : base(skin, resources, configurationStream) + : base(skin, resources, storage, configurationStream) { // todo: this shouldn't really be duplicated here (from ManiaLegacySkinTransformer). we need to come up with a better solution. hasKeyTexture = new Lazy(() => this.GetAnimation( diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index d1ea7aa300..a47da70cd6 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -13,6 +13,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; using osu.Framework.Logging; using osu.Game.Audio; using osu.Game.Database; @@ -51,30 +52,36 @@ public abstract class Skin : IDisposable, ISkin public abstract IBindable GetConfig(TLookup lookup); - private readonly RealmBackedResourceStore skinStorage; - - protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null) + protected Skin(SkinInfo skin, [CanBeNull] IStorageResourceProvider resources, [CanBeNull] IResourceStore storage = null, [CanBeNull] Stream configurationStream = null) { - if (resources.RealmAccess != null) + if (resources != null) { - SkinInfo = skin.ToLive(resources.RealmAccess); - skinStorage = new RealmBackedResourceStore(skin, resources.Files); + if (resources.RealmAccess != null) + { + SkinInfo = skin.ToLive(resources.RealmAccess); - var samples = resources?.AudioManager?.GetSampleStore(skinStorage); + if (storage == null) + { + var realmStorage = new RealmBackedResourceStore(skin, resources.Files); + realmStorage.AddExtension("ogg"); + + storage = realmStorage; + } + } + else + { + SkinInfo = skin.ToLiveUnmanaged(); + } + + var samples = resources.AudioManager?.GetSampleStore(storage); if (samples != null) samples.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY; Samples = samples; - Textures = new TextureStore(resources?.CreateTextureLoaderStore(skinStorage)); - - skinStorage.AddExtension("ogg"); - } - else - { - SkinInfo = skin.ToLiveUnmanaged(); + Textures = new TextureStore(resources.CreateTextureLoaderStore(storage)); } - configurationStream ??= skinStorage?.GetStream(@"skin.ini"); + configurationStream ??= storage?.GetStream(@"skin.ini"); if (configurationStream != null) // stream will be closed after use by LineBufferedReader. @@ -87,7 +94,7 @@ protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] St { string filename = $"{skinnableTarget}.json"; - byte[] bytes = skinStorage?.Get(filename); + byte[] bytes = storage?.Get(filename); if (bytes == null) continue;