Rename SkinnableDrawableInfo to SerialisedDrawableInfo

This commit is contained in:
Dean Herbert
2023-02-15 15:47:41 +09:00
parent 9e651a7ca2
commit 856efd9fd9
11 changed files with 32 additions and 32 deletions

View File

@ -74,7 +74,7 @@ namespace osu.Game.Tests.Skins
} }
} }
var editableTypes = SkinnableDrawableInfo.GetAllAvailableDrawables().Where(t => (Activator.CreateInstance(t) as ISkinnableDrawable)?.IsEditable == true); var editableTypes = SerialisedDrawableInfo.GetAllAvailableDrawables().Where(t => (Activator.CreateInstance(t) as ISkinnableDrawable)?.IsEditable == true);
Assert.That(instantiatedTypes, Is.EquivalentTo(editableTypes)); Assert.That(instantiatedTypes, Is.EquivalentTo(editableTypes));
} }

View File

@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual.Gameplay
if (actualComponentsContainer == null) if (actualComponentsContainer == null)
return false; return false;
var actualInfo = actualComponentsContainer.CreateSkinnableInfo(); var actualInfo = actualComponentsContainer.CreateSerialisedInfo();
var expectedComponentsContainer = expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target)) as Container; var expectedComponentsContainer = expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target)) as Container;
if (expectedComponentsContainer == null) if (expectedComponentsContainer == null)
@ -84,13 +84,13 @@ namespace osu.Game.Tests.Visual.Gameplay
Add(expectedComponentsAdjustmentContainer); Add(expectedComponentsAdjustmentContainer);
expectedComponentsAdjustmentContainer.UpdateSubTree(); expectedComponentsAdjustmentContainer.UpdateSubTree();
var expectedInfo = expectedComponentsContainer.CreateSkinnableInfo(); var expectedInfo = expectedComponentsContainer.CreateSerialisedInfo();
Remove(expectedComponentsAdjustmentContainer, true); Remove(expectedComponentsAdjustmentContainer, true);
return almostEqual(actualInfo, expectedInfo); return almostEqual(actualInfo, expectedInfo);
} }
private static bool almostEqual(SkinnableDrawableInfo drawableInfo, SkinnableDrawableInfo? other) => private static bool almostEqual(SerialisedDrawableInfo drawableInfo, SerialisedDrawableInfo? other) =>
other != null other != null
&& drawableInfo.Type == other.Type && drawableInfo.Type == other.Type
&& drawableInfo.Anchor == other.Anchor && drawableInfo.Anchor == other.Anchor
@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual.Gameplay
&& Precision.AlmostEquals(drawableInfo.Position, other.Position, 1) && Precision.AlmostEquals(drawableInfo.Position, other.Position, 1)
&& Precision.AlmostEquals(drawableInfo.Scale, other.Scale) && Precision.AlmostEquals(drawableInfo.Scale, other.Scale)
&& Precision.AlmostEquals(drawableInfo.Rotation, other.Rotation) && Precision.AlmostEquals(drawableInfo.Rotation, other.Rotation)
&& drawableInfo.Children.SequenceEqual(other.Children, new FuncEqualityComparer<SkinnableDrawableInfo>(almostEqual)); && drawableInfo.Children.SequenceEqual(other.Children, new FuncEqualityComparer<SerialisedDrawableInfo>(almostEqual));
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard? storyboard = null) protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard? storyboard = null)
=> new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, Audio, currentBeatmapSkin); => new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, Audio, currentBeatmapSkin);

View File

