mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 16:02:55 +08:00
Load json from disk store at skin construction for now
This allows for easier mutation without worrying about changes being re-read from disk unexpectedly.
This commit is contained in:
parent
1bb3c609ae
commit
c957293ec3
@ -44,6 +44,32 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
// may be null for default skin.
|
// may be null for default skin.
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
if (fileInfo == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var bytes = resources?.Files.Get(fileInfo.FileInfo.StoragePath);
|
||||||
|
|
||||||
|
if (bytes == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string jsonContent = Encoding.UTF8.GetString(bytes);
|
||||||
|
|
||||||
|
DrawableComponentInfo[skinnableTarget] = JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetDrawableTarget(SkinnableElementTargetContainer targetContainer)
|
||||||
|
{
|
||||||
|
DrawableComponentInfo.Remove(targetContainer.Target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDrawableTarget(SkinnableElementTargetContainer targetContainer)
|
public void UpdateDrawableTarget(SkinnableElementTargetContainer targetContainer)
|
||||||
@ -60,34 +86,9 @@ namespace osu.Game.Skinning
|
|||||||
var skinnableTarget = target.Target;
|
var skinnableTarget = target.Target;
|
||||||
|
|
||||||
if (!DrawableComponentInfo.TryGetValue(skinnableTarget, out var skinnableInfo))
|
if (!DrawableComponentInfo.TryGetValue(skinnableTarget, out var skinnableInfo))
|
||||||
{
|
|
||||||
switch (skinnableTarget)
|
|
||||||
{
|
|
||||||
case SkinnableTarget.MainHUDComponents:
|
|
||||||
|
|
||||||
// skininfo files may be null for default skin.
|
|
||||||
var fileInfo = SkinInfo.Files?.FirstOrDefault(f => f.Filename == $"{skinnableTarget}.json");
|
|
||||||
|
|
||||||
if (fileInfo == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var bytes = resources?.Files.Get(fileInfo.FileInfo.StoragePath);
|
|
||||||
|
|
||||||
if (bytes == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
string jsonContent = Encoding.UTF8.GetString(bytes);
|
|
||||||
|
|
||||||
DrawableComponentInfo[skinnableTarget] = skinnableInfo =
|
|
||||||
JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent).Where(i => i.Target == SkinnableTarget.MainHUDComponents).ToArray();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skinnableInfo == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new SkinnableTargetWrapper(skinnableTarget)
|
return new SkinnableTargetWrapper
|
||||||
{
|
{
|
||||||
ChildrenEnumerable = skinnableInfo.Select(i => i.CreateInstance())
|
ChildrenEnumerable = skinnableInfo.Select(i => i.CreateInstance())
|
||||||
};
|
};
|
||||||
@ -123,15 +124,10 @@ namespace osu.Game.Skinning
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SkinnableTargetWrapper : Container, IDefaultSkinnableTarget
|
public class SkinnableTargetWrapper : Container, ISkinnableComponent
|
||||||
{
|
{
|
||||||
// this is just here to implement the interface and allow a silly parent lookup to work (where the target is not the direct parent for reasons).
|
public SkinnableTargetWrapper()
|
||||||
// TODO: need to fix this.
|
|
||||||
public SkinnableTarget Target { get; }
|
|
||||||
|
|
||||||
public SkinnableTargetWrapper(SkinnableTarget target)
|
|
||||||
{
|
{
|
||||||
Target = target;
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user