From 856efd9fd9d04e312e77030d9740e738e1355b95 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Feb 2023 15:47:41 +0900 Subject: [PATCH] Rename `SkinnableDrawableInfo` to `SerialisedDrawableInfo` --- osu.Game.Tests/Skins/SkinDeserialisationTest.cs | 2 +- .../Gameplay/TestSceneBeatmapSkinFallbacks.cs | 8 ++++---- osu.Game/Extensions/DrawableExtensions.cs | 4 ++-- .../Overlays/SkinEditor/SkinComponentToolbox.cs | 3 ++- .../Overlays/SkinEditor/SkinEditorChangeHandler.cs | 8 ++++---- osu.Game/Skinning/ISkinnableDrawable.cs | 6 ++++-- osu.Game/Skinning/ISkinnableTarget.cs | 7 +++---- osu.Game/Skinning/LegacyComboCounter.cs | 2 +- ...bleDrawableInfo.cs => SerialisedDrawableInfo.cs} | 13 ++++++------- osu.Game/Skinning/Skin.cs | 9 ++++----- osu.Game/Skinning/SkinnableTargetContainer.cs | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) rename osu.Game/Skinning/{SkinnableDrawableInfo.cs => SerialisedDrawableInfo.cs} (89%) diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs index 16cae1d34f..c782fbd084 100644 --- a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs +++ b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs @@ -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)); } diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs index 8318f70e8f..5005cff265 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs @@ -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(almostEqual)); + && drawableInfo.Children.SequenceEqual(other.Children, new FuncEqualityComparer(almostEqual)); protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard? storyboard = null) => new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, Audio, currentBeatmapSkin); diff --git a/osu.Game/Extensions/DrawableExtensions.cs b/osu.Game/Extensions/DrawableExtensions.cs index c590d4fa31..cc561cebc4 100644 --- a/osu.Game/Extensions/DrawableExtensions.cs +++ b/osu.Game/Extensions/DrawableExtensions.cs @@ -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; diff --git a/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs b/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs index 37bc7df4fa..2f3fd8b5e5 100644 --- a/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs +++ b/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs @@ -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); } diff --git a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs index 2d519d3489..77032589a0 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs @@ -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>(Encoding.UTF8.GetString(newState)); + var deserializedContent = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(newState)); if (deserializedContent == null) return; - SkinnableDrawableInfo[] skinnableInfo = deserializedContent.ToArray(); + SerialisedDrawableInfo[] skinnableInfo = deserializedContent.ToArray(); Drawable[] targetComponents = firstTarget.Components.OfType().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++]); } } } diff --git a/osu.Game/Skinning/ISkinnableDrawable.cs b/osu.Game/Skinning/ISkinnableDrawable.cs index 1ecd6f967e..5ec2fa0f43 100644 --- a/osu.Game/Skinning/ISkinnableDrawable.cs +++ b/osu.Game/Skinning/ISkinnableDrawable.cs @@ -13,8 +13,10 @@ namespace osu.Game.Skinning /// Denotes a drawable which, as a drawable, can be adjusted via skinning specifications. /// /// - /// Attaching this interface to any will make it serialisable to skin settings. - /// Adding annotated bindables will also serialise these settings alongside each instance. + /// Attaching this interface to any will make it serialisable to user skins (see ). + /// Adding annotated bindables will also allow serialising settings automatically. + /// + /// Serialisation is done via using . /// public interface ISkinnableDrawable : IDrawable { diff --git a/osu.Game/Skinning/ISkinnableTarget.cs b/osu.Game/Skinning/ISkinnableTarget.cs index 4610851216..e10fc6e069 100644 --- a/osu.Game/Skinning/ISkinnableTarget.cs +++ b/osu.Game/Skinning/ISkinnableTarget.cs @@ -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 Components { get; } /// - /// Serialise all children as . + /// Serialise all children as . /// /// The serialised content. - IEnumerable CreateSkinnableInfo() => Components.Select(d => ((Drawable)d).CreateSkinnableInfo()); + IEnumerable CreateSerialisedInfo() => Components.Select(d => ((Drawable)d).CreateSerialisedInfo()); /// /// Reload this target from the current skin. @@ -39,7 +38,7 @@ namespace osu.Game.Skinning /// /// Reload this target from the provided skinnable information. /// - void Reload(SkinnableDrawableInfo[] skinnableInfo); + void Reload(SerialisedDrawableInfo[] skinnableInfo); /// /// Add a new skinnable component to this target. diff --git a/osu.Game/Skinning/LegacyComboCounter.cs b/osu.Game/Skinning/LegacyComboCounter.cs index c03386266b..f46f5a69f0 100644 --- a/osu.Game/Skinning/LegacyComboCounter.cs +++ b/osu.Game/Skinning/LegacyComboCounter.cs @@ -44,7 +44,7 @@ namespace osu.Game.Skinning private readonly Container counterContainer; /// - /// Hides the combo counter internally without affecting its . + /// Hides the combo counter internally without affecting its . /// /// /// This is used for rulesets that provide their own combo counter and don't want this HUD one to be visible, diff --git a/osu.Game/Skinning/SkinnableDrawableInfo.cs b/osu.Game/Skinning/SerialisedDrawableInfo.cs similarity index 89% rename from osu.Game/Skinning/SkinnableDrawableInfo.cs rename to osu.Game/Skinning/SerialisedDrawableInfo.cs index 5e30f94ac6..8bcfed1dbc 100644 --- a/osu.Game/Skinning/SkinnableDrawableInfo.cs +++ b/osu.Game/Skinning/SerialisedDrawableInfo.cs @@ -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 . /// [Serializable] - public sealed class SkinnableDrawableInfo + public sealed class SerialisedDrawableInfo { public Type Type { get; set; } @@ -41,10 +40,10 @@ namespace osu.Game.Skinning public Dictionary Settings { get; set; } = new Dictionary(); - public List Children { get; } = new List(); + public List Children { get; } = new List(); [JsonConstructor] - public SkinnableDrawableInfo() + public SerialisedDrawableInfo() { } @@ -52,7 +51,7 @@ namespace osu.Game.Skinning /// Construct a new instance populating all attributes from the provided drawable. /// /// The drawable which attributes should be sourced from. - public SkinnableDrawableInfo(Drawable component) + public SerialisedDrawableInfo(Drawable component) { Type = component.GetType(); @@ -75,7 +74,7 @@ namespace osu.Game.Skinning if (component is Container container) { foreach (var child in container.OfType().OfType()) - 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) diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index c55b4e789c..44bdcafe4c 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -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 DrawableComponentInfo => drawableComponentInfo; + public IDictionary DrawableComponentInfo => drawableComponentInfo; - private readonly Dictionary drawableComponentInfo = new Dictionary(); + private readonly Dictionary drawableComponentInfo = new Dictionary(); 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>(jsonContent); + var deserializedContent = JsonConvert.DeserializeObject>(jsonContent); if (deserializedContent == null) continue; @@ -155,7 +154,7 @@ namespace osu.Game.Skinning /// The target container to serialise to this skin. public void UpdateDrawableTarget(ISkinnableTarget targetContainer) { - DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSkinnableInfo().ToArray(); + DrawableComponentInfo[targetContainer.Target] = targetContainer.CreateSerialisedInfo().ToArray(); } public virtual Drawable? GetDrawableComponent(ISkinComponentLookup lookup) diff --git a/osu.Game/Skinning/SkinnableTargetContainer.cs b/osu.Game/Skinning/SkinnableTargetContainer.cs index 586462cb8c..8b37767113 100644 --- a/osu.Game/Skinning/SkinnableTargetContainer.cs +++ b/osu.Game/Skinning/SkinnableTargetContainer.cs @@ -33,7 +33,7 @@ namespace osu.Game.Skinning Target = target; } - public void Reload(SkinnableDrawableInfo[] skinnableInfo) + public void Reload(SerialisedDrawableInfo[] skinnableInfo) { var drawables = new List();