mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 20:22:55 +08:00
Refactor realm migrations to be a touch more legible
This commit is contained in:
parent
777b2cbcc4
commit
7acc4a4708
@ -152,46 +152,15 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
||||||
{
|
{
|
||||||
if (lastSchemaVersion < 9)
|
for (ulong i = lastSchemaVersion; i <= schema_version; i++)
|
||||||
{
|
applyMigrationsForVersion(migration, i);
|
||||||
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
|
|
||||||
string className = nameof(RealmBeatmapMetadata).Replace(@"Realm", string.Empty);
|
|
||||||
|
|
||||||
var oldItems = migration.OldRealm.DynamicApi.All(className);
|
|
||||||
var newItems = migration.NewRealm.All<RealmBeatmapMetadata>();
|
|
||||||
|
|
||||||
int itemCount = newItems.Count();
|
|
||||||
|
|
||||||
for (int i = 0; i < itemCount; i++)
|
|
||||||
{
|
|
||||||
dynamic? oldItem = oldItems.ElementAt(i);
|
|
||||||
var newItem = newItems.ElementAt(i);
|
|
||||||
|
|
||||||
string username = oldItem.Author;
|
|
||||||
newItem.Author = new RealmUser
|
|
||||||
{
|
|
||||||
Username = username
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastSchemaVersion < 8)
|
private void applyMigrationsForVersion(Migration migration, ulong version)
|
||||||
{
|
{
|
||||||
// Ctrl -/+ now adjusts UI scale so let's clear any bindings which overlap these combinations.
|
switch (version)
|
||||||
// New defaults will be populated by the key store afterwards.
|
|
||||||
var keyBindings = migration.NewRealm.All<RealmKeyBinding>();
|
|
||||||
|
|
||||||
var increaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.IncreaseScrollSpeed);
|
|
||||||
if (increaseSpeedBinding != null && increaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Plus }))
|
|
||||||
migration.NewRealm.Remove(increaseSpeedBinding);
|
|
||||||
|
|
||||||
var decreaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.DecreaseScrollSpeed);
|
|
||||||
if (decreaseSpeedBinding != null && decreaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Minus }))
|
|
||||||
migration.NewRealm.Remove(decreaseSpeedBinding);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastSchemaVersion < 7)
|
|
||||||
{
|
{
|
||||||
|
case 7:
|
||||||
convertOnlineIDs<RealmBeatmap>();
|
convertOnlineIDs<RealmBeatmap>();
|
||||||
convertOnlineIDs<RealmBeatmapSet>();
|
convertOnlineIDs<RealmBeatmapSet>();
|
||||||
convertOnlineIDs<RealmRuleset>();
|
convertOnlineIDs<RealmRuleset>();
|
||||||
@ -219,6 +188,46 @@ namespace osu.Game.Database
|
|||||||
newItem.OnlineID = (int)(nullableOnlineID ?? -1);
|
newItem.OnlineID = (int)(nullableOnlineID ?? -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
// Ctrl -/+ now adjusts UI scale so let's clear any bindings which overlap these combinations.
|
||||||
|
// New defaults will be populated by the key store afterwards.
|
||||||
|
var keyBindings = migration.NewRealm.All<RealmKeyBinding>();
|
||||||
|
|
||||||
|
var increaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.IncreaseScrollSpeed);
|
||||||
|
if (increaseSpeedBinding != null && increaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Plus }))
|
||||||
|
migration.NewRealm.Remove(increaseSpeedBinding);
|
||||||
|
|
||||||
|
var decreaseSpeedBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.DecreaseScrollSpeed);
|
||||||
|
if (decreaseSpeedBinding != null && decreaseSpeedBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.Control, InputKey.Minus }))
|
||||||
|
migration.NewRealm.Remove(decreaseSpeedBinding);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
|
||||||
|
string className = nameof(RealmBeatmapMetadata).Replace(@"Realm", string.Empty);
|
||||||
|
|
||||||
|
var oldItems = migration.OldRealm.DynamicApi.All(className);
|
||||||
|
var newItems = migration.NewRealm.All<RealmBeatmapMetadata>();
|
||||||
|
|
||||||
|
int itemCount = newItems.Count();
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCount; i++)
|
||||||
|
{
|
||||||
|
dynamic? oldItem = oldItems.ElementAt(i);
|
||||||
|
var newItem = newItems.ElementAt(i);
|
||||||
|
|
||||||
|
string username = oldItem.Author;
|
||||||
|
newItem.Author = new RealmUser
|
||||||
|
{
|
||||||
|
Username = username
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user