From 6a88b8888b1be641d203ed598998b7f0e985c410 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 10 May 2021 22:33:45 +0900 Subject: [PATCH] Add basic support for child serialisation --- osu.Game/Extensions/DrawableExtensions.cs | 7 ++++ osu.Game/Screens/Play/HUD/SkinnableInfo.cs | 37 ++++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/osu.Game/Extensions/DrawableExtensions.cs b/osu.Game/Extensions/DrawableExtensions.cs index e84c9e5a98..6837a802f2 100644 --- a/osu.Game/Extensions/DrawableExtensions.cs +++ b/osu.Game/Extensions/DrawableExtensions.cs @@ -3,6 +3,7 @@ using System; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Framework.Threading; using osu.Game.Screens.Play.HUD; @@ -54,6 +55,12 @@ namespace osu.Game.Extensions component.Rotation = info.Rotation; component.Scale = info.Scale; component.Anchor = info.Anchor; + + if (component is Container container) + { + foreach (var child in info.Children) + container.Add(child.CreateInstance()); + } } } } diff --git a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs index 2edc99781f..ec4eaa0e59 100644 --- a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs +++ b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs @@ -2,9 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Extensions; using osu.Game.IO.Serialization; using osu.Game.Skinning; @@ -18,6 +21,21 @@ namespace osu.Game.Screens.Play.HUD [Serializable] 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 Children { get; } = new List(); + public SkinnableInfo() { } @@ -34,21 +52,14 @@ namespace osu.Game.Screens.Play.HUD Rotation = component.Rotation; Scale = component.Scale; Anchor = component.Anchor; + + if (component is Container container) + { + foreach (var child in container.Children.OfType().OfType()) + 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() { Drawable d = (Drawable)Activator.CreateInstance(Type);