// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // 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 osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Extensions; using osu.Game.IO.Serialization; using osu.Game.Skinning; using osuTK; namespace osu.Game.Screens.Play.HUD { /// /// Serialised information governing custom changes to an . /// [Serializable] public class SkinnableInfo : IJsonSerializable { public Type Type { get; set; } public Vector2 Position { get; set; } public float Rotation { get; set; } public Vector2 Scale { get; set; } public Anchor Anchor { get; set; } public Anchor Origin { get; set; } /// public bool OverridesClosestAnchor { get; set; } public List Children { get; } = new List(); [JsonConstructor] public SkinnableInfo() { } /// /// Construct a new instance populating all attributes from the provided drawable. /// /// The drawable which attributes should be sourced from. public SkinnableInfo(Drawable component) { Type = component.GetType(); Position = component.Position; Rotation = component.Rotation; Scale = component.Scale; Anchor = component.Anchor; Origin = component.Origin; if (component is ISkinnableDrawable skinnable) OverridesClosestAnchor = skinnable.OverridesClosestAnchor; if (component is Container container) { foreach (var child in container.OfType().OfType()) Children.Add(child.CreateSkinnableInfo()); } } /// /// Construct an instance of the drawable with all attributes applied. /// /// The new instance. public Drawable CreateInstance() { Drawable d = (Drawable)Activator.CreateInstance(Type); d.ApplySkinnableInfo(this); return d; } } }