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

Attempt to reimport intro if a bad state is detected

This commit is contained in:
Dean Herbert 2020-06-08 14:48:42 +09:00
parent 63003757c4
commit dd61d6ed04
2 changed files with 43 additions and 24 deletions

View File

@ -41,9 +41,9 @@ namespace osu.Game.Screens.Menu
protected IBindable<bool> MenuMusic { get; private set; } protected IBindable<bool> MenuMusic { get; private set; }
private WorkingBeatmap introBeatmap; private WorkingBeatmap initialBeatmap;
protected Track Track { get; private set; } protected Track Track => initialBeatmap?.Track;
private readonly BindableDouble exitingVolumeFade = new BindableDouble(1); private readonly BindableDouble exitingVolumeFade = new BindableDouble(1);
@ -58,6 +58,11 @@ namespace osu.Game.Screens.Menu
[Resolved] [Resolved]
private AudioManager audio { get; set; } private AudioManager audio { get; set; }
/// <summary>
/// Whether the <see cref="Track"/> is provided by osu! resources, rather than a user beatmap.
/// </summary>
protected bool UsingThemedIntro { get; private set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game) private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
{ {
@ -71,29 +76,45 @@ namespace osu.Game.Screens.Menu
BeatmapSetInfo setInfo = null; BeatmapSetInfo setInfo = null;
// if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
if (!MenuMusic.Value) if (!MenuMusic.Value)
{ {
var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal); var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal);
if (sets.Count > 0) if (sets.Count > 0)
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
}
if (setInfo == null)
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
if (setInfo == null)
{ {
// we need to import the default menu background beatmap setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result; initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
setInfo.Protected = true;
beatmaps.Update(setInfo);
} }
} }
introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); // we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
Track = introBeatmap.Track; if (setInfo == null)
{
if (!loadThemedIntro())
{
// if we detect that the theme track or beatmap is unavailable this is either first startup or things are in a bad state.
// this could happen if a user has nuked their files store. for now, reimport to repair this.
var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;
import.Protected = true;
beatmaps.Update(import);
loadThemedIntro();
}
}
bool loadThemedIntro()
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
if (setInfo != null)
{
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
UsingThemedIntro = !(Track is TrackVirtual);
}
return UsingThemedIntro;
}
} }
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
@ -119,7 +140,7 @@ namespace osu.Game.Screens.Menu
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
{ {
base.OnSuspending(next); base.OnSuspending(next);
Track = null; initialBeatmap = null;
} }
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
@ -127,7 +148,7 @@ namespace osu.Game.Screens.Menu
protected void StartTrack() protected void StartTrack()
{ {
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu. // Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
if (MenuMusic.Value) if (UsingThemedIntro)
Track.Restart(); Track.Restart();
} }
@ -141,8 +162,7 @@ namespace osu.Game.Screens.Menu
if (!resuming) if (!resuming)
{ {
beatmap.Value = introBeatmap; beatmap.Value = initialBeatmap;
introBeatmap = null;
logo.MoveTo(new Vector2(0.5f)); logo.MoveTo(new Vector2(0.5f));
logo.ScaleTo(Vector2.One); logo.ScaleTo(Vector2.One);

View File

@ -7,7 +7,6 @@ using System.IO;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -47,7 +46,7 @@ namespace osu.Game.Screens.Menu
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
if (MenuVoice.Value && !MenuMusic.Value) if (MenuVoice.Value && !UsingThemedIntro)
welcome = audio.Samples.Get(@"welcome"); welcome = audio.Samples.Get(@"welcome");
} }
@ -62,7 +61,7 @@ namespace osu.Game.Screens.Menu
LoadComponentAsync(new TrianglesIntroSequence(logo, background) LoadComponentAsync(new TrianglesIntroSequence(logo, background)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Clock = new FramedClock(MenuMusic.Value && !(Track is TrackVirtual) ? Track : null), Clock = new FramedClock(UsingThemedIntro ? Track : null),
LoadMenu = LoadMenu LoadMenu = LoadMenu
}, t => }, t =>
{ {