1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 05:02:56 +08:00

Merge branch 'master' into top-local-rank-optimisation

This commit is contained in:
Dean Herbert 2022-01-19 13:04:14 +09:00
commit e60fd358d0
43 changed files with 334 additions and 192 deletions

View File

@ -12,7 +12,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -12,7 +12,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -12,7 +12,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -12,7 +12,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -9,7 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> <PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="nunit" Version="3.13.2" /> <PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -40,7 +40,7 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
Artist = @"Unknown", Artist = @"Unknown",
Title = @"You're breathtaking", Title = @"You're breathtaking",
AuthorString = @"Everyone", Author = { Username = @"Everyone" },
}, },
Ruleset = new CatchRuleset().RulesetInfo Ruleset = new CatchRuleset().RulesetInfo
}, },

View File

@ -4,7 +4,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">

View File

@ -4,7 +4,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">

View File

@ -5,7 +5,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Moq" Version="4.16.1" /> <PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">

View File

@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
{ {
Artist = @"Unknown", Artist = @"Unknown",
Title = @"Sample Beatmap", Title = @"Sample Beatmap",
AuthorString = @"peppy", Author = { Username = @"peppy" },
}, },
Ruleset = new TaikoRuleset().RulesetInfo Ruleset = new TaikoRuleset().RulesetInfo
}, },

View File

@ -163,7 +163,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
{ {
Artist = "Unknown", Artist = "Unknown",
Title = "Sample Beatmap", Title = "Sample Beatmap",
AuthorString = "Craftplacer", Author = { Username = "Craftplacer" },
}, },
Ruleset = new TaikoRuleset().RulesetInfo Ruleset = new TaikoRuleset().RulesetInfo
}, },

View File

@ -4,7 +4,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
ArtistUnicode = "check unicode too", ArtistUnicode = "check unicode too",
Title = "Title goes here", Title = "Title goes here",
TitleUnicode = "Title goes here", TitleUnicode = "Title goes here",
AuthorString = "The Author", Author = { Username = "The Author" },
Source = "unit tests", Source = "unit tests",
Tags = "look for tags too", Tags = "look for tags too",
}, },

View File

@ -89,7 +89,7 @@ namespace osu.Game.Tests.Resources
// Create random metadata, then we can check if sorting works based on these // Create random metadata, then we can check if sorting works based on these
Artist = "Some Artist " + RNG.Next(0, 9), Artist = "Some Artist " + RNG.Next(0, 9),
Title = $"Some Song (set id {setId}) {Guid.NewGuid()}", Title = $"Some Song (set id {setId}) {Guid.NewGuid()}",
AuthorString = "Some Guy " + RNG.Next(0, 9), Author = { Username = "Some Guy " + RNG.Next(0, 9) },
}; };
var beatmapSet = new BeatmapSetInfo var beatmapSet = new BeatmapSetInfo

View File

@ -29,9 +29,10 @@ namespace osu.Game.Tests.Visual.Editing
[Cached] [Cached]
private EditorClipboard clipboard = new EditorClipboard(); private EditorClipboard clipboard = new EditorClipboard();
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap); Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
Child = new ComposeScreen Child = new ComposeScreen

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -37,9 +36,10 @@ namespace osu.Game.Tests.Visual.Editing
}); });
} }
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
// ensure that music controller does not change this beatmap due to it // ensure that music controller does not change this beatmap due to it
// completing naturally as part of the test. // completing naturally as part of the test.

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -23,9 +22,10 @@ namespace osu.Game.Tests.Visual.Editing
BeatDivisor.Value = 4; BeatDivisor.Value = 4;
} }
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
var testBeatmap = new Beatmap var testBeatmap = new Beatmap
{ {
ControlPointInfo = new ControlPointInfo(), ControlPointInfo = new ControlPointInfo(),

View File

@ -29,9 +29,10 @@ namespace osu.Game.Tests.Visual.Editing
editorBeatmap = new EditorBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); editorBeatmap = new EditorBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
} }
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap); Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
Beatmap.Disabled = true; Beatmap.Disabled = true;

View File

@ -52,7 +52,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Artist = "Some Artist", Artist = "Some Artist",
Title = "Some Beatmap", Title = "Some Beatmap",
AuthorString = "Some Author" Author = { Username = "Some Author" },
}; };
var beatmapSetInfo = new BeatmapSetInfo var beatmapSetInfo = new BeatmapSetInfo

View File

