1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Switch realm ruleset configuration to use ruleset's ShortName as key

This commit is contained in:
Dean Herbert 2021-11-22 18:07:28 +09:00
parent ca26b6c540
commit 329bae50b0
4 changed files with 34 additions and 17 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Database;
using Realms;
#nullable enable
@ -10,13 +8,10 @@ using Realms;
namespace osu.Game.Configuration
{
[MapTo(@"RulesetSetting")]
public class RealmRulesetSetting : RealmObject, IHasGuidPrimaryKey
public class RealmRulesetSetting : RealmObject
{
[PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid();
[Indexed]
public int RulesetID { get; set; }
public string RulesetName { get; set; } = string.Empty;
[Indexed]
public int Variant { get; set; }

View File

@ -11,6 +11,7 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Statistics;
using osu.Game.Configuration;
using osu.Game.Input.Bindings;
using osu.Game.Models;
using osu.Game.Rulesets;
@ -40,8 +41,9 @@ namespace osu.Game.Database
/// 7 2021-10-18 Changed OnlineID fields to non-nullable to add indexing support.
/// 8 2021-10-29 Rebind scroll adjust keys to not have control modifier.
/// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser.
/// 10 2021-11-22 Use ShortName instead of RulesetID for ruleset settings.
/// </summary>
private const int schema_version = 9;
private const int schema_version = 10;
/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
@ -236,6 +238,28 @@ namespace osu.Game.Database
};
}
break;
case 10:
string rulesetSettingClassName = getMappedOrOriginalName(typeof(RealmRulesetSetting));
var oldSettings = migration.OldRealm.DynamicApi.All(rulesetSettingClassName);
var newSettings = migration.NewRealm.All<RealmRulesetSetting>().ToList();
for (int i = 0; i < newSettings.Count; i++)
{
dynamic? oldItem = oldSettings.ElementAt(i);
var newItem = newSettings.ElementAt(i);
long rulesetId = oldItem.RulesetID;
string? rulesetName = rulesets?.GetRuleset((int)rulesetId)?.ShortName;
if (string.IsNullOrEmpty(rulesetName))
migration.NewRealm.Remove(newItem);
else
newItem.RulesetName = rulesetName;
}
break;
}
}

View File

@ -456,7 +456,8 @@ namespace osu.Game
{
Key = dkb.Key,
Value = dkb.StringValue,
RulesetID = dkb.RulesetID.Value,
// important: this RulesetStore must be the EF one.
RulesetName = RulesetStore.GetRuleset(dkb.RulesetID.Value).ShortName,
Variant = dkb.Variant ?? 0,
});
}

View File

@ -20,16 +20,13 @@ namespace osu.Game.Rulesets.Configuration
private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>();
private readonly int rulesetId;
private readonly string rulesetName;
protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null)
{
realmFactory = store?.Realm;
if (realmFactory != null && !ruleset.ID.HasValue)
throw new InvalidOperationException("Attempted to add databased settings for a non-databased ruleset");
rulesetId = ruleset.ID ?? -1;
rulesetName = ruleset.ShortName;
this.variant = variant ?? 0;
@ -43,7 +40,7 @@ namespace osu.Game.Rulesets.Configuration
if (realmFactory != null)
{
// As long as RulesetConfigCache exists, there is no need to subscribe to realm events.
databasedSettings = realmFactory.Context.All<RealmRulesetSetting>().Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList();
databasedSettings = realmFactory.Context.All<RealmRulesetSetting>().Where(b => b.RulesetName == rulesetName && b.Variant == variant).ToList();
}
}
@ -68,7 +65,7 @@ namespace osu.Game.Rulesets.Configuration
{
foreach (var c in changed)
{
var setting = realm.All<RealmRulesetSetting>().First(s => s.RulesetID == rulesetId && s.Variant == variant && s.Key == c.ToString());
var setting = realm.All<RealmRulesetSetting>().First(s => s.RulesetName == rulesetName && s.Variant == variant && s.Key == c.ToString());
setting.Value = ConfigStore[c].ToString();
}
@ -94,7 +91,7 @@ namespace osu.Game.Rulesets.Configuration
{
Key = lookup.ToString(),
Value = bindable.Value.ToString(),
RulesetID = rulesetId,
RulesetName = rulesetName,
Variant = variant,
};