mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge remote-tracking branch 'upstream/master' into databased-sin-setting
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Rulesets;
|
||||
@ -19,6 +20,8 @@ namespace osu.Game.Configuration
|
||||
|
||||
private readonly RulesetInfo ruleset;
|
||||
|
||||
private readonly bool legacySettingsExist;
|
||||
|
||||
protected DatabasedConfigManager(SettingsStore settings, RulesetInfo ruleset = null, int? variant = null)
|
||||
{
|
||||
this.settings = settings;
|
||||
@ -26,6 +29,7 @@ namespace osu.Game.Configuration
|
||||
this.variant = variant;
|
||||
|
||||
databasedSettings = settings.Query(ruleset?.ID, variant);
|
||||
legacySettingsExist = databasedSettings.Any(s => int.TryParse(s.Key, out var _));
|
||||
|
||||
InitialiseDefaults();
|
||||
}
|
||||
@ -43,7 +47,18 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
base.AddBindable(lookup, bindable);
|
||||
|
||||
var setting = databasedSettings.Find(s => (int)s.Key == (int)(object)lookup);
|
||||
if (legacySettingsExist)
|
||||
{
|
||||
var legacySetting = databasedSettings.Find(s => s.Key == ((int)(object)lookup).ToString());
|
||||
|
||||
if (legacySetting != null)
|
||||
{
|
||||
bindable.Parse(legacySetting.Value);
|
||||
settings.Delete(legacySetting);
|
||||
}
|
||||
}
|
||||
|
||||
var setting = databasedSettings.Find(s => s.Key == lookup.ToString());
|
||||
|
||||
if (setting != null)
|
||||
{
|
||||
@ -53,7 +68,7 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
settings.Update(setting = new DatabasedSetting
|
||||
{
|
||||
Key = lookup,
|
||||
Key = lookup.ToString(),
|
||||
Value = bindable.Value,
|
||||
RulesetID = ruleset?.ID,
|
||||
Variant = variant,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// 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.
|
||||
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -18,11 +18,7 @@ namespace osu.Game.Configuration
|
||||
public int? SkinInfoID { get; set; }
|
||||
|
||||
[Column("Key")]
|
||||
public int IntKey
|
||||
{
|
||||
get => (int)Key;
|
||||
private set => Key = value;
|
||||
}
|
||||
public string Key { get; set; }
|
||||
|
||||
[Column("Value")]
|
||||
public string StringValue
|
||||
@ -31,10 +27,9 @@ namespace osu.Game.Configuration
|
||||
set => Value = value;
|
||||
}
|
||||
|
||||
public object Key;
|
||||
public object Value;
|
||||
|
||||
public DatabasedSetting(object key, object value)
|
||||
public DatabasedSetting(string key, object value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
|
@ -37,5 +37,11 @@ namespace osu.Game.Configuration
|
||||
|
||||
SettingChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void Delete(DatabasedSetting setting)
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
usage.Context.Remove(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user