mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Initial refactoring of key binding logic
This commit is contained in:
61
osu.Game/Input/KeyBindingStore.cs
Normal file
61
osu.Game/Input/KeyBindingStore.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2007-2017 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 osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input.Bindings;
|
||||
using SQLite.Net;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public class KeyBindingStore : DatabaseBackedStore
|
||||
{
|
||||
public KeyBindingStore(SQLiteConnection connection, Storage storage = null)
|
||||
: base(connection, storage)
|
||||
{
|
||||
}
|
||||
|
||||
protected override int StoreVersion => 2;
|
||||
|
||||
protected override void PerformMigration(int currentVersion, int targetVersion)
|
||||
{
|
||||
base.PerformMigration(currentVersion, targetVersion);
|
||||
|
||||
while (currentVersion++ < targetVersion)
|
||||
{
|
||||
switch (currentVersion)
|
||||
{
|
||||
case 1:
|
||||
// cannot migrate; breaking underlying changes.
|
||||
Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Prepare(bool reset = false)
|
||||
{
|
||||
Connection.CreateTable<DatabasedKeyBinding>();
|
||||
}
|
||||
|
||||
protected override Type[] ValidTypes => new[]
|
||||
{
|
||||
typeof(DatabasedKeyBinding)
|
||||
};
|
||||
|
||||
public List<KeyBinding> GetProcessedList(IEnumerable<KeyBinding> defaults, int? rulesetId, int? variant)
|
||||
{
|
||||
//todo: cache and share reference
|
||||
List<KeyBinding> bindings = new List<KeyBinding>(defaults);
|
||||
|
||||
// load from database if present.
|
||||
foreach (var b in Query<DatabasedKeyBinding>(b => b.RulesetID == rulesetId && b.Variant == variant))
|
||||
bindings.Add(b);
|
||||
|
||||
return bindings;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user