1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 04:13:00 +08:00

Merge branch 'master' into all-ruleset-encoders

This commit is contained in:
Dean Herbert 2020-04-22 13:04:16 +09:00 committed by GitHub
commit 223c822e57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 8 deletions

View File

@ -0,0 +1,61 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Users;
namespace osu.Game.Tests.Beatmaps
{
[TestFixture]
public class ToStringFormattingTest
{
[Test]
public void TestArtistTitle()
{
var beatmap = new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Artist = "artist",
Title = "title"
}
};
Assert.That(beatmap.ToString(), Is.EqualTo("artist - title"));
}
[Test]
public void TestArtistTitleCreator()
{
var beatmap = new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Artist = "artist",
Title = "title",
Author = new User { Username = "creator" }
}
};
Assert.That(beatmap.ToString(), Is.EqualTo("artist - title (creator)"));
}
[Test]
public void TestArtistTitleCreatorDifficulty()
{
var beatmap = new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Artist = "artist",
Title = "title",
Author = new User { Username = "creator" }
},
Version = "difficulty"
};
Assert.That(beatmap.ToString(), Is.EqualTo("artist - title (creator) [difficulty]"));
}
}
}

View File

@ -149,7 +149,12 @@ namespace osu.Game.Beatmaps
}
}
public override string ToString() => $"{Metadata} [{Version}]".Trim();
public override string ToString()
{
string version = string.IsNullOrEmpty(Version) ? string.Empty : $"[{Version}]";
return $"{Metadata} {version}".Trim();
}
public bool Equals(BeatmapInfo other)
{

View File

@ -53,7 +53,11 @@ namespace osu.Game.Beatmaps
public string AudioFile { get; set; }
public string BackgroundFile { get; set; }
public override string ToString() => $"{Artist} - {Title} ({Author})";
public override string ToString()
{
string author = Author == null ? string.Empty : $"({Author})";
return $"{Artist} - {Title} {author}".Trim();
}
[JsonIgnore]
public string[] SearchableTerms => new[]

View File

@ -168,7 +168,7 @@ namespace osu.Game
var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory, Storage));
dependencies.Cache(FileStore = new FileStore(contextFactory, Storage));
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
namespace osu.Game.Rulesets
@ -17,16 +18,24 @@ namespace osu.Game.Rulesets
private readonly Dictionary<Assembly, Type> loadedAssemblies = new Dictionary<Assembly, Type>();
public RulesetStore(IDatabaseContextFactory factory)
private readonly Storage rulesetStorage;
public RulesetStore(IDatabaseContextFactory factory, Storage storage = null)
: base(factory)
{
rulesetStorage = storage?.GetStorageForDirectory("rulesets");
// On android in release configuration assemblies are loaded from the apk directly into memory.
// We cannot read assemblies from cwd, so should check loaded assemblies instead.
loadFromAppDomain();
loadFromDisk();
addMissingRulesets();
AppDomain.CurrentDomain.AssemblyResolve += resolveRulesetAssembly;
// the event handler contains code for resolving dependency on the game assembly for rulesets located outside the base game directory.
// It needs to be attached to the assembly lookup event before the actual call to loadUserRulesets() else rulesets located out of the base game directory will fail
// to load as unable to locate the game core assembly.
AppDomain.CurrentDomain.AssemblyResolve += resolveRulesetDependencyAssembly;
loadUserRulesets();
addMissingRulesets();
}
/// <summary>
@ -48,7 +57,21 @@ namespace osu.Game.Rulesets
/// </summary>
public IEnumerable<RulesetInfo> AvailableRulesets { get; private set; }
private Assembly resolveRulesetAssembly(object sender, ResolveEventArgs args) => loadedAssemblies.Keys.FirstOrDefault(a => a.FullName == args.Name);
private Assembly resolveRulesetDependencyAssembly(object sender, ResolveEventArgs args)
{
var asm = new AssemblyName(args.Name);
// the requesting assembly may be located out of the executable's base directory, thus requiring manual resolving of its dependencies.
// this attempts resolving the ruleset dependencies on game core and framework assemblies by returning assemblies with the same assembly name
// already loaded in the AppDomain.
foreach (var curAsm in AppDomain.CurrentDomain.GetAssemblies())
{
if (asm.Name.Equals(curAsm.GetName().Name, StringComparison.Ordinal))
return curAsm;
}
return loadedAssemblies.Keys.FirstOrDefault(a => a.FullName == asm.FullName);
}
private void addMissingRulesets()
{
@ -120,6 +143,16 @@ namespace osu.Game.Rulesets
}
}
private void loadUserRulesets()
{
if (rulesetStorage == null) return;
var rulesets = rulesetStorage.GetFiles(".", $"{ruleset_library_prefix}.*.dll");
foreach (var ruleset in rulesets.Where(f => !f.Contains("Tests")))
loadRulesetFromFile(rulesetStorage.GetFullPath(ruleset));
}
private void loadFromDisk()
{
try
@ -175,7 +208,7 @@ namespace osu.Game.Rulesets
protected virtual void Dispose(bool disposing)
{
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetAssembly;
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetDependencyAssembly;
}
}
}