@ -100,7 +100,7 @@ namespace osu.Game.Tests.Visual.Navigation
var metadata = new BeatmapMetadata var metadata = new BeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
AuthorString = "SomeAuthor", Author = { Username = "SomeAuthor" },
Title = $"import {i}" Title = $"import {i}"
}; };

View File

@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.Navigation
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
AuthorString = "SomeAuthor", Author = { Username = "SomeAuthor" },
Title = "import" Title = "import"
}, },
BaseDifficulty = new BeatmapDifficulty(), BaseDifficulty = new BeatmapDifficulty(),
@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual.Navigation
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
AuthorString = "SomeAuthor", Author = { Username = "SomeAuthor" },
Title = "import" Title = "import"
}, },
BaseDifficulty = new BeatmapDifficulty(), BaseDifficulty = new BeatmapDifficulty(),

View File

@ -0,0 +1,32 @@
// 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.Framework.Development;
using osu.Game.Configuration;
namespace osu.Game.Tests.Visual.Navigation
{
[TestFixture]
public class TestSceneStartupRuleset : OsuGameTestScene
{
protected override TestOsuGame CreateTestGame()
{
// Must be done in this function due to the RecycleLocalStorage call just before.
var config = DebugUtils.IsDebugBuild
? new DevelopmentOsuConfigManager(LocalStorage)
: new OsuConfigManager(LocalStorage);
config.SetValue(OsuSetting.Ruleset, "mania");
config.Save();
return base.CreateTestGame();
}
[Test]
public void TestRulesetConsumed()
{
AddUntilStep("ruleset correct", () => Game.Ruleset.Value.ShortName == "mania");
}
}
}

View File

@ -2,8 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Overlays;
namespace osu.Game.Tests.Visual.Playlists namespace osu.Game.Tests.Visual.Playlists
{ {
@ -12,9 +10,6 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
protected override bool UseOnlineAPI => true; protected override bool UseOnlineAPI => true;
[Cached]
private MusicController musicController { get; set; } = new MusicController();
public TestScenePlaylistsScreen() public TestScenePlaylistsScreen()
{ {
var multi = new Screens.OnlinePlay.Playlists.Playlists(); var multi = new Screens.OnlinePlay.Playlists.Playlists();

View File

@ -409,7 +409,7 @@ namespace osu.Game.Tests.Visual.SongSelect
set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string); set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string);
if (i == 16) if (i == 16)
set.Beatmaps.ForEach(b => b.Metadata.AuthorString = zzz_string); set.Beatmaps.ForEach(b => b.Metadata.Author.Username = zzz_string);
sets.Add(set); sets.Add(set);
} }

View File

@ -208,7 +208,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
AuthorString = $"{ruleset.ShortName}Author", Author = { Username = $"{ruleset.ShortName}Author" },
Artist = $"{ruleset.ShortName}Artist", Artist = $"{ruleset.ShortName}Artist",
Source = $"{ruleset.ShortName}Source", Source = $"{ruleset.ShortName}Source",
Title = $"{ruleset.ShortName}Title" Title = $"{ruleset.ShortName}Title"
@ -230,7 +230,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
AuthorString = "WWWWWWWWWWWWWWW", Author = { Username = "WWWWWWWWWWWWWWW" },
Artist = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Artist", Artist = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Artist",
Source = "Verrrrry long Source", Source = "Verrrrry long Source",
Title = "Verrrrry long Title" Title = "Verrrrry long Title"

View File

@ -6,7 +6,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" /> <PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Moq" Version="4.16.1" /> <PackageReference Include="Moq" Version="4.16.1" />
</ItemGroup> </ItemGroup>

View File

@ -35,9 +35,9 @@ namespace osu.Game.Tournament.Tests.NonVisual
public class TestTournament : TournamentGameBase public class TestTournament : TournamentGameBase
{ {
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
Ruleset.Value = new RulesetInfo(); // not available Ruleset.Value = new RulesetInfo(); // not available
} }
} }

View File

@ -7,7 +7,7 @@
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" /> <PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>

View File

@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps
{ {
Artist = @"Unknown", Artist = @"Unknown",
Title = @"Unknown", Title = @"Unknown",
AuthorString = @"Unknown Creator", Author = { Username = @"Unknown Creator" },
}, },
DifficultyName = @"Normal", DifficultyName = @"Normal",
BaseDifficulty = Difficulty, BaseDifficulty = Difficulty,

View File

