Move implementation into resetTrack for safety

This commit is contained in:
Dean Herbert 2019-11-08 18:51:01 +09:00
parent e904928314
commit a849bc0746
1 changed files with 17 additions and 10 deletions

View File

@ -69,14 +69,6 @@ private void load(OsuColour colours, GameHost host)
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false }; clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
clock.ChangeSource(sourceClock); clock.ChangeSource(sourceClock);
if (Beatmap.Value.Beatmap.HitObjects.Count > 0)
{
double targetTime = Beatmap.Value.Beatmap.HitObjects[0].StartTime;
double beatLength = Beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(targetTime).BeatLength;
clock.Seek(Math.Max(0, targetTime - beatLength));
}
dependencies.CacheAs<IFrameBasedClock>(clock); dependencies.CacheAs<IFrameBasedClock>(clock);
dependencies.CacheAs<IAdjustableClock>(clock); dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.Cache(beatDivisor); dependencies.Cache(beatDivisor);
@ -249,7 +241,8 @@ public override void OnEntering(IScreen last)
base.OnEntering(last); base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500); Background.FadeColour(Color4.DarkGray, 500);
resetTrack();
resetTrack(true);
} }
public override bool OnExiting(IScreen next) public override bool OnExiting(IScreen next)
@ -260,10 +253,24 @@ public override bool OnExiting(IScreen next)
return base.OnExiting(next); return base.OnExiting(next);
} }
private void resetTrack() private void resetTrack(bool seekToStart = false)
{ {
Beatmap.Value.Track?.ResetSpeedAdjustments(); Beatmap.Value.Track?.ResetSpeedAdjustments();
Beatmap.Value.Track?.Stop(); Beatmap.Value.Track?.Stop();
if (seekToStart)
{
double targetTime = 0;
if (Beatmap.Value.Beatmap.HitObjects.Count > 0)
{
// seek to one beat length before the first hitobject
targetTime = Beatmap.Value.Beatmap.HitObjects[0].StartTime;
targetTime -= Beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(targetTime).BeatLength;
}
clock.Seek(Math.Max(0, targetTime));
}
} }
private void exportBeatmap() => host.OpenFileExternally(Beatmap.Value.Save()); private void exportBeatmap() => host.OpenFileExternally(Beatmap.Value.Save());