Store bindings to database

This commit is contained in:
Dean Herbert 2017-08-09 12:37:47 +09:00
parent b88f37de45
commit eee6404986
2 changed files with 57 additions and 0 deletions

View File

@ -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 @@ public class ActionMappingInputManager<T> : PassThroughInputManager
{
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 @@ private void mapKey(InputState state, Key key)
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)
};
}
}

View File

@ -19,6 +19,7 @@
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 @@ public class OsuGameBase : Framework.Game, IOnlineComponent
protected ScoreStore ScoreStore;
protected BindingStore BindingStore;
protected override string MainResourceFile => @"osu.Game.Resources.dll";
public APIAccess API;
@ -104,6 +107,7 @@ private void load()
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.