1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 13:22:55 +08:00

Use ILive for Skin.SkinInfo

This commit is contained in:
Dean Herbert 2021-11-29 18:02:09 +09:00
parent cd0c811ab1
commit 6b55de2845

View File

@ -15,6 +15,7 @@ using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
using osu.Game.Audio;
using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.IO;
using osu.Game.Screens.Play.HUD;
@ -23,7 +24,7 @@ namespace osu.Game.Skinning
{
public abstract class Skin : IDisposable, ISkin
{
public readonly SkinInfo SkinInfo;
public readonly ILive<SkinInfo> SkinInfo;
private readonly IStorageResourceProvider resources;
public SkinConfiguration Configuration { get; set; }
@ -42,7 +43,7 @@ namespace osu.Game.Skinning
protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null)
{
SkinInfo = skin;
SkinInfo = skin.ToLive();
this.resources = resources;
configurationStream ??= getConfigurationStream();
@ -53,13 +54,16 @@ namespace osu.Game.Skinning
else
Configuration = new SkinConfiguration();
// skininfo files may be null for default skin.
SkinInfo.PerformRead(s =>
{
// we may want to move this to some kind of async operation in the future.
foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
{
string filename = $"{skinnableTarget}.json";
// skininfo files may be null for default skin.
var fileInfo = SkinInfo.Files.FirstOrDefault(f => f.Filename == filename);
var fileInfo = s.Files.FirstOrDefault(f => f.Filename == filename);
if (fileInfo == null)
continue;
@ -84,6 +88,7 @@ namespace osu.Game.Skinning
Logger.Error(ex, "Failed to load skin configuration.");
}
}
});
}
protected virtual void ParseConfigurationStream(Stream stream)
@ -94,7 +99,7 @@ namespace osu.Game.Skinning
private Stream getConfigurationStream()
{
string path = SkinInfo.Files.SingleOrDefault(f => f.Filename.Equals(@"skin.ini", StringComparison.OrdinalIgnoreCase))?.File.GetStoragePath();
string path = SkinInfo.PerformRead(s => s.Files.SingleOrDefault(f => f.Filename.Equals(@"skin.ini", StringComparison.OrdinalIgnoreCase))?.File.GetStoragePath());
if (string.IsNullOrEmpty(path))
return null;