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

Ensure CurrentTrack is never null

This commit is contained in:
smoogipoo 2020-08-07 19:43:16 +09:00
parent bf21fdd6da
commit 61b632516e
10 changed files with 8 additions and 22 deletions

View File

@ -95,10 +95,7 @@ namespace osu.Game.Tests.Visual.Editing
base.Update();
if (musicController.TrackLoaded)
{
Debug.Assert(musicController.CurrentTrack != null);
marker.X = (float)(editorClock.CurrentTime / musicController.CurrentTrack.Length);
}
}
}

View File

@ -136,8 +136,8 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("Wait for music controller", () => Game.MusicController.IsLoaded);
AddStep("Seek close to end", () =>
{
Game.MusicController.SeekTo(MusicController.CurrentTrack.AsNonNull().Length - 1000);
MusicController.CurrentTrack.AsNonNull().Completed += () => trackCompleted = true;
Game.MusicController.SeekTo(MusicController.CurrentTrack.Length - 1000);
MusicController.CurrentTrack.Completed += () => trackCompleted = true;
});
AddUntilStep("Track was completed", () => trackCompleted);

View File

@ -169,7 +169,7 @@ namespace osu.Game.Tests.Visual.UserInterface
if (timingPoints.Count == 0) return 0;
if (timingPoints[^1] == current)
return (int)Math.Ceiling((musicController.CurrentTrack.AsNonNull().Length - current.Time) / current.BeatLength);
return (int)Math.Ceiling((musicController.CurrentTrack.Length - current.Time) / current.BeatLength);
return (int)Math.Ceiling((getNextTimingPoint(current).Time - current.Time) / current.BeatLength);
}

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
@ -65,8 +64,7 @@ namespace osu.Game.Overlays
[Resolved(canBeNull: true)]
private OnScreenDisplay onScreenDisplay { get; set; }
[CanBeNull]
public DrawableTrack CurrentTrack { get; private set; }
public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000));
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
@ -312,7 +310,7 @@ namespace osu.Game.Overlays
current = beatmap.NewValue;
if (!beatmap.OldValue.BeatmapInfo.AudioEquals(current?.BeatmapInfo))
if (CurrentTrack == null || !beatmap.OldValue.BeatmapInfo.AudioEquals(current?.BeatmapInfo))
changeTrack();
TrackChanged?.Invoke(current, direction);

View File

@ -58,7 +58,6 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
return;
}
Debug.Assert(musicController.CurrentTrack != null);
content.RelativeChildSize = new Vector2((float)Math.Max(1, musicController.CurrentTrack.Length), 1);
}

View File

@ -44,7 +44,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
for (var i = 0; i < beatmap.ControlPointInfo.TimingPoints.Count; i++)
{
var point = beatmap.ControlPointInfo.TimingPoints[i];
var until = i + 1 < beatmap.ControlPointInfo.TimingPoints.Count ? beatmap.ControlPointInfo.TimingPoints[i + 1].Time : musicController.CurrentTrack.AsNonNull().Length;
var until = i + 1 < beatmap.ControlPointInfo.TimingPoints.Count ? beatmap.ControlPointInfo.TimingPoints[i + 1].Time : musicController.CurrentTrack.Length;
int beat = 0;

View File

@ -109,14 +109,14 @@ namespace osu.Game.Screens.Menu
private void updateAmplitudes()
{
var effect = beatmap.Value.BeatmapLoaded && musicController.TrackLoaded
? beatmap.Value.Beatmap?.ControlPointInfo.EffectPointAt(musicController.CurrentTrack.AsNonNull().CurrentTime)
? beatmap.Value.Beatmap?.ControlPointInfo.EffectPointAt(musicController.CurrentTrack.CurrentTime)
: null;
for (int i = 0; i < temporalAmplitudes.Length; i++)
temporalAmplitudes[i] = 0;
if (musicController.TrackLoaded)
addAmplitudesFromSource(musicController.CurrentTrack.AsNonNull());
addAmplitudesFromSource(musicController.CurrentTrack);
foreach (var source in amplitudeSources)
addAmplitudesFromSource(source);

View File

@ -179,8 +179,6 @@ namespace osu.Game.Screens.Menu
if (last is IntroScreen && music.TrackLoaded)
{
Debug.Assert(music.CurrentTrack != null);
if (!music.CurrentTrack.IsRunning)
{
music.CurrentTrack.Seek(metadata.PreviewTime != -1 ? metadata.PreviewTime : 0.4f * music.CurrentTrack.Length);

View File

@ -170,10 +170,7 @@ namespace osu.Game.Tests.Visual
rulesetDependencies?.Dispose();
if (MusicController?.TrackLoaded == true)
{
Debug.Assert(MusicController.CurrentTrack != null);
MusicController.CurrentTrack.Stop();
}
if (contextFactory.IsValueCreated)
contextFactory.Value.ResetDatabase();

View File

@ -16,10 +16,7 @@ namespace osu.Game.Tests.Visual
// note that this will override any mod rate application
if (MusicController.TrackLoaded)
{
Debug.Assert(MusicController.CurrentTrack != null);
MusicController.CurrentTrack.Tempo.Value = Clock.Rate;
}
}
}
}