Rename realm to become imposter classes

This commit is contained in:
Dean Herbert 2021-11-19 19:07:21 +09:00
parent 0b6c4497bd
commit 618903c217
13 changed files with 140 additions and 140 deletions

View File

@ -19,6 +19,7 @@ using osu.Game.Extensions;
using osu.Game.IO.Archives;
using osu.Game.Models;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Stores;
using osu.Game.Tests.Resources;
using Realms;
@ -42,25 +43,25 @@ namespace osu.Game.Tests.Database
using (var importer = new BeatmapImporter(realmFactory, storage))
using (new RealmRulesetStore(realmFactory, storage))
{
ILive<RealmBeatmapSet>? imported;
ILive<BeatmapSetInfo>? imported;
using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
imported = await importer.Import(reader);
Assert.AreEqual(1, realmFactory.Context.All<RealmBeatmapSet>().Count());
Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count());
Assert.NotNull(imported);
Debug.Assert(imported != null);
imported.PerformWrite(s => s.DeletePending = true);
Assert.AreEqual(1, realmFactory.Context.All<RealmBeatmapSet>().Count(s => s.DeletePending));
Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count(s => s.DeletePending));
}
});
Logger.Log("Running with no work to purge pending deletions");
RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All<RealmBeatmapSet>().Count()); });
RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All<BeatmapSetInfo>().Count()); });
}
[Test]
@ -117,7 +118,7 @@ namespace osu.Game.Tests.Database
string? tempPath = TestResources.GetTestBeatmapForImport();
ILive<RealmBeatmapSet>? importedSet;
ILive<BeatmapSetInfo>? importedSet;
using (var stream = File.OpenRead(tempPath))
{
@ -131,7 +132,7 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
File.Delete(tempPath);
var imported = realmFactory.Context.All<RealmBeatmapSet>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
var imported = realmFactory.Context.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
deleteBeatmapSet(imported, realmFactory.Context);
});
@ -556,7 +557,7 @@ namespace osu.Game.Tests.Database
using var importer = new BeatmapImporter(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage);
var metadata = new RealmBeatmapMetadata
var metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
Author =
@ -565,18 +566,18 @@ namespace osu.Game.Tests.Database
}
};
var ruleset = realmFactory.Context.All<RealmRuleset>().First();
var ruleset = realmFactory.Context.All<RulesetInfo>().First();
var toImport = new RealmBeatmapSet
var toImport = new BeatmapSetInfo
{
OnlineID = 1,
Beatmaps =
{
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata)
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata)
{
OnlineID = 2,
},
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata)
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata)
{
OnlineID = 2,
Status = BeatmapOnlineStatus.Loved,
@ -752,18 +753,18 @@ namespace osu.Game.Tests.Database
await importer.Import(temp);
// Update via the beatmap, not the beatmap info, to ensure correct linking
RealmBeatmapSet setToUpdate = realmFactory.Context.All<RealmBeatmapSet>().First();
BeatmapSetInfo setToUpdate = realmFactory.Context.All<BeatmapSetInfo>().First();
var beatmapToUpdate = setToUpdate.Beatmaps.First();
realmFactory.Context.Write(() => beatmapToUpdate.DifficultyName = "updated");
RealmBeatmap updatedInfo = realmFactory.Context.All<RealmBeatmap>().First(b => b.ID == beatmapToUpdate.ID);
BeatmapInfo updatedInfo = realmFactory.Context.All<BeatmapInfo>().First(b => b.ID == beatmapToUpdate.ID);
Assert.That(updatedInfo.DifficultyName, Is.EqualTo("updated"));
});
}
public static async Task<RealmBeatmapSet?> LoadQuickOszIntoOsu(BeatmapImporter importer, Realm realm)
public static async Task<BeatmapSetInfo?> LoadQuickOszIntoOsu(BeatmapImporter importer, Realm realm)
{
string? temp = TestResources.GetQuickTestBeatmapForImport();
@ -775,10 +776,10 @@ namespace osu.Game.Tests.Database
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return realm.All<RealmBeatmapSet>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID);
return realm.All<BeatmapSetInfo>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID);
}
public static async Task<RealmBeatmapSet> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false)
public static async Task<BeatmapSetInfo> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false)
{
string? temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
@ -791,20 +792,20 @@ namespace osu.Game.Tests.Database
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return realm.All<RealmBeatmapSet>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
return realm.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
}
private void deleteBeatmapSet(RealmBeatmapSet imported, Realm realm)
private void deleteBeatmapSet(BeatmapSetInfo imported, Realm realm)
{
realm.Write(() => imported.DeletePending = true);
checkBeatmapSetCount(realm, 0);
checkBeatmapSetCount(realm, 1, true);
Assert.IsTrue(realm.All<RealmBeatmapSet>().First(_ => true).DeletePending);
Assert.IsTrue(realm.All<BeatmapSetInfo>().First(_ => true).DeletePending);
}
private static Task createScoreForBeatmap(Realm realm, RealmBeatmap beatmap)
private static Task createScoreForBeatmap(Realm realm, BeatmapInfo beatmap)
{
// TODO: reimplement when we have score support in realm.
// return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo
@ -820,8 +821,8 @@ namespace osu.Game.Tests.Database
private static void checkBeatmapSetCount(Realm realm, int expected, bool includeDeletePending = false)
{
Assert.AreEqual(expected, includeDeletePending
? realm.All<RealmBeatmapSet>().Count()
: realm.All<RealmBeatmapSet>().Count(s => !s.DeletePending));
? realm.All<BeatmapSetInfo>().Count()
: realm.All<BeatmapSetInfo>().Count(s => !s.DeletePending));
}
private static string hashFile(string filename)
@ -832,7 +833,7 @@ namespace osu.Game.Tests.Database
private static void checkBeatmapCount(Realm realm, int expected)
{
Assert.AreEqual(expected, realm.All<RealmBeatmap>().Where(_ => true).ToList().Count);
Assert.AreEqual(expected, realm.All<BeatmapInfo>().Where(_ => true).ToList().Count);
}
private static void checkSingleReferencedFileCount(Realm realm, int expected)
@ -850,24 +851,23 @@ namespace osu.Game.Tests.Database
private static void ensureLoaded(Realm realm, int timeout = 60000)
{
IQueryable<RealmBeatmapSet>? resultSets = null;
IQueryable<BeatmapSetInfo>? resultSets = null;
waitForOrAssert(() =>
{
realm.Refresh();
return (resultSets = realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any();
},
@"BeatmapSet did not import to the database in allocated time.", timeout);
{
realm.Refresh();
return (resultSets = realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any();
}, @"BeatmapSet did not import to the database in allocated time.", timeout);
// ensure we were stored to beatmap database backing...
Assert.IsTrue(resultSets?.Count() == 1, $@"Incorrect result count found ({resultSets?.Count()} but should be 1).");
IEnumerable<RealmBeatmapSet> queryBeatmapSets() => realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526);
IEnumerable<BeatmapSetInfo> queryBeatmapSets() => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && s.OnlineID == 241526);
var set = queryBeatmapSets().First();
// ReSharper disable once PossibleUnintendedReferenceComparison
IEnumerable<RealmBeatmap> queryBeatmaps() => realm.All<RealmBeatmap>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set);
IEnumerable<BeatmapInfo> queryBeatmaps() => realm.All<BeatmapInfo>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set);
Assert.AreEqual(12, queryBeatmaps().Count(), @"Beatmap count was not correct");
Assert.AreEqual(1, queryBeatmapSets().Count(), @"Beatmapset count was not correct");
@ -880,7 +880,7 @@ namespace osu.Game.Tests.Database
countBeatmaps = queryBeatmaps().Count(),
$@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).");
foreach (RealmBeatmap b in set.Beatmaps)
foreach (BeatmapInfo b in set.Beatmaps)
Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID));
Assert.IsTrue(set.Beatmaps.Count > 0);
}