@ -48,9 +48,9 @@ namespace osu.Game.Extensions
public static Vector2 ScreenSpaceDeltaToParentSpace(this Drawable drawable, Vector2 delta) => public static Vector2 ScreenSpaceDeltaToParentSpace(this Drawable drawable, Vector2 delta) =>
drawable.Parent.ToLocalSpace(drawable.Parent.ToScreenSpace(Vector2.Zero) + delta); drawable.Parent.ToLocalSpace(drawable.Parent.ToScreenSpace(Vector2.Zero) + delta);
public static SkinnableDrawableInfo CreateSkinnableInfo(this Drawable component) => new SkinnableDrawableInfo(component); public static SerialisedDrawableInfo CreateSerialisedInfo(this Drawable component) => new SerialisedDrawableInfo(component);
public static void ApplySkinnableInfo(this Drawable component, SkinnableDrawableInfo drawableInfo) public static void ApplySerialisedInfo(this Drawable component, SerialisedDrawableInfo drawableInfo)
{ {
// todo: can probably make this better via deserialisation directly using a common interface. // todo: can probably make this better via deserialisation directly using a common interface.
component.Position = drawableInfo.Position; component.Position = drawableInfo.Position;

View File

@ -10,6 +10,7 @@ using osu.Framework.Logging;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Screens.Edit.Components; using osu.Game.Screens.Edit.Components;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
@ -48,7 +49,7 @@ namespace osu.Game.Overlays.SkinEditor
{ {
fill.Clear(); fill.Clear();
var skinnableTypes = SkinnableDrawableInfo.GetAllAvailableDrawables(target?.Ruleset); var skinnableTypes = SerialisedDrawableInfo.GetAllAvailableDrawables();
foreach (var type in skinnableTypes) foreach (var type in skinnableTypes)
attemptAddComponent(type); attemptAddComponent(type);
} }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Overlays.SkinEditor
if (firstTarget == null) if (firstTarget == null)
return; return;
var skinnableInfos = firstTarget.CreateSkinnableInfo().ToArray(); var skinnableInfos = firstTarget.CreateSerialisedInfo().ToArray();
string json = JsonConvert.SerializeObject(skinnableInfos, new JsonSerializerSettings { Formatting = Formatting.Indented }); string json = JsonConvert.SerializeObject(skinnableInfos, new JsonSerializerSettings { Formatting = Formatting.Indented });
stream.Write(Encoding.UTF8.GetBytes(json)); stream.Write(Encoding.UTF8.GetBytes(json));
} }
@ -52,12 +52,12 @@ namespace osu.Game.Overlays.SkinEditor
if (firstTarget == null) if (firstTarget == null)
return; return;
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableDrawableInfo>>(Encoding.UTF8.GetString(newState)); var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SerialisedDrawableInfo>>(Encoding.UTF8.GetString(newState));
if (deserializedContent == null) if (deserializedContent == null)
return; return;
SkinnableDrawableInfo[] skinnableInfo = deserializedContent.ToArray(); SerialisedDrawableInfo[] skinnableInfo = deserializedContent.ToArray();
Drawable[] targetComponents = firstTarget.Components.OfType<Drawable>().ToArray(); Drawable[] targetComponents = firstTarget.Components.OfType<Drawable>().ToArray();
if (!skinnableInfo.Select(s => s.Type).SequenceEqual(targetComponents.Select(d => d.GetType()))) if (!skinnableInfo.Select(s => s.Type).SequenceEqual(targetComponents.Select(d => d.GetType())))
@ -70,7 +70,7 @@ namespace osu.Game.Overlays.SkinEditor
int i = 0; int i = 0;
foreach (var drawable in targetComponents) foreach (var drawable in targetComponents)
drawable.ApplySkinnableInfo(skinnableInfo[i++]); drawable.ApplySerialisedInfo(skinnableInfo[i++]);
} }
} }
} }

View File

