Skip to content

Commit

Permalink
Migrate combo counter layouts in custom skins to correct target-rules…
Browse files Browse the repository at this point in the history
…et pairs
  • Loading branch information
frenzibyte committed Jun 25, 2024
1 parent e8de293 commit 78e0126
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public class RealmAccess : IDisposable
/// 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.
Expand Down
19 changes: 19 additions & 0 deletions osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -69,6 +70,24 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
// 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);
Expand Down
19 changes: 19 additions & 0 deletions osu.Game/Skinning/LegacySkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -56,6 +57,24 @@ public LegacySkin(SkinInfo skin, IStorageResourceProvider resources)
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)
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Skinning/SkinImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public bool Save(Skin skin)
}
}

s.LayoutVersion = SkinInfo.LATEST_LAYOUT_VERSION;

string newHash = ComputeHash(s);

hadChanges = newHash != s.Hash;
Expand Down
15 changes: 15 additions & 0 deletions osu.Game/Skinning/SkinInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public class SkinInfo : RealmObject, IHasRealmFiles, IEquatable<SkinInfo>, IHasG

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)
Expand Down

0 comments on commit 78e0126

Please sign in to comment.