mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 12:32:58 +08:00
Merge pull request #9230 from peppy/startup-safety
Improve handling of missing intro beatmap / files
This commit is contained in:
commit
ad28f84335
@ -79,6 +79,8 @@ namespace osu.Game.Beatmaps
|
||||
beatmaps = (BeatmapStore)ModelStore;
|
||||
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
|
||||
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
|
||||
beatmaps.ItemRemoved += removeWorkingCache;
|
||||
beatmaps.ItemUpdated += removeWorkingCache;
|
||||
|
||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||
}
|
||||
@ -213,9 +215,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
||||
if (working != null)
|
||||
workingCache.Remove(working);
|
||||
removeWorkingCache(info);
|
||||
}
|
||||
|
||||
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
|
||||
@ -417,6 +417,24 @@ namespace osu.Game.Beatmaps
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
||||
private void removeWorkingCache(BeatmapSetInfo info)
|
||||
{
|
||||
if (info.Beatmaps == null) return;
|
||||
|
||||
foreach (var b in info.Beatmaps)
|
||||
removeWorkingCache(b);
|
||||
}
|
||||
|
||||
private void removeWorkingCache(BeatmapInfo info)
|
||||
{
|
||||
lock (workingCache)
|
||||
{
|
||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
||||
if (working != null)
|
||||
workingCache.Remove(working);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
onlineLookupQueue?.Dispose();
|
||||
|
@ -41,9 +41,9 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
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);
|
||||
|
||||
@ -58,6 +58,11 @@ namespace osu.Game.Screens.Menu
|
||||
[Resolved]
|
||||
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]
|
||||
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
|
||||
{
|
||||
@ -71,29 +76,45 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
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)
|
||||
{
|
||||
var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal);
|
||||
|
||||
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.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;
|
||||
|
||||
setInfo.Protected = true;
|
||||
beatmaps.Update(setInfo);
|
||||
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
|
||||
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
|
||||
}
|
||||
}
|
||||
|
||||
introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
|
||||
Track = introBeatmap.Track;
|
||||
// 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.
|
||||
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)
|
||||
@ -119,7 +140,7 @@ namespace osu.Game.Screens.Menu
|
||||
public override void OnSuspending(IScreen next)
|
||||
{
|
||||
base.OnSuspending(next);
|
||||
Track = null;
|
||||
initialBeatmap = null;
|
||||
}
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
||||
@ -127,7 +148,7 @@ namespace osu.Game.Screens.Menu
|
||||
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.
|
||||
if (MenuMusic.Value)
|
||||
if (UsingThemedIntro)
|
||||
Track.Restart();
|
||||
}
|
||||
|
||||
@ -141,8 +162,7 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
if (!resuming)
|
||||
{
|
||||
beatmap.Value = introBeatmap;
|
||||
introBeatmap = null;
|
||||
beatmap.Value = initialBeatmap;
|
||||
|
||||
logo.MoveTo(new Vector2(0.5f));
|
||||
logo.ScaleTo(Vector2.One);
|
||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Screens.Menu
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
if (MenuVoice.Value && !MenuMusic.Value)
|
||||
if (MenuVoice.Value && !UsingThemedIntro)
|
||||
welcome = audio.Samples.Get(@"welcome");
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ namespace osu.Game.Screens.Menu
|
||||
LoadComponentAsync(new TrianglesIntroSequence(logo, background)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Clock = new FramedClock(MenuMusic.Value ? Track : null),
|
||||
Clock = new FramedClock(UsingThemedIntro ? Track : null),
|
||||
LoadMenu = LoadMenu
|
||||
}, t =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user