@ -13,8 +13,10 @@ namespace osu.Game.Skinning
/// Denotes a drawable which, as a drawable, can be adjusted via skinning specifications. /// Denotes a drawable which, as a drawable, can be adjusted via skinning specifications.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Attaching this interface to any <see cref="IDrawable"/> will make it serialisable to skin settings. /// Attaching this interface to any <see cref="IDrawable"/> will make it serialisable to user skins (see <see cref="SkinImporter.Save"/>).
/// Adding <see cref="SettingSourceAttribute"/> annotated bindables will also serialise these settings alongside each instance. /// Adding <see cref="SettingSourceAttribute"/> annotated bindables will also allow serialising settings automatically.
///
/// Serialisation is done via <see cref="SerialisedDrawableInfo"/> using <see cref="Extensions.DrawableExtensions.CreateSerialisedInfo"/>.
/// </remarks> /// </remarks>
public interface ISkinnableDrawable : IDrawable public interface ISkinnableDrawable : IDrawable
{ {

View File

@ -6,7 +6,6 @@ using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Rulesets;
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
@ -26,10 +25,10 @@ namespace osu.Game.Skinning
IBindableList<ISkinnableDrawable> Components { get; } IBindableList<ISkinnableDrawable> Components { get; }
/// <summary> /// <summary>
/// Serialise all children as <see cref="SkinnableInfo"/>. /// Serialise all children as <see cref="SerialisedDrawableInfo"/>.
/// </summary> /// </summary>
/// <returns>The serialised content.</returns> /// <returns>The serialised content.</returns>
IEnumerable<SkinnableDrawableInfo> CreateSkinnableInfo() => Components.Select(d => ((Drawable)d).CreateSkinnableInfo()); IEnumerable<SerialisedDrawableInfo> CreateSerialisedInfo() => Components.Select(d => ((Drawable)d).CreateSerialisedInfo());
/// <summary> /// <summary>
/// Reload this target from the current skin. /// Reload this target from the current skin.
@ -39,7 +38,7 @@ namespace osu.Game.Skinning
/// <summary> /// <summary>
/// Reload this target from the provided skinnable information. /// Reload this target from the provided skinnable information.
/// </summary> /// </summary>
void Reload(SkinnableDrawableInfo[] skinnableInfo); void Reload(SerialisedDrawableInfo[] skinnableInfo);
/// <summary> /// <summary>
/// Add a new skinnable component to this target. /// Add a new skinnable component to this target.

View File

@ -44,7 +44,7 @@ namespace osu.Game.Skinning
private readonly Container counterContainer; private readonly Container counterContainer;
/// <summary> /// <summary>
/// Hides the combo counter internally without affecting its <see cref="SkinnableDrawableInfo"/>. /// Hides the combo counter internally without affecting its <see cref="SerialisedDrawableInfo"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This is used for rulesets that provide their own combo counter and don't want this HUD one to be visible, /// This is used for rulesets that provide their own combo counter and don't want this HUD one to be visible,

View File

@ -13,7 +13,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Rulesets;
using osuTK; using osuTK;
namespace osu.Game.Skinning namespace osu.Game.Skinning
@ -22,7 +21,7 @@ namespace osu.Game.Skinning
/// Serialised information governing custom changes to an <see cref="ISkinnableDrawable"/>. /// Serialised information governing custom changes to an <see cref="ISkinnableDrawable"/>.
/// </summary> /// </summary>
[Serializable] [Serializable]
public sealed class SkinnableDrawableInfo public sealed class SerialisedDrawableInfo
{ {
public Type Type { get; set; } public Type Type { get; set; }
@ -41,10 +40,10 @@ namespace osu.Game.Skinning
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>(); public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
public List<SkinnableDrawableInfo> Children { get; } = new List<SkinnableDrawableInfo>(); public List<SerialisedDrawableInfo> Children { get; } = new List<SerialisedDrawableInfo>();
[JsonConstructor] [JsonConstructor]
public SkinnableDrawableInfo() public SerialisedDrawableInfo()
{ {
} }
@ -52,7 +51,7 @@ namespace osu.Game.Skinning
/// Construct a new instance populating all attributes from the provided drawable. /// Construct a new instance populating all attributes from the provided drawable.
/// </summary> /// </summary>
/// <param name="component">The drawable which attributes should be sourced from.</param> /// <param name="component">The drawable which attributes should be sourced from.</param>
public SkinnableDrawableInfo(Drawable component) public SerialisedDrawableInfo(Drawable component)
{ {
Type = component.GetType(); Type = component.GetType();
@ -75,7 +74,7 @@ namespace osu.Game.Skinning
if (component is Container<Drawable> container) if (component is Container<Drawable> container)
{ {
foreach (var child in container.OfType<ISkinnableDrawable>().OfType<Drawable>()) foreach (var child in container.OfType<ISkinnableDrawable>().OfType<Drawable>())
Children.Add(child.CreateSkinnableInfo()); Children.Add(child.CreateSerialisedInfo());
} }
} }
@ -88,7 +87,7 @@ namespace osu.Game.Skinning
try try
{ {
Drawable d = (Drawable)Activator.CreateInstance(Type)!; Drawable d = (Drawable)Activator.CreateInstance(Type)!;
d.ApplySkinnableInfo(this); d.ApplySerialisedInfo(this);
return d; return d;
} }
catch (Exception e) catch (Exception e)

View File

@ -18,7 +18,6 @@ using osu.Framework.Logging;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
@ -38,9 +37,9 @@ namespace osu.Game.Skinning
public SkinConfiguration Configuration { get; set; } public SkinConfiguration Configuration { get; set; }
public IDictionary<GlobalSkinComponentLookup.LookupType, SkinnableInfo[]> DrawableComponentInfo => drawableComponentInfo; public IDictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]> DrawableComponentInfo => drawableComponentInfo;
private readonly Dictionary<GlobalSkinComponentLookup.LookupType, SkinnableInfo[]> drawableComponentInfo = new Dictionary<GlobalSkinComponentLookup.LookupType, SkinnableInfo[]>(); private readonly Dictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]> drawableComponentInfo = new Dictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]>();
public abstract ISample? GetSample(ISampleInfo sampleInfo); public abstract ISample? GetSample(ISampleInfo sampleInfo);
@ -120,7 +119,7 @@ namespace osu.Game.Skinning
jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.SongProgress", @"osu.Game.Screens.Play.HUD.DefaultSongProgress"); jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.SongProgress", @"osu.Game.Screens.Play.HUD.DefaultSongProgress");
jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.HUD.LegacyComboCounter", @"osu.Game.Skinning.LegacyComboCounter"); jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.HUD.LegacyComboCounter", @"osu.Game.Skinning.LegacyComboCounter");
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent); var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SerialisedDrawableInfo>>(jsonContent);
if (deserializedContent == null) if (deserializedContent == null)
continue; continue;
@ -155,7 +154,7 @@ namespace osu.Game.Skinning
/// <param name="targetContainer">The target container to serialise to this skin.</param> /// <param name="targetContainer">The target container to serialise to this skin.</param>
public void UpdateDrawableTarget(ISkinnableTarget targetContainer) public void UpdateDrawableTarget(ISkinnableTarget targetContainer)
{ {
DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSkinnableInfo().ToArray(); DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSerialisedInfo().ToArray();
} }
public virtual Drawable? GetDrawableComponent(ISkinComponentLookup lookup) public virtual Drawable? GetDrawableComponent(ISkinComponentLookup lookup)

View File

@ -33,7 +33,7 @@ namespace osu.Game.Skinning
Target = target; Target = target;
} }
public void Reload(SkinnableDrawableInfo[] skinnableInfo) public void Reload(SerialisedDrawableInfo[] skinnableInfo)
{ {
var drawables = new List<Drawable>(); var drawables = new List<Drawable>();