Make ruleset id non-nullable

This commit is contained in:
Dean Herbert
2021-09-15 17:01:31 +09:00
parent 80ecf81be3
commit dcfe9c67e3
3 changed files with 14 additions and 8 deletions

View File

@ -13,7 +13,8 @@ namespace osu.Game.Configuration
[PrimaryKey] [PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid(); public Guid ID { get; set; } = Guid.NewGuid();
public int? RulesetID { get; set; } [Indexed]
public int RulesetID { get; set; }
public int? Variant { get; set; } public int? Variant { get; set; }

View File

@ -458,11 +458,13 @@ namespace osu.Game
{ {
foreach (var dkb in existingSettings) foreach (var dkb in existingSettings)
{ {
if (dkb.RulesetID == null) continue;
usage.Realm.Add(new RealmRulesetSetting usage.Realm.Add(new RealmRulesetSetting
{ {
ValueString = dkb.StringValue, ValueString = dkb.StringValue,
Key = dkb.Key, Key = dkb.Key,
RulesetID = dkb.RulesetID, RulesetID = dkb.RulesetID.Value,
Variant = dkb.Variant Variant = dkb.Variant
}); });
} }

View File

@ -20,12 +20,17 @@ namespace osu.Game.Rulesets.Configuration
private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>(); private List<RealmRulesetSetting> databasedSettings = new List<RealmRulesetSetting>();
private readonly RulesetInfo ruleset; private readonly int rulesetId;
protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null) protected RulesetConfigManager(SettingsStore store, RulesetInfo ruleset, int? variant = null)
{ {
realmFactory = store?.Realm; realmFactory = store?.Realm;
this.ruleset = ruleset;
if (realmFactory != null && !ruleset.ID.HasValue)
throw new InvalidOperationException("Attempted to add databased settings for a non-databased ruleset");
rulesetId = ruleset.ID ?? -1;
this.variant = variant; this.variant = variant;
Load(); Load();
@ -35,12 +40,10 @@ namespace osu.Game.Rulesets.Configuration
protected override void PerformLoad() protected override void PerformLoad()
{ {
var rulesetID = ruleset?.ID;
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.RulesetID == rulesetId && b.Variant == variant).ToList();
} }
} }
@ -66,7 +69,7 @@ namespace osu.Game.Rulesets.Configuration
{ {
Key = lookup.ToString(), Key = lookup.ToString(),
Value = bindable.Value, Value = bindable.Value,
RulesetID = ruleset?.ID, RulesetID = rulesetId,
Variant = variant, Variant = variant,
}; };