From 9e651a7ca26f48eb9a95d770a29fb6bd680173f8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Feb 2023 15:36:18 +0900 Subject: [PATCH] Rename `SkinnableInfo` to `SkinnableDrawableInfo` --- .../Skins/SkinDeserialisationTest.cs | 2 +- .../Gameplay/TestSceneBeatmapSkinFallbacks.cs | 16 +++++++-------- osu.Game/Extensions/DrawableExtensions.cs | 20 +++++++++---------- .../SkinEditor/SkinComponentToolbox.cs | 2 +- .../SkinEditor/SkinEditorChangeHandler.cs | 4 ++-- osu.Game/Skinning/ISkinnableTarget.cs | 4 ++-- osu.Game/Skinning/LegacyComboCounter.cs | 2 +- ...nnableInfo.cs => SkinnableDrawableInfo.cs} | 8 ++++---- osu.Game/Skinning/SkinnableTargetContainer.cs | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) rename osu.Game/Skinning/{SkinnableInfo.cs => SkinnableDrawableInfo.cs} (93%) diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs index 3bab91bd9c..16cae1d34f 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 = SkinnableInfo.GetAllAvailableDrawables().Where(t => (Activator.CreateInstance(t) as ISkinnableDrawable)?.IsEditable == true); + var editableTypes = SkinnableDrawableInfo.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 615bf609dc..8318f70e8f 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs @@ -90,15 +90,15 @@ namespace osu.Game.Tests.Visual.Gameplay return almostEqual(actualInfo, expectedInfo); } - private static bool almostEqual(SkinnableInfo info, SkinnableInfo? other) => + private static bool almostEqual(SkinnableDrawableInfo drawableInfo, SkinnableDrawableInfo? other) => other != null - && info.Type == other.Type - && info.Anchor == other.Anchor - && info.Origin == other.Origin - && Precision.AlmostEquals(info.Position, other.Position, 1) - && Precision.AlmostEquals(info.Scale, other.Scale) - && Precision.AlmostEquals(info.Rotation, other.Rotation) - && info.Children.SequenceEqual(other.Children, new FuncEqualityComparer(almostEqual)); + && drawableInfo.Type == other.Type + && drawableInfo.Anchor == other.Anchor + && drawableInfo.Origin == other.Origin + && 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)); 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 021745e5e1..c590d4fa31 100644 --- a/osu.Game/Extensions/DrawableExtensions.cs +++ b/osu.Game/Extensions/DrawableExtensions.cs @@ -48,26 +48,26 @@ namespace osu.Game.Extensions public static Vector2 ScreenSpaceDeltaToParentSpace(this Drawable drawable, Vector2 delta) => drawable.Parent.ToLocalSpace(drawable.Parent.ToScreenSpace(Vector2.Zero) + delta); - public static SkinnableInfo CreateSkinnableInfo(this Drawable component) => new SkinnableInfo(component); + public static SkinnableDrawableInfo CreateSkinnableInfo(this Drawable component) => new SkinnableDrawableInfo(component); - public static void ApplySkinnableInfo(this Drawable component, SkinnableInfo info) + public static void ApplySkinnableInfo(this Drawable component, SkinnableDrawableInfo drawableInfo) { // todo: can probably make this better via deserialisation directly using a common interface. - component.Position = info.Position; - component.Rotation = info.Rotation; - component.Scale = info.Scale; - component.Anchor = info.Anchor; - component.Origin = info.Origin; + component.Position = drawableInfo.Position; + component.Rotation = drawableInfo.Rotation; + component.Scale = drawableInfo.Scale; + component.Anchor = drawableInfo.Anchor; + component.Origin = drawableInfo.Origin; if (component is ISkinnableDrawable skinnable) { - skinnable.UsesFixedAnchor = info.UsesFixedAnchor; + skinnable.UsesFixedAnchor = drawableInfo.UsesFixedAnchor; foreach (var (_, property) in component.GetSettingsSourceProperties()) { var bindable = ((IBindable)property.GetValue(component)!); - if (!info.Settings.TryGetValue(property.Name.ToSnakeCase(), out object? settingValue)) + if (!drawableInfo.Settings.TryGetValue(property.Name.ToSnakeCase(), out object? settingValue)) { // TODO: We probably want to restore default if not included in serialisation information. // This is not simple to do as SetDefault() is only found in the typed Bindable interface right now. @@ -80,7 +80,7 @@ namespace osu.Game.Extensions if (component is Container container) { - foreach (var child in info.Children) + foreach (var child in drawableInfo.Children) container.Add(child.CreateInstance()); } } diff --git a/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs b/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs index 3298c267f3..37bc7df4fa 100644 --- a/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs +++ b/osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs @@ -48,7 +48,7 @@ namespace osu.Game.Overlays.SkinEditor { fill.Clear(); - var skinnableTypes = SkinnableInfo.GetAllAvailableDrawables(); + var skinnableTypes = SkinnableDrawableInfo.GetAllAvailableDrawables(target?.Ruleset); foreach (var type in skinnableTypes) attemptAddComponent(type); } diff --git a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs index 41b6b24da1..2d519d3489 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs @@ -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; - SkinnableInfo[] skinnableInfo = deserializedContent.ToArray(); + SkinnableDrawableInfo[] skinnableInfo = deserializedContent.ToArray(); Drawable[] targetComponents = firstTarget.Components.OfType().ToArray(); if (!skinnableInfo.Select(s => s.Type).SequenceEqual(targetComponents.Select(d => d.GetType()))) diff --git a/osu.Game/Skinning/ISkinnableTarget.cs b/osu.Game/Skinning/ISkinnableTarget.cs index 6429d116dd..4610851216 100644 --- a/osu.Game/Skinning/ISkinnableTarget.cs +++ b/osu.Game/Skinning/ISkinnableTarget.cs @@ -29,7 +29,7 @@ namespace osu.Game.Skinning /// Serialise all children as . /// /// The serialised content. - IEnumerable CreateSkinnableInfo() => Components.Select(d => ((Drawable)d).CreateSkinnableInfo()); + IEnumerable CreateSkinnableInfo() => Components.Select(d => ((Drawable)d).CreateSkinnableInfo()); /// /// Reload this target from the current skin. @@ -39,7 +39,7 @@ namespace osu.Game.Skinning /// /// Reload this target from the provided skinnable information. /// - void Reload(SkinnableInfo[] skinnableInfo); + void Reload(SkinnableDrawableInfo[] skinnableInfo); /// /// Add a new skinnable component to this target. diff --git a/osu.Game/Skinning/LegacyComboCounter.cs b/osu.Game/Skinning/LegacyComboCounter.cs index 1de13841fe..c03386266b 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/SkinnableInfo.cs b/osu.Game/Skinning/SkinnableDrawableInfo.cs similarity index 93% rename from osu.Game/Skinning/SkinnableInfo.cs rename to osu.Game/Skinning/SkinnableDrawableInfo.cs index 96aaed667e..5e30f94ac6 100644 --- a/osu.Game/Skinning/SkinnableInfo.cs +++ b/osu.Game/Skinning/SkinnableDrawableInfo.cs @@ -22,7 +22,7 @@ namespace osu.Game.Skinning /// Serialised information governing custom changes to an . /// [Serializable] - public class SkinnableInfo + public sealed class SkinnableDrawableInfo { public Type Type { get; set; } @@ -41,10 +41,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 SkinnableInfo() + public SkinnableDrawableInfo() { } @@ -52,7 +52,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 SkinnableInfo(Drawable component) + public SkinnableDrawableInfo(Drawable component) { Type = component.GetType(); diff --git a/osu.Game/Skinning/SkinnableTargetContainer.cs b/osu.Game/Skinning/SkinnableTargetContainer.cs index cbc719cef5..586462cb8c 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(SkinnableInfo[] skinnableInfo) + public void Reload(SkinnableDrawableInfo[] skinnableInfo) { var drawables = new List();