mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Combine Setting and DatabasedSetting
This commit is contained in:
parent
5a00ae36d1
commit
29e98a58f2
@ -7,7 +7,7 @@ using osu.Game.Database;
|
|||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
{
|
{
|
||||||
[Table("Settings")]
|
[Table("Settings")]
|
||||||
public class DatabasedSetting : Setting, IHasPrimaryKey
|
public class DatabasedSetting : IHasPrimaryKey
|
||||||
{
|
{
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
@ -27,5 +27,23 @@ namespace osu.Game.Configuration
|
|||||||
get => Value.ToString();
|
get => Value.ToString();
|
||||||
set => Value = value;
|
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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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}";
|
|
||||||
}
|
|
||||||
}
|
|
@ -26,14 +26,13 @@ namespace osu.Game.Configuration
|
|||||||
public List<DatabasedSetting> Query(int? rulesetId = null) =>
|
public List<DatabasedSetting> Query(int? rulesetId = null) =>
|
||||||
GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList();
|
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();
|
var context = GetContext();
|
||||||
|
|
||||||
Refresh(ref dbSetting);
|
Refresh(ref setting);
|
||||||
dbSetting.Value = setting.Value;
|
|
||||||
|
setting.Value = setting.Value;
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
SettingChanged?.Invoke();
|
SettingChanged?.Invoke();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user