@ -64,6 +64,7 @@ namespace osu.Game.Beatmaps
[Ignored] [Ignored]
public RealmNamedFileUsage? File => BeatmapSet?.Files.FirstOrDefault(f => f.File.Hash == Hash); public RealmNamedFileUsage? File => BeatmapSet?.Files.FirstOrDefault(f => f.File.Hash == Hash);
[Ignored]
public BeatmapOnlineStatus Status public BeatmapOnlineStatus Status
{ {
get => (BeatmapOnlineStatus)StatusInt; get => (BeatmapOnlineStatus)StatusInt;

View File

@ -45,16 +45,6 @@ namespace osu.Game.Beatmaps
IUser IBeatmapMetadataInfo.Author => Author; IUser IBeatmapMetadataInfo.Author => Author;
#region Compatibility properties
public string AuthorString
{
get => Author.Username;
set => Author.Username = value;
}
#endregion
public override string ToString() => this.GetDisplayTitle(); public override string ToString() => this.GetDisplayTitle();
} }
} }

View File

@ -32,6 +32,7 @@ namespace osu.Game.Beatmaps
public IList<RealmNamedFileUsage> Files { get; } = null!; public IList<RealmNamedFileUsage> Files { get; } = null!;
[Ignored]
public BeatmapOnlineStatus Status public BeatmapOnlineStatus Status
{ {
get => (BeatmapOnlineStatus)StatusInt; get => (BeatmapOnlineStatus)StatusInt;

View File

@ -251,7 +251,7 @@ namespace osu.Game.Beatmaps.Formats
break; break;
case @"Creator": case @"Creator":
metadata.AuthorString = pair.Value; metadata.Author.Username = pair.Value;
break; break;
case @"Version": case @"Version":

View File

@ -1,9 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using osu.Framework.Development;
using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Statistics; using osu.Framework.Statistics;
@ -144,6 +147,18 @@ namespace osu.Game.Database
Database = { AutoTransactionsEnabled = false } Database = { AutoTransactionsEnabled = false }
}; };
public void CreateBackup(string backupFilename)
{
Logger.Log($"Creating full EF database backup at {backupFilename}", LoggingTarget.Database);
if (DebugUtils.IsDebugBuild)
Logger.Log("Your development database has been fully migrated to realm. If you switch back to a pre-realm branch and need your previous database, rename the backup file back to \"client.db\".\n\nNote that doing this can potentially leave your file store in a bad state.", level: LogLevel.Important);
using (var source = storage.GetStream(DATABASE_NAME))
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
source.CopyTo(destination);
}
public void ResetDatabase() public void ResetDatabase()
{ {
lock (writeLock) lock (writeLock)

View File

@ -1,8 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Models; using osu.Game.Models;
@ -21,6 +24,8 @@ namespace osu.Game.Database
private readonly RealmContextFactory realmContextFactory; private readonly RealmContextFactory realmContextFactory;
private readonly OsuConfigManager config; private readonly OsuConfigManager config;
private bool hasTakenBackup;
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config) public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config)
{ {
this.efContextFactory = efContextFactory; this.efContextFactory = efContextFactory;
@ -30,97 +35,125 @@ namespace osu.Game.Database
public void Run() public void Run()
{ {
using (var db = efContextFactory.GetForWrite()) using (var ef = efContextFactory.GetForWrite())
{ {
migrateSettings(db); migrateSettings(ef);
migrateSkins(db); migrateSkins(ef);
migrateBeatmaps(ef);
migrateBeatmaps(db); migrateScores(ef);
migrateScores(db);
} }
// Delete the database permanently.
// Will cause future startups to not attempt migration.
Logger.Log("Migration successful, deleting EF database", LoggingTarget.Database);
efContextFactory.ResetDatabase();
} }
private void migrateBeatmaps(DatabaseWriteUsage db) private void migrateBeatmaps(DatabaseWriteUsage ef)
{ {
// can be removed 20220730. // can be removed 20220730.
var existingBeatmapSets = db.Context.EFBeatmapSetInfo List<EFBeatmapSetInfo> existingBeatmapSets = ef.Context.EFBeatmapSetInfo
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo) .Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata) .Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty) .Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
.Include(s => s.Files).ThenInclude(f => f.FileInfo) .Include(s => s.Files).ThenInclude(f => f.FileInfo)
.Include(s => s.Metadata) .Include(s => s.Metadata)
.ToList(); .ToList();
Logger.Log("Beginning beatmaps migration to realm", LoggingTarget.Database);
// previous entries in EF are removed post migration. // previous entries in EF are removed post migration.
if (!existingBeatmapSets.Any()) if (!existingBeatmapSets.Any())
{
Logger.Log("No beatmaps found to migrate", LoggingTarget.Database);
return; return;
}
using (var realm = realmContextFactory.CreateContext()) using (var realm = realmContextFactory.CreateContext())
using (var transaction = realm.BeginWrite())
{ {
// only migrate data if the realm database is empty. Logger.Log($"Found {existingBeatmapSets.Count} beatmaps in EF", LoggingTarget.Database);
// note that this cannot be written as: `realm.All<BeatmapInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (!realm.All<BeatmapSetInfo>().Any(s => !s.Protected)) if (!hasTakenBackup)
{ {
foreach (var beatmapSet in existingBeatmapSets) string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
efContextFactory.CreateBackup($"client.{migration}.db");
realmContextFactory.CreateBackup($"client.{migration}.realm");
hasTakenBackup = true;
}
// only migrate data if the realm database is empty.
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
{
Logger.Log("Skipping migration as realm already has beatmaps loaded", LoggingTarget.Database);
}
else
{
using (var transaction = realm.BeginWrite())
{ {
var realmBeatmapSet = new BeatmapSetInfo foreach (var beatmapSet in existingBeatmapSets)
{ {
OnlineID = beatmapSet.OnlineID ?? -1, var realmBeatmapSet = new BeatmapSetInfo
DateAdded = beatmapSet.DateAdded,
Status = beatmapSet.Status,
DeletePending = beatmapSet.DeletePending,
Hash = beatmapSet.Hash,
Protected = beatmapSet.Protected,
};
migrateFiles(beatmapSet, realm, realmBeatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
{
var realmBeatmap = new BeatmapInfo
{ {
DifficultyName = beatmap.DifficultyName, OnlineID = beatmapSet.OnlineID ?? -1,
Status = beatmap.Status, DateAdded = beatmapSet.DateAdded,
OnlineID = beatmap.OnlineID ?? -1, Status = beatmapSet.Status,
Length = beatmap.Length, DeletePending = beatmapSet.DeletePending,
BPM = beatmap.BPM, Hash = beatmapSet.Hash,
Hash = beatmap.Hash, Protected = beatmapSet.Protected,
StarRating = beatmap.StarRating,
MD5Hash = beatmap.MD5Hash,
Hidden = beatmap.Hidden,
AudioLeadIn = beatmap.AudioLeadIn,
StackLeniency = beatmap.StackLeniency,
SpecialStyle = beatmap.SpecialStyle,
LetterboxInBreaks = beatmap.LetterboxInBreaks,
WidescreenStoryboard = beatmap.WidescreenStoryboard,
EpilepsyWarning = beatmap.EpilepsyWarning,
SamplesMatchPlaybackRate = beatmap.SamplesMatchPlaybackRate,
DistanceSpacing = beatmap.DistanceSpacing,
BeatDivisor = beatmap.BeatDivisor,
GridSize = beatmap.GridSize,
TimelineZoom = beatmap.TimelineZoom,
Countdown = beatmap.Countdown,
CountdownOffset = beatmap.CountdownOffset,
MaxCombo = beatmap.MaxCombo,
Bookmarks = beatmap.Bookmarks,
Ruleset = realm.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName),
Difficulty = new BeatmapDifficulty(beatmap.BaseDifficulty),
Metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata),
BeatmapSet = realmBeatmapSet,
}; };
realmBeatmapSet.Beatmaps.Add(realmBeatmap); migrateFiles(beatmapSet, realm, realmBeatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
{
var realmBeatmap = new BeatmapInfo
{
DifficultyName = beatmap.DifficultyName,
Status = beatmap.Status,
OnlineID = beatmap.OnlineID ?? -1,
Length = beatmap.Length,
BPM = beatmap.BPM,
Hash = beatmap.Hash,
StarRating = beatmap.StarRating,
MD5Hash = beatmap.MD5Hash,
Hidden = beatmap.Hidden,
AudioLeadIn = beatmap.AudioLeadIn,
StackLeniency = beatmap.StackLeniency,
SpecialStyle = beatmap.SpecialStyle,
LetterboxInBreaks = beatmap.LetterboxInBreaks,
WidescreenStoryboard = beatmap.WidescreenStoryboard,
EpilepsyWarning = beatmap.EpilepsyWarning,
SamplesMatchPlaybackRate = beatmap.SamplesMatchPlaybackRate,
DistanceSpacing = beatmap.DistanceSpacing,
BeatDivisor = beatmap.BeatDivisor,
GridSize = beatmap.GridSize,
TimelineZoom = beatmap.TimelineZoom,
Countdown = beatmap.Countdown,
CountdownOffset = beatmap.CountdownOffset,
MaxCombo = beatmap.MaxCombo,
Bookmarks = beatmap.Bookmarks,
Ruleset = realm.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName),
Difficulty = new BeatmapDifficulty(beatmap.BaseDifficulty),
Metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata),
BeatmapSet = realmBeatmapSet,
};
realmBeatmapSet.Beatmaps.Add(realmBeatmap);
}
realm.Add(realmBeatmapSet);
} }
realm.Add(realmBeatmapSet); transaction.Commit();
Logger.Log($"Successfully migrated {existingBeatmapSets.Count} beatmaps to realm", LoggingTarget.Database);
} }
} }
db.Context.RemoveRange(existingBeatmapSets); ef.Context.RemoveRange(existingBeatmapSets);
// Intentionally don't clean up the files, so they don't get purged by EF. // Intentionally don't clean up the files, so they don't get purged by EF.
transaction.Commit();
} }
} }
@ -144,69 +177,91 @@ namespace osu.Game.Database
PreviewTime = metadata.PreviewTime, PreviewTime = metadata.PreviewTime,
AudioFile = metadata.AudioFile, AudioFile = metadata.AudioFile,
BackgroundFile = metadata.BackgroundFile, BackgroundFile = metadata.BackgroundFile,
AuthorString = metadata.AuthorString,
}; };
} }
private void migrateScores(DatabaseWriteUsage db) private void migrateScores(DatabaseWriteUsage db)
{ {
// can be removed 20220730. // can be removed 20220730.
var existingScores = db.Context.ScoreInfo List<EFScoreInfo> existingScores = db.Context.ScoreInfo
.Include(s => s.Ruleset) .Include(s => s.Ruleset)
.Include(s => s.BeatmapInfo) .Include(s => s.BeatmapInfo)
.Include(s => s.Files) .Include(s => s.Files)
.ThenInclude(f => f.FileInfo) .ThenInclude(f => f.FileInfo)
.ToList(); .ToList();
Logger.Log("Beginning scores migration to realm", LoggingTarget.Database);
// previous entries in EF are removed post migration. // previous entries in EF are removed post migration.
if (!existingScores.Any()) if (!existingScores.Any())
{
Logger.Log("No scores found to migrate", LoggingTarget.Database);
return; return;
}
using (var realm = realmContextFactory.CreateContext()) using (var realm = realmContextFactory.CreateContext())
using (var transaction = realm.BeginWrite())
{ {
// only migrate data if the realm database is empty. Logger.Log($"Found {existingScores.Count} scores in EF", LoggingTarget.Database);
// note that this cannot be written as: `realm.All<ScoreInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (!realm.All<ScoreInfo>().Any()) if (!hasTakenBackup)
{ {
foreach (var score in existingScores) string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
efContextFactory.CreateBackup($"client.{migration}.db");
realmContextFactory.CreateBackup($"client.{migration}.realm");
hasTakenBackup = true;
}
// only migrate data if the realm database is empty.
if (realm.All<ScoreInfo>().Any())
{
Logger.Log("Skipping migration as realm already has scores loaded", LoggingTarget.Database);
}
else
{
using (var transaction = realm.BeginWrite())
{ {
var realmScore = new ScoreInfo foreach (var score in existingScores)
{ {
Hash = score.Hash, var realmScore = new ScoreInfo
DeletePending = score.DeletePending, {
OnlineID = score.OnlineID ?? -1, Hash = score.Hash,
ModsJson = score.ModsJson, DeletePending = score.DeletePending,
StatisticsJson = score.StatisticsJson, OnlineID = score.OnlineID ?? -1,
User = score.User, ModsJson = score.ModsJson,
TotalScore = score.TotalScore, StatisticsJson = score.StatisticsJson,
MaxCombo = score.MaxCombo, User = score.User,
Accuracy = score.Accuracy, TotalScore = score.TotalScore,
HasReplay = ((IScoreInfo)score).HasReplay, MaxCombo = score.MaxCombo,
Date = score.Date, Accuracy = score.Accuracy,
PP = score.PP, HasReplay = ((IScoreInfo)score).HasReplay,
BeatmapInfo = realm.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash), Date = score.Date,
Ruleset = realm.Find<RulesetInfo>(score.Ruleset.ShortName), PP = score.PP,
Rank = score.Rank, BeatmapInfo = realm.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash),
HitEvents = score.HitEvents, Ruleset = realm.Find<RulesetInfo>(score.Ruleset.ShortName),
Passed = score.Passed, Rank = score.Rank,
Combo = score.Combo, HitEvents = score.HitEvents,
Position = score.Position, Passed = score.Passed,
Statistics = score.Statistics, Combo = score.Combo,
Mods = score.Mods, Position = score.Position,
APIMods = score.APIMods, Statistics = score.Statistics,
}; Mods = score.Mods,
APIMods = score.APIMods,
};
migrateFiles(score, realm, realmScore); migrateFiles(score, realm, realmScore);
realm.Add(realmScore); realm.Add(realmScore);
}
transaction.Commit();
Logger.Log($"Successfully migrated {existingScores.Count} scores to realm", LoggingTarget.Database);
} }
} }
db.Context.RemoveRange(existingScores); db.Context.RemoveRange(existingScores);
// Intentionally don't clean up the files, so they don't get purged by EF. // Intentionally don't clean up the files, so they don't get purged by EF.
transaction.Commit();
} }
} }
@ -243,6 +298,8 @@ namespace osu.Game.Database
// note that this cannot be written as: `realm.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`. // note that this cannot be written as: `realm.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (!realm.All<SkinInfo>().Any(s => !s.Protected)) if (!realm.All<SkinInfo>().Any(s => !s.Protected))
{ {
Logger.Log($"Migrating {existingSkins.Count} skins", LoggingTarget.Database);
foreach (var skin in existingSkins) foreach (var skin in existingSkins)
{ {
var realmSkin = new SkinInfo var realmSkin = new SkinInfo
@ -286,18 +343,22 @@ namespace osu.Game.Database
private void migrateSettings(DatabaseWriteUsage db) private void migrateSettings(DatabaseWriteUsage db)
{ {
// migrate ruleset settings. can be removed 20220315. // migrate ruleset settings. can be removed 20220315.
var existingSettings = db.Context.DatabasedSetting; var existingSettings = db.Context.DatabasedSetting.ToList();
// previous entries in EF are removed post migration. // previous entries in EF are removed post migration.
if (!existingSettings.Any()) if (!existingSettings.Any())
return; return;
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
using (var realm = realmContextFactory.CreateContext()) using (var realm = realmContextFactory.CreateContext())
using (var transaction = realm.BeginWrite()) using (var transaction = realm.BeginWrite())
{ {
// only migrate data if the realm database is empty. // only migrate data if the realm database is empty.
if (!realm.All<RealmRulesetSetting>().Any()) if (!realm.All<RealmRulesetSetting>().Any())
{ {
Logger.Log($"Migrating {existingSettings.Count} settings", LoggingTarget.Database);
foreach (var dkb in existingSettings) foreach (var dkb in existingSettings)
{ {
if (dkb.RulesetID == null) if (dkb.RulesetID == null)

View File

@ -361,6 +361,17 @@ namespace osu.Game.Database
private string? getRulesetShortNameFromLegacyID(long rulesetId) => private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName; efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
public void CreateBackup(string backupFilename)
{
using (BlockAllOperations())
{
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
using (var source = storage.GetStream(Filename))
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
source.CopyTo(destination);
}
}
/// <summary> /// <summary>
/// Flush any active contexts and block any further writes. /// Flush any active contexts and block any further writes.
/// </summary> /// </summary>
@ -374,17 +385,17 @@ namespace osu.Game.Database
if (isDisposed) if (isDisposed)
throw new ObjectDisposedException(nameof(RealmContextFactory)); throw new ObjectDisposedException(nameof(RealmContextFactory));
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
try try
{ {
contextCreationLock.Wait(); contextCreationLock.Wait();
lock (contextLock) lock (contextLock)
{ {
if (!ThreadSafety.IsUpdateThread && context != null)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
context?.Dispose(); context?.Dispose();
context = null; context = null;
} }

View File

@ -20,12 +20,14 @@ namespace osu.Game.Input.Bindings
public int? Variant { get; set; } public int? Variant { get; set; }
[Ignored]
public KeyCombination KeyCombination public KeyCombination KeyCombination
{ {
get => KeyCombinationString; get => KeyCombinationString;
set => KeyCombinationString = value.ToString(); set => KeyCombinationString = value.ToString();
} }
[Ignored]
public object Action public object Action
{ {
get => ActionInt; get => ActionInt;

View File

@ -193,6 +193,7 @@ namespace osu.Game
dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage)); dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage));
dependencies.CacheAs<IRulesetStore>(RulesetStore); dependencies.CacheAs<IRulesetStore>(RulesetStore);
// A non-null context factory means there's still content to migrate.
if (efContextFactory != null) if (efContextFactory != null)
new EFToRealmMigrator(efContextFactory, realmFactory, LocalConfig).Run(); new EFToRealmMigrator(efContextFactory, realmFactory, LocalConfig).Run();
@ -300,6 +301,7 @@ namespace osu.Game
dependencies.CacheAs(MusicController); dependencies.CacheAs(MusicController);
Ruleset.BindValueChanged(onRulesetChanged); Ruleset.BindValueChanged(onRulesetChanged);
Beatmap.BindValueChanged(onBeatmapChanged);
} }
protected virtual void InitialiseFonts() protected virtual void InitialiseFonts()
@ -420,8 +422,17 @@ namespace osu.Game
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage); protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage);
private void onBeatmapChanged(ValueChangedEvent<WorkingBeatmap> valueChangedEvent)
{
if (IsLoaded && !ThreadSafety.IsUpdateThread)
throw new InvalidOperationException("Global beatmap bindable must be changed from update thread.");
}
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r) private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
{ {
if (IsLoaded && !ThreadSafety.IsUpdateThread)
throw new InvalidOperationException("Global ruleset bindable must be changed from update thread.");
Ruleset instance = null; Ruleset instance = null;
try try

View File

@ -104,6 +104,7 @@ namespace osu.Game.Scoring
} }
} }
[Ignored]
public ScoreRank Rank public ScoreRank Rank
{ {
get => (ScoreRank)RankInt; get => (ScoreRank)RankInt;

View File

@ -110,7 +110,7 @@ namespace osu.Game.Screens.Edit.Setup
Beatmap.Metadata.TitleUnicode = TitleTextBox.Current.Value; Beatmap.Metadata.TitleUnicode = TitleTextBox.Current.Value;
Beatmap.Metadata.Title = RomanisedTitleTextBox.Current.Value; Beatmap.Metadata.Title = RomanisedTitleTextBox.Current.Value;
Beatmap.Metadata.AuthorString = creatorTextBox.Current.Value; Beatmap.Metadata.Author.Username = creatorTextBox.Current.Value;
Beatmap.BeatmapInfo.DifficultyName = difficultyTextBox.Current.Value; Beatmap.BeatmapInfo.DifficultyName = difficultyTextBox.Current.Value;
Beatmap.Metadata.Source = sourceTextBox.Current.Value; Beatmap.Metadata.Source = sourceTextBox.Current.Value;
Beatmap.Metadata.Tags = tagsTextBox.Current.Value; Beatmap.Metadata.Tags = tagsTextBox.Current.Value;

View File

@ -35,9 +35,9 @@ namespace osu.Game.Tests.Visual
return dependencies; return dependencies;
} }
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load()
{ {
base.LoadComplete();
Beatmap.BindValueChanged(beatmapChanged, true); Beatmap.BindValueChanged(beatmapChanged, true);
} }

View File

@ -42,17 +42,27 @@ namespace osu.Game.Tests.Visual
Alpha = 0 Alpha = 0
}; };
private TestBeatmapManager testBeatmapManager;
private WorkingBeatmap working;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio, RulesetStore rulesets) private void load(GameHost host, AudioManager audio, RulesetStore rulesets)
{ {
Add(logo); Add(logo);
var working = CreateWorkingBeatmap(Ruleset.Value); working = CreateWorkingBeatmap(Ruleset.Value);
Beatmap.Value = working;
if (IsolateSavingFromDatabase) if (IsolateSavingFromDatabase)
Dependencies.CacheAs<BeatmapManager>(new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default, working)); Dependencies.CacheAs<BeatmapManager>(testBeatmapManager = new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
}
protected override void LoadComplete()
{
base.LoadComplete();
Beatmap.Value = working;
if (testBeatmapManager != null)
testBeatmapManager.TestBeatmap = working;
} }
protected virtual bool EditorComponentsReady => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true protected virtual bool EditorComponentsReady => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
@ -114,12 +124,11 @@ namespace osu.Game.Tests.Visual
private class TestBeatmapManager : BeatmapManager private class TestBeatmapManager : BeatmapManager
{ {
private readonly WorkingBeatmap testBeatmap; public WorkingBeatmap TestBeatmap;
public TestBeatmapManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host, WorkingBeatmap defaultBeatmap, WorkingBeatmap testBeatmap) public TestBeatmapManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host, WorkingBeatmap defaultBeatmap)
: base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap) : base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap)
{ {
this.testBeatmap = testBeatmap;
} }
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue) protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue)
@ -143,7 +152,7 @@ namespace osu.Game.Tests.Visual
} }
public override WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo) public override WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
=> testBeatmapManager.testBeatmap; => testBeatmapManager.TestBeatmap;
} }
internal class TestBeatmapModelManager : BeatmapModelManager internal class TestBeatmapModelManager : BeatmapModelManager

