Combine Setting and DatabasedSetting

This commit is contained in:
Dean Herbert 2018-01-24 17:59:49 +09:00
parent 5a00ae36d1
commit 29e98a58f2
3 changed files with 24 additions and 47 deletions

View File

@ -7,7 +7,7 @@
namespace osu.Game.Configuration
{
[Table("Settings")]
public class DatabasedSetting : Setting, IHasPrimaryKey
public class DatabasedSetting : IHasPrimaryKey
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
@ -27,5 +27,23 @@ public string StringValue
get => Value.ToString();
set => Value = value;
}
public object Key;
public object Value;
public DatabasedSetting(object key, object value)
{
Key = key;
Value = value;
}
/// <summary>
/// Constructor for derived classes that may require serialisation.
/// </summary>
public DatabasedSetting()
{
}
public override string ToString() => $"{Key}=>{Value}";
}
}

View File

@ -1,41 +1 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Configuration
{
/// <summary>
/// A binding of a <see cref="Bindings.KeyCombination"/> to an action.
/// </summary>
public class Setting
{
/// <summary>
/// The combination of keys which will trigger this binding.
/// </summary>
public object Key;
/// <summary>
/// The resultant action which is triggered by this binding.
/// </summary>
public object Value;
/// <summary>
/// Construct a new instance.
/// </summary>
/// <param name="key">The combination of keys which will trigger this binding.</param>
/// <param name="action">The resultant action which is triggered by this binding. Usually an enum type.</param>
public Setting(object key, object value)
{
Key = key;
Value = value;
}
/// <summary>
/// Constructor for derived classes that may require serialisation.
/// </summary>
public Setting()
{
}
public override string ToString() => $"{Key}=>{Value}";
}
}


View File

@ -26,14 +26,13 @@ public SettingsStore(Func<OsuDbContext> createContext)
public List<DatabasedSetting> Query(int? rulesetId = null) =>
GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList();
public void Update(Setting setting)
public void Update(DatabasedSetting setting)
{
var dbSetting = (DatabasedSetting)setting;
var context = GetContext();
Refresh(ref dbSetting);
dbSetting.Value = setting.Value;
Refresh(ref setting);
setting.Value = setting.Value;
context.SaveChanges();
SettingChanged?.Invoke();