mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Add database-based configuration for rulesets
This commit is contained in:
42
osu.Game/Configuration/SettingsStore.cs
Normal file
42
osu.Game/Configuration/SettingsStore.cs
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Game.Database;
|
||||
|
||||
namespace osu.Game.Configuration
|
||||
{
|
||||
public class SettingsStore : DatabaseBackedStore
|
||||
{
|
||||
public event Action SettingChanged;
|
||||
|
||||
public SettingsStore(Func<OsuDbContext> createContext)
|
||||
: base(createContext)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve <see cref="DatabasedSetting"/>s for a specified ruleset/variant content.
|
||||
/// </summary>
|
||||
/// <param name="rulesetId">The ruleset's internal ID.</param>
|
||||
/// <param name="variant">An optional variant.</param>
|
||||
/// <returns></returns>
|
||||
public List<DatabasedSetting> Query(int? rulesetId = null) =>
|
||||
GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList();
|
||||
|
||||
public void Update(Setting setting)
|
||||
{
|
||||
var dbSetting = (DatabasedSetting)setting;
|
||||
|
||||
var context = GetContext();
|
||||
|
||||
Refresh(ref dbSetting);
|
||||
dbSetting.Value = setting.Value;
|
||||
context.SaveChanges();
|
||||
|
||||
SettingChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user