View File

@ -28,7 +28,6 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Rulesets; using osu.Game.Tests.Rulesets;
@ -38,13 +37,16 @@ namespace osu.Game.Tests.Visual
[ExcludeFromDynamicCompile] [ExcludeFromDynamicCompile]
public abstract class OsuTestScene : TestScene public abstract class OsuTestScene : TestScene
{ {
protected Bindable<WorkingBeatmap> Beatmap { get; private set; } [Cached]
protected Bindable<WorkingBeatmap> Beatmap { get; } = new Bindable<WorkingBeatmap>();
protected Bindable<RulesetInfo> Ruleset; [Cached]
protected Bindable<RulesetInfo> Ruleset { get; } = new Bindable<RulesetInfo>();
protected Bindable<IReadOnlyList<Mod>> SelectedMods; [Cached]
protected Bindable<IReadOnlyList<Mod>> SelectedMods { get; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
protected new OsuScreenDependencies Dependencies { get; private set; } protected new DependencyContainer Dependencies { get; private set; }
protected IResourceStore<byte[]> Resources; protected IResourceStore<byte[]> Resources;
@ -132,17 +134,15 @@ namespace osu.Game.Tests.Visual
var providedRuleset = CreateRuleset(); var providedRuleset = CreateRuleset();
if (providedRuleset != null) if (providedRuleset != null)
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies); isolatedBaseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies);
Dependencies = new OsuScreenDependencies(false, baseDependencies); Dependencies = isolatedBaseDependencies;
Beatmap = Dependencies.Beatmap; Beatmap.Default = parent.Get<Bindable<WorkingBeatmap>>().Default;
Beatmap.SetDefault(); Beatmap.SetDefault();
Ruleset = Dependencies.Ruleset; Ruleset.Value = CreateRuleset()?.RulesetInfo ?? parent.Get<RulesetStore>().AvailableRulesets.First();
Ruleset.SetDefault();
SelectedMods = Dependencies.Mods;
SelectedMods.SetDefault(); SelectedMods.SetDefault();
if (!UseOnlineAPI) if (!UseOnlineAPI)
@ -155,6 +155,23 @@ namespace osu.Game.Tests.Visual
return Dependencies; return Dependencies;
} }
protected override void LoadComplete()
{
base.LoadComplete();
var parentBeatmap = Parent.Dependencies.Get<Bindable<WorkingBeatmap>>();
parentBeatmap.Value = Beatmap.Value;
Beatmap.BindTo(parentBeatmap);
var parentRuleset = Parent.Dependencies.Get<Bindable<RulesetInfo>>();
parentRuleset.Value = Ruleset.Value;
Ruleset.BindTo(parentRuleset);
var parentMods = Parent.Dependencies.Get<Bindable<IReadOnlyList<Mod>>>();
parentMods.Value = SelectedMods.Value;
SelectedMods.BindTo(parentMods);
}
protected override Container<Drawable> Content => content ?? base.Content; protected override Container<Drawable> Content => content ?? base.Content;
private readonly Container content; private readonly Container content;
@ -279,12 +296,6 @@ namespace osu.Game.Tests.Visual
protected virtual WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => protected virtual WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) =>
new ClockBackedTestWorkingBeatmap(beatmap, storyboard, Clock, Audio); new ClockBackedTestWorkingBeatmap(beatmap, storyboard, Clock, Audio);
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{
Ruleset.Value = CreateRuleset()?.RulesetInfo ?? rulesets.AvailableRulesets.First();
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);