2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Configuration
|
|
|
|
|
{
|
|
|
|
|
public abstract class DatabasedConfigManager<T> : ConfigManager<T>
|
|
|
|
|
where T : struct
|
|
|
|
|
{
|
|
|
|
|
private readonly SettingsStore settings;
|
|
|
|
|
|
2018-06-11 12:13:36 +08:00
|
|
|
|
private readonly int? variant;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private readonly List<DatabasedSetting> databasedSettings;
|
|
|
|
|
|
|
|
|
|
private readonly RulesetInfo ruleset;
|
|
|
|
|
|
2018-06-11 12:13:36 +08:00
|
|
|
|
protected DatabasedConfigManager(SettingsStore settings, RulesetInfo ruleset = null, int? variant = null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.settings = settings;
|
|
|
|
|
this.ruleset = ruleset;
|
|
|
|
|
this.variant = variant;
|
|
|
|
|
|
|
|
|
|
databasedSettings = settings.Query(ruleset?.ID, variant);
|
|
|
|
|
|
|
|
|
|
InitialiseDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PerformLoad()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool PerformSave()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AddBindable<TBindable>(T lookup, Bindable<TBindable> bindable)
|
|
|
|
|
{
|
|
|
|
|
base.AddBindable(lookup, bindable);
|
|
|
|
|
|
2019-01-06 00:35:33 +08:00
|
|
|
|
var setting = databasedSettings.Find(s => (int)s.Key == (int)(object)lookup);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (setting != null)
|
|
|
|
|
{
|
|
|
|
|
bindable.Parse(setting.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
settings.Update(setting = new DatabasedSetting
|
|
|
|
|
{
|
|
|
|
|
Key = lookup,
|
|
|
|
|
Value = bindable.Value,
|
|
|
|
|
RulesetID = ruleset?.ID,
|
|
|
|
|
Variant = variant,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
databasedSettings.Add(setting);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
bindable.ValueChanged += b =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
setting.Value = b.NewValue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
settings.Update(setting);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|