View File

@ -5,8 +5,8 @@ using System;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Models;
#nullable enable
@ -48,7 +48,7 @@ namespace osu.Game.Tests.Database
using (var context = realmFactory.CreateContext())
{
var subscription = context.All<RealmBeatmap>().QueryAsyncWithNotifications((sender, changes, error) =>
var subscription = context.All<BeatmapInfo>().QueryAsyncWithNotifications((sender, changes, error) =>
{
using (realmFactory.CreateContext())
{

View File

@ -8,8 +8,8 @@ using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Extensions;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Models;
using Realms;
#nullable enable
@ -23,9 +23,9 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
ILive<RealmBeatmap> beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(realmFactory);
ILive<BeatmapInfo> beatmap = realmFactory.CreateContext().Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()))).ToLive(realmFactory);
ILive<RealmBeatmap> beatmap2 = realmFactory.CreateContext().All<RealmBeatmap>().First().ToLive(realmFactory);
ILive<BeatmapInfo> beatmap2 = realmFactory.CreateContext().All<BeatmapInfo>().First().ToLive(realmFactory);
Assert.AreEqual(beatmap, beatmap2);
});
@ -36,9 +36,9 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, storage) =>
{
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
ILive<RealmBeatmap> liveBeatmap;
ILive<BeatmapInfo> liveBeatmap;
using (var context = realmFactory.CreateContext())
{
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLive(realmFactory);
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Database
[Test]
public void TestAccessNonManaged()
{
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLiveUnmanaged();
Assert.IsFalse(beatmap.Hidden);
@ -96,12 +96,12 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
ILive<RealmBeatmap>? liveBeatmap = null;
ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() =>
{
using (var threadContext = realmFactory.CreateContext())
{
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory);
}
@ -125,12 +125,12 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
ILive<RealmBeatmap>? liveBeatmap = null;
ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() =>
{
using (var threadContext = realmFactory.CreateContext())
{
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory);
}
@ -151,7 +151,7 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLive(realmFactory);
Assert.DoesNotThrow(() =>
@ -166,13 +166,13 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
ILive<RealmBeatmap>? liveBeatmap = null;
ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() =>
{
using (var threadContext = realmFactory.CreateContext())
{
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory);
}
@ -205,12 +205,12 @@ namespace osu.Game.Tests.Database
{
RunTestWithRealm((realmFactory, _) =>
{
ILive<RealmBeatmap>? liveBeatmap = null;
ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() =>
{
using (var threadContext = realmFactory.CreateContext())
{
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory);
}
@ -237,19 +237,19 @@ namespace osu.Game.Tests.Database
using (var updateThreadContext = realmFactory.CreateContext())
{
updateThreadContext.All<RealmBeatmap>().QueryAsyncWithNotifications(gotChange);
ILive<RealmBeatmap>? liveBeatmap = null;
updateThreadContext.All<BeatmapInfo>().QueryAsyncWithNotifications(gotChange);
ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() =>
{
using (var threadContext = realmFactory.CreateContext())
{
var ruleset = CreateRuleset();
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
// add a second beatmap to ensure that a full refresh occurs below.
// not just a refresh from the resolved Live.
threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
threadContext.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory);
}
@ -258,14 +258,14 @@ namespace osu.Game.Tests.Database
Debug.Assert(liveBeatmap != null);
// not yet seen by main context
Assert.AreEqual(0, updateThreadContext.All<RealmBeatmap>().Count());
Assert.AreEqual(0, updateThreadContext.All<BeatmapInfo>().Count());
Assert.AreEqual(0, changesTriggered);
liveBeatmap.PerformRead(resolved =>
{
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
// ReSharper disable once AccessToDisposedClosure
Assert.AreEqual(2, updateThreadContext.All<RealmBeatmap>().Count());
Assert.AreEqual(2, updateThreadContext.All<BeatmapInfo>().Count());
Assert.AreEqual(1, changesTriggered);
// can access properties without a crash.
@ -280,7 +280,7 @@ namespace osu.Game.Tests.Database
});
}
void gotChange(IRealmCollection<RealmBeatmap> sender, ChangeSet changes, Exception error)
void gotChange(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error)
{
changesTriggered++;
}

View File

@ -9,9 +9,11 @@ using osu.Framework.Extensions;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO;
using osu.Game.Models;
using osu.Game.Rulesets;
#nullable enable
@ -74,24 +76,24 @@ namespace osu.Game.Tests.Database
}
}
protected static RealmBeatmapSet CreateBeatmapSet(RealmRuleset ruleset)
protected static BeatmapSetInfo CreateBeatmapSet(RulesetInfo ruleset)
{
RealmFile createRealmFile() => new RealmFile { Hash = Guid.NewGuid().ToString().ComputeSHA2Hash() };
var metadata = new RealmBeatmapMetadata
var metadata = new BeatmapMetadata
{
Title = "My Love",
Artist = "Kuba Oms"
};
var beatmapSet = new RealmBeatmapSet
var beatmapSet = new BeatmapSetInfo
{
Beatmaps =
{
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Easy", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Normal", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Hard", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Insane", }
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Easy", },
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Normal", },
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Hard", },
new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Insane", }
},
Files =
{
@ -111,8 +113,8 @@ namespace osu.Game.Tests.Database
return beatmapSet;
}
protected static RealmRuleset CreateRuleset() =>
new RealmRuleset(0, "osu!", "osu", true);
protected static RulesetInfo CreateRuleset() =>
new RulesetInfo(0, "osu!", "osu", true);
private class RealmTestGame : Framework.Game
{

View File

@ -3,7 +3,7 @@
using System.Linq;
using NUnit.Framework;
using osu.Game.Models;
using osu.Game.Rulesets;
using osu.Game.Stores;
namespace osu.Game.Tests.Database
@ -18,7 +18,7 @@ namespace osu.Game.Tests.Database
var rulesets = new RealmRulesetStore(realmFactory, storage);
Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
Assert.AreEqual(4, realmFactory.Context.All<RealmRuleset>().Count());
Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
});
}
@ -34,7 +34,7 @@ namespace osu.Game.Tests.Database
Assert.AreEqual(4, rulesets2.AvailableRulesets.Count());
Assert.AreEqual(rulesets.AvailableRulesets.First(), rulesets2.AvailableRulesets.First());
Assert.AreEqual(4, realmFactory.Context.All<RealmRuleset>().Count());
Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
});
}

View File

@ -2,16 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using Realms;
#nullable enable
namespace osu.Game.Models
namespace osu.Game.Beatmaps
{
[ExcludeFromDynamicCompile]
[MapTo("BeatmapDifficulty")]
public class RealmBeatmapDifficulty : EmbeddedObject, IBeatmapDifficultyInfo
public class BeatmapDifficulty : EmbeddedObject, IBeatmapDifficultyInfo
{
public float DrainRate { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
public float CircleSize { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
@ -22,16 +21,16 @@ namespace osu.Game.Models
public double SliderTickRate { get; set; } = 1;
/// <summary>
/// Returns a shallow-clone of this <see cref="RealmBeatmapDifficulty"/>.
/// Returns a shallow-clone of this <see cref="BeatmapDifficulty"/>.
/// </summary>
public RealmBeatmapDifficulty Clone()
public BeatmapDifficulty Clone()
{
var diff = new RealmBeatmapDifficulty();
var diff = new BeatmapDifficulty();
CopyTo(diff);
return diff;
}
public void CopyTo(RealmBeatmapDifficulty difficulty)
public void CopyTo(BeatmapDifficulty difficulty)
{
difficulty.ApproachRate = ApproachRate;
difficulty.DrainRate = DrainRate;

View File

@ -6,14 +6,14 @@ using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Rulesets;
using Realms;
#nullable enable
namespace osu.Game.Models
namespace osu.Game.Beatmaps
{
/// <summary>
/// A single beatmap difficulty.
@ -21,20 +21,20 @@ namespace osu.Game.Models
[ExcludeFromDynamicCompile]
[Serializable]
[MapTo("Beatmap")]
public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo, IEquatable<RealmBeatmap>
public class BeatmapInfo : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo, IEquatable<BeatmapInfo>
{
[PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid();
public string DifficultyName { get; set; } = string.Empty;
public RealmRuleset Ruleset { get; set; } = null!;
public RulesetInfo Ruleset { get; set; } = null!;
public RealmBeatmapDifficulty Difficulty { get; set; } = null!;
public BeatmapDifficulty Difficulty { get; set; } = null!;
public RealmBeatmapMetadata Metadata { get; set; } = null!;
public BeatmapMetadata Metadata { get; set; } = null!;
public RealmBeatmapSet? BeatmapSet { get; set; }
public BeatmapSetInfo? BeatmapSet { get; set; }
[Ignored]
public RealmNamedFileUsage? File => BeatmapSet?.Files.First(f => f.File.Hash == Hash);
@ -64,7 +64,7 @@ namespace osu.Game.Models
[JsonIgnore]
public bool Hidden { get; set; }
public RealmBeatmap(RealmRuleset ruleset, RealmBeatmapDifficulty difficulty, RealmBeatmapMetadata metadata)
public BeatmapInfo(RulesetInfo ruleset, BeatmapDifficulty difficulty, BeatmapMetadata metadata)
{
Ruleset = ruleset;
Difficulty = difficulty;
@ -72,7 +72,7 @@ namespace osu.Game.Models
}
[UsedImplicitly]
private RealmBeatmap()
private BeatmapInfo()
{
}
@ -102,7 +102,7 @@ namespace osu.Game.Models
#endregion
public bool Equals(RealmBeatmap? other)
public bool Equals(BeatmapInfo? other)
{
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
@ -110,15 +110,15 @@ namespace osu.Game.Models
return ID == other.ID;
}
public bool Equals(IBeatmapInfo? other) => other is RealmBeatmap b && Equals(b);
public bool Equals(IBeatmapInfo? other) => other is BeatmapInfo b && Equals(b);
public bool AudioEquals(RealmBeatmap? other) => other != null
public bool AudioEquals(BeatmapInfo? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null
&& BeatmapSet.Hash == other.BeatmapSet.Hash
&& Metadata.AudioFile == other.Metadata.AudioFile;
public bool BackgroundEquals(RealmBeatmap? other) => other != null
public bool BackgroundEquals(BeatmapInfo? other) => other != null
&& BeatmapSet != null
&& other.BeatmapSet != null
&& BeatmapSet.Hash == other.BeatmapSet.Hash

View File

@ -4,18 +4,18 @@
using System;
using Newtonsoft.Json;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Models;
using osu.Game.Users;
using Realms;
#nullable enable
namespace osu.Game.Models
namespace osu.Game.Beatmaps
{
[ExcludeFromDynamicCompile]
[Serializable]
[MapTo("BeatmapMetadata")]
public class RealmBeatmapMetadata : RealmObject, IBeatmapMetadataInfo
public class BeatmapMetadata : RealmObject, IBeatmapMetadataInfo
{
public string Title { get; set; } = string.Empty;

View File

@ -5,18 +5,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.Models;
using Realms;
#nullable enable
namespace osu.Game.Models
namespace osu.Game.Beatmaps
{
[ExcludeFromDynamicCompile]
[MapTo("BeatmapSet")]
public class RealmBeatmapSet : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<RealmBeatmapSet>, IBeatmapSetInfo
public class BeatmapSetInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<BeatmapSetInfo>, IBeatmapSetInfo
{
[PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid();
@ -26,9 +26,9 @@ namespace osu.Game.Models
public DateTimeOffset DateAdded { get; set; }
public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new RealmBeatmapMetadata();
public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new BeatmapMetadata();
public IList<RealmBeatmap> Beatmaps { get; } = null!;
public IList<BeatmapInfo> Beatmaps { get; } = null!;
public IList<RealmNamedFileUsage> Files { get; } = null!;
@ -63,7 +63,7 @@ namespace osu.Game.Models
/// <param name="filename">The name of the file to get the storage path of.</param>
public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.GetStoragePath();
public bool Equals(RealmBeatmapSet? other)
public bool Equals(BeatmapSetInfo? other)
{
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
@ -73,7 +73,7 @@ namespace osu.Game.Models
public override string ToString() => Metadata.GetDisplayString();
public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b);
public bool Equals(IBeatmapSetInfo? other) => other is BeatmapSetInfo b && Equals(b);
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;

View File

@ -12,6 +12,7 @@ using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Statistics;
using osu.Game.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Models;
using osu.Game.Skinning;
@ -109,7 +110,7 @@ namespace osu.Game.Database
using (var realm = CreateContext())
using (var transaction = realm.BeginWrite())
{
var pendingDeleteSets = realm.All<RealmBeatmapSet>().Where(s => s.DeletePending);
var pendingDeleteSets = realm.All<BeatmapSetInfo>().Where(s => s.DeletePending);
foreach (var s in pendingDeleteSets)
{
@ -206,9 +207,9 @@ namespace osu.Game.Database
switch (targetVersion)
{
case 7:
convertOnlineIDs<RealmBeatmap>();
convertOnlineIDs<RealmBeatmapSet>();
convertOnlineIDs<RealmRuleset>();
convertOnlineIDs<BeatmapInfo>();
convertOnlineIDs<BeatmapSetInfo>();
convertOnlineIDs<RulesetInfo>();
void convertOnlineIDs<T>() where T : RealmObject
{
@ -253,14 +254,14 @@ namespace osu.Game.Database
case 9:
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
string metadataClassName = getMappedOrOriginalName(typeof(RealmBeatmapMetadata));
string metadataClassName = getMappedOrOriginalName(typeof(BeatmapMetadata));
// May be coming from a version before `RealmBeatmapMetadata` existed.
if (!migration.OldRealm.Schema.TryFindObjectSchema(metadataClassName, out _))
return;
var oldMetadata = migration.OldRealm.DynamicApi.All(metadataClassName);
var newMetadata = migration.NewRealm.All<RealmBeatmapMetadata>();
var newMetadata = migration.NewRealm.All<BeatmapMetadata>();
int metadataCount = newMetadata.Count();

View File

@ -4,16 +4,15 @@
using System;
using JetBrains.Annotations;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using Realms;
#nullable enable
namespace osu.Game.Models
namespace osu.Game.Rulesets
{
[ExcludeFromDynamicCompile]
[MapTo("Ruleset")]
public class RealmRuleset : RealmObject, IEquatable<RealmRuleset>, IRulesetInfo
public class RulesetInfo : RealmObject, IEquatable<RulesetInfo>, IRulesetInfo
{
[PrimaryKey]
public string ShortName { get; set; } = string.Empty;
@ -25,7 +24,7 @@ namespace osu.Game.Models
public string InstantiationInfo { get; set; } = string.Empty;
public RealmRuleset(string shortName, string name, string instantiationInfo, int onlineID)
public RulesetInfo(string shortName, string name, string instantiationInfo, int onlineID)
{
ShortName = shortName;
Name = name;
@ -34,11 +33,11 @@ namespace osu.Game.Models
}
[UsedImplicitly]
private RealmRuleset()
private RulesetInfo()
{
}
public RealmRuleset(int? onlineID, string name, string shortName, bool available)
public RulesetInfo(int? onlineID, string name, string shortName, bool available)
{
OnlineID = onlineID ?? -1;
Name = name;
@ -48,13 +47,13 @@ namespace osu.Game.Models
public bool Available { get; set; }
public bool Equals(RealmRuleset? other) => other != null && OnlineID == other.OnlineID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo;
public bool Equals(RulesetInfo? other) => other != null && OnlineID == other.OnlineID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo;
public bool Equals(IRulesetInfo? other) => other is RealmRuleset b && Equals(b);
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
public override string ToString() => Name;
public RealmRuleset Clone() => new RealmRuleset
public RulesetInfo Clone() => new RulesetInfo
{
OnlineID = OnlineID,
Name = Name,

View File

@ -34,7 +34,7 @@ namespace osu.Game.Stores
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
/// </summary>
[ExcludeFromDynamicCompile]
public class BeatmapImporter : RealmArchiveModelImporter<RealmBeatmapSet>, IDisposable
public class BeatmapImporter : RealmArchiveModelImporter<BeatmapSetInfo>, IDisposable
{
public override IEnumerable<string> HandledExtensions => new[] { ".osz" };
@ -53,12 +53,12 @@ namespace osu.Game.Stores
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz";
protected override Task Populate(RealmBeatmapSet beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
{
if (archive != null)
beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet.Files, realm));
foreach (RealmBeatmap b in beatmapSet.Beatmaps)
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
b.BeatmapSet = beatmapSet;
validateOnlineIds(beatmapSet, realm);
@ -84,7 +84,7 @@ namespace osu.Game.Stores
return Task.CompletedTask;
}
protected override void PreImport(RealmBeatmapSet beatmapSet, Realm realm)
protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
{
// We are about to import a new beatmap. Before doing so, ensure that no other set shares the online IDs used by the new one.
// Note that this means if the previous beatmap is restored by the user, it will no longer be linked to its online IDs.
@ -93,7 +93,7 @@ namespace osu.Game.Stores
if (beatmapSet.OnlineID > 0)
{
var existingSetWithSameOnlineID = realm.All<RealmBeatmapSet>().SingleOrDefault(b => b.OnlineID == beatmapSet.OnlineID);
var existingSetWithSameOnlineID = realm.All<BeatmapSetInfo>().SingleOrDefault(b => b.OnlineID == beatmapSet.OnlineID);
if (existingSetWithSameOnlineID != null)
{
@ -108,7 +108,7 @@ namespace osu.Game.Stores
}
}
private void validateOnlineIds(RealmBeatmapSet beatmapSet, Realm realm)
private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm)
{
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineID > 0).Select(b => b.OnlineID).ToList();
@ -121,10 +121,10 @@ namespace osu.Game.Stores
}
// find any existing beatmaps in the database that have matching online ids
List<RealmBeatmap> existingBeatmaps = new List<RealmBeatmap>();
List<BeatmapInfo> existingBeatmaps = new List<BeatmapInfo>();
foreach (int id in beatmapIds)
existingBeatmaps.AddRange(realm.All<RealmBeatmap>().Where(b => b.OnlineID == id));
existingBeatmaps.AddRange(realm.All<BeatmapInfo>().Where(b => b.OnlineID == id));
if (existingBeatmaps.Any())
{
@ -143,7 +143,7 @@ namespace osu.Game.Stores
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineID = -1);
}
protected override bool CanSkipImport(RealmBeatmapSet existing, RealmBeatmapSet import)
protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import)
{
if (!base.CanSkipImport(existing, import))
return false;
@ -151,7 +151,7 @@ namespace osu.Game.Stores
return existing.Beatmaps.Any(b => b.OnlineID > 0);
}
protected override bool CanReuseExisting(RealmBeatmapSet existing, RealmBeatmapSet import)
protected override bool CanReuseExisting(BeatmapSetInfo existing, BeatmapSetInfo import)
{
if (!base.CanReuseExisting(existing, import))
return false;
@ -165,7 +165,7 @@ namespace osu.Game.Stores
public override string HumanisedModelName => "beatmap";
protected override RealmBeatmapSet? CreateModel(ArchiveReader reader)
protected override BeatmapSetInfo? CreateModel(ArchiveReader reader)
{
// let's make sure there are actually .osu files to import.
string? mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu", StringComparison.OrdinalIgnoreCase));
@ -180,7 +180,7 @@ namespace osu.Game.Stores
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
return new RealmBeatmapSet
return new BeatmapSetInfo
{
OnlineID = beatmap.BeatmapInfo.BeatmapSet?.OnlineID ?? -1,
// Metadata = beatmap.Metadata,
@ -189,11 +189,11 @@ namespace osu.Game.Stores
}
/// <summary>
/// Create all required <see cref="RealmBeatmap"/>s for the provided archive.
/// Create all required <see cref="BeatmapInfo"/>s for the provided archive.
/// </summary>
private List<RealmBeatmap> createBeatmapDifficulties(IList<RealmNamedFileUsage> files, Realm realm)
private List<BeatmapInfo> createBeatmapDifficulties(IList<RealmNamedFileUsage> files, Realm realm)
{
var beatmaps = new List<RealmBeatmap>();
var beatmaps = new List<BeatmapInfo>();
foreach (var file in files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
{
@ -214,7 +214,7 @@ namespace osu.Game.Stores
var decodedInfo = decoded.BeatmapInfo;
var decodedDifficulty = decodedInfo.BaseDifficulty;
var ruleset = realm.All<RealmRuleset>().FirstOrDefault(r => r.OnlineID == decodedInfo.RulesetID);
var ruleset = realm.All<RulesetInfo>().FirstOrDefault(r => r.OnlineID == decodedInfo.RulesetID);
if (ruleset?.Available != true)
{
@ -222,7 +222,7 @@ namespace osu.Game.Stores
continue;
}
var difficulty = new RealmBeatmapDifficulty
var difficulty = new BeatmapDifficulty
{
DrainRate = decodedDifficulty.DrainRate,
CircleSize = decodedDifficulty.CircleSize,
@ -232,7 +232,7 @@ namespace osu.Game.Stores
SliderTickRate = decodedDifficulty.SliderTickRate,
};
var metadata = new RealmBeatmapMetadata
var metadata = new BeatmapMetadata
{
Title = decoded.Metadata.Title,
TitleUnicode = decoded.Metadata.TitleUnicode,
@ -250,7 +250,7 @@ namespace osu.Game.Stores
BackgroundFile = decoded.Metadata.BackgroundFile,
};
var beatmap = new RealmBeatmap(ruleset, difficulty, metadata)
var beatmap = new BeatmapInfo(ruleset, difficulty, metadata)
{
Hash = hash,
DifficultyName = decodedInfo.DifficultyName,
@ -278,7 +278,7 @@ namespace osu.Game.Stores
return beatmaps;
}
private void updateBeatmapStatistics(RealmBeatmap beatmap, IBeatmap decoded)
private void updateBeatmapStatistics(BeatmapInfo beatmap, IBeatmap decoded)
{
var rulesetInstance = ((IRulesetInfo)beatmap.Ruleset).CreateInstance();

View File

@ -11,7 +11,6 @@ using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Rulesets;
#nullable enable
@ -106,7 +105,7 @@ namespace osu.Game.Stores
{
context.Write(realm =>
{
var rulesets = realm.All<RealmRuleset>();
var rulesets = realm.All<RulesetInfo>();
List<Ruleset> instances = loadedAssemblies.Values
.Select(r => Activator.CreateInstance(r) as Ruleset)
@ -117,8 +116,8 @@ namespace osu.Game.Stores
// add all legacy rulesets first to ensure they have exclusive choice of primary key.
foreach (var r in instances.Where(r => r is ILegacyRuleset))
{
if (realm.All<RealmRuleset>().FirstOrDefault(rr => rr.OnlineID == r.RulesetInfo.OnlineID) == null)
realm.Add(new RealmRuleset(r.RulesetInfo.ShortName, r.RulesetInfo.Name, r.RulesetInfo.InstantiationInfo, r.RulesetInfo.OnlineID));
if (realm.All<RulesetInfo>().FirstOrDefault(rr => rr.OnlineID == r.RulesetInfo.OnlineID) == null)
realm.Add(new RulesetInfo(r.RulesetInfo.ShortName, r.RulesetInfo.Name, r.RulesetInfo.InstantiationInfo, r.RulesetInfo.OnlineID));
}
// add any other rulesets which have assemblies present but are not yet in the database.
@ -136,11 +135,11 @@ namespace osu.Game.Stores
existingSameShortName.InstantiationInfo = r.RulesetInfo.InstantiationInfo;
}
else
realm.Add(new RealmRuleset(r.RulesetInfo.ShortName, r.RulesetInfo.Name, r.RulesetInfo.InstantiationInfo, r.RulesetInfo.OnlineID));
realm.Add(new RulesetInfo(r.RulesetInfo.ShortName, r.RulesetInfo.Name, r.RulesetInfo.InstantiationInfo, r.RulesetInfo.OnlineID));
}
}
List<RealmRuleset> detachedRulesets = new List<RealmRuleset>();
List<RulesetInfo> detachedRulesets = new List<RulesetInfo>();
// perform a consistency check and detach final rulesets from realm for cross-thread runtime usage.
foreach (var r in rulesets)