mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Add basic support for child serialisation
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
@ -54,6 +55,12 @@ namespace osu.Game.Extensions
|
|||||||
component.Rotation = info.Rotation;
|
component.Rotation = info.Rotation;
|
||||||
component.Scale = info.Scale;
|
component.Scale = info.Scale;
|
||||||
component.Anchor = info.Anchor;
|
component.Anchor = info.Anchor;
|
||||||
|
|
||||||
|
if (component is Container container)
|
||||||
|
{
|
||||||
|
foreach (var child in info.Children)
|
||||||
|
container.Add(child.CreateInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.IO.Serialization;
|
using osu.Game.IO.Serialization;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -18,6 +21,21 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class SkinnableInfo : IJsonSerializable
|
public class SkinnableInfo : IJsonSerializable
|
||||||
{
|
{
|
||||||
|
public Type Type { get; set; }
|
||||||
|
|
||||||
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
public SkinnableTarget? Target { get; set; }
|
||||||
|
|
||||||
|
public Vector2 Position { get; set; }
|
||||||
|
|
||||||
|
public float Rotation { get; set; }
|
||||||
|
|
||||||
|
public Vector2 Scale { get; set; }
|
||||||
|
|
||||||
|
public Anchor Anchor { get; set; }
|
||||||
|
|
||||||
|
public List<SkinnableInfo> Children { get; } = new List<SkinnableInfo>();
|
||||||
|
|
||||||
public SkinnableInfo()
|
public SkinnableInfo()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -34,21 +52,14 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Rotation = component.Rotation;
|
Rotation = component.Rotation;
|
||||||
Scale = component.Scale;
|
Scale = component.Scale;
|
||||||
Anchor = component.Anchor;
|
Anchor = component.Anchor;
|
||||||
|
|
||||||
|
if (component is Container container)
|
||||||
|
{
|
||||||
|
foreach (var child in container.Children.OfType<ISkinnableComponent>().OfType<Drawable>())
|
||||||
|
Children.Add(child.CreateSerialisedInformation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type Type { get; set; }
|
|
||||||
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
|
||||||
public SkinnableTarget? Target { get; set; }
|
|
||||||
|
|
||||||
public Vector2 Position { get; set; }
|
|
||||||
|
|
||||||
public float Rotation { get; set; }
|
|
||||||
|
|
||||||
public Vector2 Scale { get; set; }
|
|
||||||
|
|
||||||
public Anchor Anchor { get; set; }
|
|
||||||
|
|
||||||
public Drawable CreateInstance()
|
public Drawable CreateInstance()
|
||||||
{
|
{
|
||||||
Drawable d = (Drawable)Activator.CreateInstance(Type);
|
Drawable d = (Drawable)Activator.CreateInstance(Type);
|
||||||
|
Reference in New Issue
Block a user