mirror of
https://github.com/ppy/osu
synced 2025-02-22 21:47:12 +00:00
Switch realm ruleset configuration to use ruleset's ShortName
as key
This commit is contained in:
parent
ca26b6c540
commit
329bae50b0
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Game.Database;
|
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
@ -10,13 +8,10 @@ using Realms;
|
|||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
{
|
{
|
||||||
[MapTo(@"RulesetSetting")]
|
[MapTo(@"RulesetSetting")]
|
||||||
public class RealmRulesetSetting : RealmObject, IHasGuidPrimaryKey
|
public class RealmRulesetSetting : RealmObject
|
||||||
{
|
{
|
||||||
[PrimaryKey]
|
|
||||||
public Guid ID { get; set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public int RulesetID { get; set; }
|
public string RulesetName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public int Variant { get; set; }
|
public int Variant { get; set; }
|
||||||
|
@ -11,6 +11,7 @@ using osu.Framework.Input.Bindings;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Statistics;
|
using osu.Framework.Statistics;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Models;
|
using osu.Game.Models;
|
||||||
using osu.Game.Rulesets;
|
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.
|
/// 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.
|
/// 8 2021-10-29 Rebind scroll adjust keys to not have control modifier.
|
||||||
/// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser.
|
/// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser.
|
||||||
|
/// 10 2021-11-22 Use ShortName instead of RulesetID for ruleset settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int schema_version = 9;
|
private const int schema_version = 10;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
|
/// 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,8 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
Key = dkb.Key,
|
Key = dkb.Key,
|
||||||
Value = dkb.StringValue,
|
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,
|
Variant = dkb.Variant ?? 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,13 @@ namespace osu.Game.Rulesets.Configuration
|
|||||||
|
|
||||||
private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>();
|
private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>();
|
||||||
|
|
||||||
private readonly int rulesetId;
|
private readonly string rulesetName;
|
||||||
|
|
||||||
protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null)
|
protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null)
|
||||||
{
|
{
|
||||||
realmFactory = store?.Realm;
|
realmFactory = store?.Realm;
|
||||||
|
|
||||||
if (realmFactory != null && !ruleset.ID.HasValue)
|
rulesetName = ruleset.ShortName;
|
||||||
throw new InvalidOperationException("Attempted to add databased settings for a non-databased ruleset");
|
|
||||||
|
|
||||||
rulesetId = ruleset.ID ?? -1;
|
|
||||||
|
|
||||||
this.variant = variant ?? 0;
|
this.variant = variant ?? 0;
|
||||||
|
|
||||||
@ -43,7 +40,7 @@ namespace osu.Game.Rulesets.Configuration
|
|||||||
if (realmFactory != null)
|
if (realmFactory != null)
|
||||||
{
|
{
|
||||||
// As long as RulesetConfigCache exists, there is no need to subscribe to realm events.
|
// 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)
|
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();
|
setting.Value = ConfigStore[c].ToString();
|
||||||
}
|
}
|
||||||
@ -94,7 +91,7 @@ namespace osu.Game.Rulesets.Configuration
|
|||||||
{
|
{
|
||||||
Key = lookup.ToString(),
|
Key = lookup.ToString(),
|
||||||
Value = bindable.Value.ToString(),
|
Value = bindable.Value.ToString(),
|
||||||
RulesetID = rulesetId,
|
RulesetName = rulesetName,
|
||||||
Variant = variant,
|
Variant = variant,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user