mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 05:22:54 +08:00
Store bindings to database
This commit is contained in:
parent
b88f37de45
commit
eee6404986
@ -1,9 +1,16 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets;
|
||||
using OpenTK.Input;
|
||||
using SQLite.Net;
|
||||
using SQLiteNetExtensions.Attributes;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
@ -12,6 +19,13 @@ namespace osu.Game.Input
|
||||
{
|
||||
protected IDictionary<Key, T> Mappings { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BindingStore bindings)
|
||||
{
|
||||
foreach (var b in bindings.Query<Binding>())
|
||||
Mappings[b.Key] = (T)(object)b.Action;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
mapKey(state, args.Key);
|
||||
@ -30,5 +44,44 @@ namespace osu.Game.Input
|
||||
if (Mappings.TryGetValue(key, out mappedData))
|
||||
state.Data = mappedData;
|
||||
}
|
||||
|
||||
private T parseStringRepresentation(string str)
|
||||
{
|
||||
T res;
|
||||
|
||||
if (Enum.TryParse(str, out res))
|
||||
return res;
|
||||
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public class Binding
|
||||
{
|
||||
[ForeignKey(typeof(RulesetInfo))]
|
||||
public int? RulesetID { get; set; }
|
||||
|
||||
public Key Key { get; set; }
|
||||
|
||||
public int Action { get; set; }
|
||||
}
|
||||
|
||||
public class BindingStore : DatabaseBackedStore
|
||||
{
|
||||
public BindingStore(SQLiteConnection connection, Storage storage = null)
|
||||
: base(connection, storage)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Prepare(bool reset = false)
|
||||
{
|
||||
Connection.CreateTable<Binding>();
|
||||
}
|
||||
|
||||
protected override Type[] ValidTypes => new[]
|
||||
{
|
||||
typeof(Binding)
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ using osu.Game.Online.API;
|
||||
using SQLite.Net;
|
||||
using osu.Framework.Graphics.Performance;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
@ -37,6 +38,8 @@ namespace osu.Game
|
||||
|
||||
protected ScoreStore ScoreStore;
|
||||
|
||||
protected BindingStore BindingStore;
|
||||
|
||||
protected override string MainResourceFile => @"osu.Game.Resources.dll";
|
||||
|
||||
public APIAccess API;
|
||||
@ -104,6 +107,7 @@ namespace osu.Game
|
||||
dependencies.Cache(FileStore = new FileStore(connection, Host.Storage));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host));
|
||||
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager));
|
||||
dependencies.Cache(BindingStore = new BindingStore(connection));
|
||||
dependencies.Cache(new OsuColour());
|
||||
|
||||
//this completely overrides the framework default. will need to change once we make a proper FontStore.
|
||||
|
Loading…
Reference in New Issue
Block a user