mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 12:45:09 +08:00
Use ILive
for Skin.SkinInfo
This commit is contained in:
parent
cd0c811ab1
commit
6b55de2845
@ -15,6 +15,7 @@ using osu.Framework.Graphics.OpenGL.Textures;
|
|||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
@ -23,7 +24,7 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
public abstract class Skin : IDisposable, ISkin
|
public abstract class Skin : IDisposable, ISkin
|
||||||
{
|
{
|
||||||
public readonly SkinInfo SkinInfo;
|
public readonly ILive<SkinInfo> SkinInfo;
|
||||||
private readonly IStorageResourceProvider resources;
|
private readonly IStorageResourceProvider resources;
|
||||||
|
|
||||||
public SkinConfiguration Configuration { get; set; }
|
public SkinConfiguration Configuration { get; set; }
|
||||||
@ -42,7 +43,7 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null)
|
protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null)
|
||||||
{
|
{
|
||||||
SkinInfo = skin;
|
SkinInfo = skin.ToLive();
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
|
|
||||||
configurationStream ??= getConfigurationStream();
|
configurationStream ??= getConfigurationStream();
|
||||||
@ -53,37 +54,41 @@ namespace osu.Game.Skinning
|
|||||||
else
|
else
|
||||||
Configuration = new SkinConfiguration();
|
Configuration = new SkinConfiguration();
|
||||||
|
|
||||||
// we may want to move this to some kind of async operation in the future.
|
// skininfo files may be null for default skin.
|
||||||
foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
|
SkinInfo.PerformRead(s =>
|
||||||
{
|
{
|
||||||
string filename = $"{skinnableTarget}.json";
|
// we may want to move this to some kind of async operation in the future.
|
||||||
|
foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
|
||||||
// skininfo files may be null for default skin.
|
|
||||||
var fileInfo = SkinInfo.Files.FirstOrDefault(f => f.Filename == filename);
|
|
||||||
|
|
||||||
if (fileInfo == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
byte[] bytes = resources?.Files.Get(fileInfo.File.GetStoragePath());
|
|
||||||
|
|
||||||
if (bytes == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string jsonContent = Encoding.UTF8.GetString(bytes);
|
string filename = $"{skinnableTarget}.json";
|
||||||
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent);
|
|
||||||
|
|
||||||
if (deserializedContent == null)
|
// skininfo files may be null for default skin.
|
||||||
|
var fileInfo = s.Files.FirstOrDefault(f => f.Filename == filename);
|
||||||
|
|
||||||
|
if (fileInfo == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray();
|
byte[] bytes = resources?.Files.Get(fileInfo.File.GetStoragePath());
|
||||||
|
|
||||||
|
if (bytes == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string jsonContent = Encoding.UTF8.GetString(bytes);
|
||||||
|
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent);
|
||||||
|
|
||||||
|
if (deserializedContent == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error(ex, "Failed to load skin configuration.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
});
|
||||||
{
|
|
||||||
Logger.Error(ex, "Failed to load skin configuration.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ParseConfigurationStream(Stream stream)
|
protected virtual void ParseConfigurationStream(Stream stream)
|
||||||
@ -94,7 +99,7 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private Stream getConfigurationStream()
|
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))
|
if (string.IsNullOrEmpty(path))
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user