1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 17:47:18 +08:00

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));
}

View File

@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual.Gameplay
if (actualComponentsContainer == null)
return false;
var actualInfo = actualComponentsContainer.CreateSkinnableInfo();
var actualInfo = actualComponentsContainer.CreateSerialisedInfo();
var expectedComponentsContainer = expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target)) as Container;
if (expectedComponentsContainer == null)
@ -84,13 +84,13 @@ namespace osu.Game.Tests.Visual.Gameplay
Add(expectedComponentsAdjustmentContainer);
expectedComponentsAdjustmentContainer.UpdateSubTree();
var expectedInfo = expectedComponentsContainer.CreateSkinnableInfo();
var expectedInfo = expectedComponentsContainer.CreateSerialisedInfo();
Remove(expectedComponentsAdjustmentContainer, true);
return almostEqual(actualInfo, expectedInfo);
}
private static bool almostEqual(SkinnableDrawableInfo drawableInfo, SkinnableDrawableInfo? other) =>
private static bool almostEqual(SerialisedDrawableInfo drawableInfo, SerialisedDrawableInfo? other) =>
other != null
&& drawableInfo.Type == other.Type
&& drawableInfo.Anchor == other.Anchor
@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual.Gameplay
&& Precision.AlmostEquals(drawableInfo.Position, other.Position, 1)
&& Precision.AlmostEquals(drawableInfo.Scale, other.Scale)
&& 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)
=> 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) =>
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.
component.Position = drawableInfo.Position;

View File

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

View File

@ -42,7 +42,7 @@ namespace osu.Game.Overlays.SkinEditor
if (firstTarget == null)
return;
var skinnableInfos = firstTarget.CreateSkinnableInfo().ToArray();
var skinnableInfos = firstTarget.CreateSerialisedInfo().ToArray();
string json = JsonConvert.SerializeObject(skinnableInfos, new JsonSerializerSettings { Formatting = Formatting.Indented });
stream.Write(Encoding.UTF8.GetBytes(json));
}
@ -52,12 +52,12 @@ namespace osu.Game.Overlays.SkinEditor
if (firstTarget == null)
return;
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableDrawableInfo>>(Encoding.UTF8.GetString(newState));
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SerialisedDrawableInfo>>(Encoding.UTF8.GetString(newState));
if (deserializedContent == null)
return;
SkinnableDrawableInfo[] skinnableInfo = deserializedContent.ToArray();
SerialisedDrawableInfo[] skinnableInfo = deserializedContent.ToArray();
Drawable[] targetComponents = firstTarget.Components.OfType<Drawable>().ToArray();
if (!skinnableInfo.Select(s => s.Type).SequenceEqual(targetComponents.Select(d => d.GetType())))
@ -70,7 +70,7 @@ namespace osu.Game.Overlays.SkinEditor
int i = 0;
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.
/// </summary>
/// <remarks>
/// Attaching this interface to any <see cref="IDrawable"/> will make it serialisable to skin settings.
/// Adding <see cref="SettingSourceAttribute"/> annotated bindables will also serialise these settings alongside each instance.
/// 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 allow serialising settings automatically.
///
/// Serialisation is done via <see cref="SerialisedDrawableInfo"/> using <see cref="Extensions.DrawableExtensions.CreateSerialisedInfo"/>.
/// </remarks>
public interface ISkinnableDrawable : IDrawable
{

View File

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

View File

@ -44,7 +44,7 @@ namespace osu.Game.Skinning
private readonly Container counterContainer;
/// <summary>
/// Hides the combo counter internally without affecting its <see cref="SkinnableDrawableInfo"/>.
/// Hides the combo counter internally without affecting its <see cref="SerialisedDrawableInfo"/>.
/// </summary>
/// <remarks>
/// 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.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Rulesets;
using osuTK;
namespace osu.Game.Skinning
@ -22,7 +21,7 @@ namespace osu.Game.Skinning
/// Serialised information governing custom changes to an <see cref="ISkinnableDrawable"/>.
/// </summary>
[Serializable]
public sealed class SkinnableDrawableInfo
public sealed class SerialisedDrawableInfo
{
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 List<SkinnableDrawableInfo> Children { get; } = new List<SkinnableDrawableInfo>();
public List<SerialisedDrawableInfo> Children { get; } = new List<SerialisedDrawableInfo>();
[JsonConstructor]
public SkinnableDrawableInfo()
public SerialisedDrawableInfo()
{
}
@ -52,7 +51,7 @@ namespace osu.Game.Skinning
/// Construct a new instance populating all attributes from the provided drawable.
/// </summary>
/// <param name="component">The drawable which attributes should be sourced from.</param>
public SkinnableDrawableInfo(Drawable component)
public SerialisedDrawableInfo(Drawable component)
{
Type = component.GetType();
@ -75,7 +74,7 @@ namespace osu.Game.Skinning
if (component is Container<Drawable> container)
{
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
{
Drawable d = (Drawable)Activator.CreateInstance(Type)!;
d.ApplySkinnableInfo(this);
d.ApplySerialisedInfo(this);
return d;
}
catch (Exception e)

View File

@ -18,7 +18,6 @@ using osu.Framework.Logging;
using osu.Game.Audio;
using osu.Game.Database;
using osu.Game.IO;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning
{
@ -38,9 +37,9 @@ namespace osu.Game.Skinning
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);
@ -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.HUD.LegacyComboCounter", @"osu.Game.Skinning.LegacyComboCounter");
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SkinnableInfo>>(jsonContent);
var deserializedContent = JsonConvert.DeserializeObject<IEnumerable<SerialisedDrawableInfo>>(jsonContent);
if (deserializedContent == null)
continue;
@ -155,7 +154,7 @@ namespace osu.Game.Skinning
/// <param name="targetContainer">The target container to serialise to this skin.</param>
public void UpdateDrawableTarget(ISkinnableTarget targetContainer)
{
DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSkinnableInfo().ToArray();
DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSerialisedInfo().ToArray();
}
public virtual Drawable? GetDrawableComponent(ISkinComponentLookup lookup)

View File

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