1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 18:43:22 +08:00

Migrate combo counter layouts in custom skins to correct target-ruleset pairs

This commit is contained in:
Salman Ahmed 2024-06-25 04:24:58 +03:00
parent e8de293be5
commit 78e0126f16
5 changed files with 57 additions and 1 deletions

View File

@ -93,8 +93,9 @@ namespace osu.Game.Database
/// 39 2023-12-19 Migrate any EndTimeObjectCount and TotalObjectCount values of 0 to -1 to better identify non-calculated values.
/// 40 2023-12-21 Add ScoreInfo.Version to keep track of which build scores were set on.
/// 41 2024-04-17 Add ScoreInfo.TotalScoreWithoutMods for future mod multiplier rebalances.
/// 42 2024-06-25 Add SkinInfo.LayoutVersion to allow performing migrations of components on structural changes.
/// </summary>
private const int schema_version = 41;
private const int schema_version = 42;
/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.

View File

@ -12,6 +12,7 @@ using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
using osu.Game.Extensions;
using osu.Game.IO;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
@ -69,6 +70,24 @@ namespace osu.Game.Skinning
// Purple
new Color4(92, 0, 241, 255),
};
if (skin.LayoutVersion < 20240625
&& LayoutInfos.TryGetValue(SkinComponentsContainerLookup.TargetArea.MainHUDComponents, out var hudLayout)
&& hudLayout.TryGetDrawableInfo(null, out var hudComponents))
{
var comboCounters = hudComponents.Where(h => h.Type.Name == nameof(ArgonComboCounter)).ToArray();
if (comboCounters.Any())
{
hudLayout.Update(null, hudComponents.Except(comboCounters).ToArray());
resources.RealmAccess.Run(r =>
{
foreach (var ruleset in r.All<RulesetInfo>())
hudLayout.Update(ruleset, comboCounters);
});
}
}
}
public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Textures?.Get(componentName, wrapModeS, wrapModeT);

View File

@ -19,6 +19,7 @@ using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
using osu.Game.Extensions;
using osu.Game.IO;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
@ -56,6 +57,24 @@ namespace osu.Game.Skinning
protected LegacySkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? fallbackStore, string configurationFilename = @"skin.ini")
: base(skin, resources, fallbackStore, configurationFilename)
{
if (resources != null
&& skin.LayoutVersion < 20240625
&& LayoutInfos.TryGetValue(SkinComponentsContainerLookup.TargetArea.MainHUDComponents, out var hudLayout)
&& hudLayout.TryGetDrawableInfo(null, out var hudComponents))
{
var comboCounters = hudComponents.Where(h => h.Type.Name == nameof(LegacyComboCounter)).ToArray();
if (comboCounters.Any())
{
hudLayout.Update(null, hudComponents.Except(comboCounters).ToArray());
resources.RealmAccess.Run(r =>
{
foreach (var ruleset in r.All<RulesetInfo>())
hudLayout.Update(ruleset, comboCounters);
});
}
}
}
protected override IResourceStore<TextureUpload> CreateTextureLoaderStore(IStorageResourceProvider resources, IResourceStore<byte[]> storage)

View File

@ -223,6 +223,8 @@ namespace osu.Game.Skinning
}
}
s.LayoutVersion = SkinInfo.LATEST_LAYOUT_VERSION;
string newHash = ComputeHash(s);
hadChanges = newHash != s.Hash;

View File

@ -39,6 +39,21 @@ namespace osu.Game.Skinning
public bool Protected { get; set; }
/// <summary>
/// The latest version in YYYYMMDD format for skin layout migrations.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item><description>20240625: Moves combo counters from ruleset-agnostic to ruleset-specific HUD targets.</description></item>
/// </list>
/// </remarks>
public const int LATEST_LAYOUT_VERSION = 20240625;
/// <summary>
/// A version in YYYYMMDD format for applying skin layout migrations.
/// </summary>
public int LayoutVersion { get; set; }
public virtual Skin CreateInstance(IStorageResourceProvider resources)
{
var type = string.IsNullOrEmpty(InstantiationInfo)