diff --git a/osu.Game/Input/ActionMappingInputManager.cs b/osu.Game/Input/ActionMappingInputManager.cs index 5e2facdc93..89e8686a2c 100644 --- a/osu.Game/Input/ActionMappingInputManager.cs +++ b/osu.Game/Input/ActionMappingInputManager.cs @@ -1,9 +1,16 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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 Mappings { get; set; } + [BackgroundDependencyLoader] + private void load(BindingStore bindings) + { + foreach (var b in bindings.Query()) + 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(); + } + + protected override Type[] ValidTypes => new[] + { + typeof(Binding) + }; + } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 0dec4228de..b76235f3f4 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -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.