mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 10:03:05 +08:00
Add basic migration logic of key bindings to realm
This commit is contained in:
parent
a1cb6d8c54
commit
1abed11fb7
@ -24,6 +24,7 @@ using osu.Game.Online.API;
|
|||||||
using osu.Framework.Graphics.Performance;
|
using osu.Framework.Graphics.Performance;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
@ -265,10 +266,10 @@ namespace osu.Game
|
|||||||
dependencies.Cache(scorePerformanceManager);
|
dependencies.Cache(scorePerformanceManager);
|
||||||
AddInternal(scorePerformanceManager);
|
AddInternal(scorePerformanceManager);
|
||||||
|
|
||||||
// todo: migrate to realm
|
migrateDataToRealm();
|
||||||
// dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
|
||||||
|
|
||||||
dependencies.CacheAs(KeyBindingStore = new RealmKeyBindingStore(realmFactory, RulesetStore));
|
dependencies.CacheAs(KeyBindingStore = new RealmKeyBindingStore(realmFactory, RulesetStore));
|
||||||
|
|
||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||||
dependencies.Cache(new SessionStatics());
|
dependencies.Cache(new SessionStatics());
|
||||||
@ -322,6 +323,29 @@ namespace osu.Game
|
|||||||
Ruleset.BindValueChanged(onRulesetChanged);
|
Ruleset.BindValueChanged(onRulesetChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void migrateDataToRealm()
|
||||||
|
{
|
||||||
|
using (var db = contextFactory.GetForWrite())
|
||||||
|
using (var realm = realmFactory.GetForWrite())
|
||||||
|
{
|
||||||
|
var existingBindings = db.Context.DatabasedKeyBinding;
|
||||||
|
|
||||||
|
foreach (var dkb in existingBindings)
|
||||||
|
{
|
||||||
|
realm.Context.Add(new RealmKeyBinding
|
||||||
|
{
|
||||||
|
ID = Guid.NewGuid().ToString(),
|
||||||
|
KeyCombination = dkb.KeyCombination.ToString(),
|
||||||
|
Action = (int)dkb.Action,
|
||||||
|
RulesetID = dkb.RulesetID,
|
||||||
|
Variant = dkb.Variant
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Context.RemoveRange(existingBindings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
|
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<ModType, IReadOnlyList<Mod>>();
|
var dict = new Dictionary<ModType, IReadOnlyList<Mod>>();
|
||||||
|
Loading…
Reference in New Issue
Block a user