Merge branch 'framed-replay-handler-fixes' into better-player-flags

This commit is contained in:
Dean Herbert 2019-03-28 12:45:25 +09:00
commit 467ee12edf
2 changed files with 9 additions and 28 deletions

View File

@ -18,16 +18,18 @@ public OsuFramedReplayInputHandler(Replay replay)
{
}
protected override bool IsImportant(OsuReplayFrame frame) => frame.Actions.Any();
protected override bool IsImportant(OsuReplayFrame frame) => frame?.Actions.Any() ?? false;
protected Vector2? Position
{
get
{
if (!HasFrames)
var frame = CurrentFrame;
if (frame == null)
return null;
return Interpolation.ValueAt(CurrentTime, CurrentFrame.Position, NextFrame.Position, CurrentFrame.Time, NextFrame.Time);
return Interpolation.ValueAt(CurrentTime, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time);
}
}
@ -41,7 +43,7 @@ public override List<IInput> GetPendingInputs()
},
new ReplayState<OsuAction>
{
PressedActions = CurrentFrame.Actions
PressedActions = CurrentFrame?.Actions ?? new List<OsuAction>()
}
};
}

View File

@ -7,7 +7,6 @@
using osu.Game.Input.Handlers;
using osu.Game.Replays;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Replays
{
@ -22,12 +21,12 @@ public abstract class FramedReplayInputHandler<TFrame> : ReplayInputHandler
protected List<ReplayFrame> Frames => replay.Frames;
public TFrame CurrentFrame => !HasFrames ? null : (TFrame)Frames[currentFrameIndex];
public TFrame CurrentFrame => !HasFrames || !currentFrameIndex.HasValue ? null : (TFrame)Frames[currentFrameIndex.Value];
public TFrame NextFrame => !HasFrames ? null : (TFrame)Frames[nextFrameIndex];
private int currentFrameIndex;
private int? currentFrameIndex;
private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, Frames.Count - 1);
private int nextFrameIndex => currentFrameIndex.HasValue ? MathHelper.Clamp(currentFrameIndex.Value + (currentDirection > 0 ? 1 : -1), 0, Frames.Count - 1) : 0;
protected FramedReplayInputHandler(Replay replay)
{
@ -47,9 +46,6 @@ private bool advanceFrame()
public override List<IInput> GetPendingInputs() => new List<IInput>();
public bool AtLastFrame => currentFrameIndex == Frames.Count - 1;
public bool AtFirstFrame => currentFrameIndex == 0;
private const double sixty_frame_time = 1000.0 / 60;
protected double CurrentTime { get; private set; }
@ -106,22 +102,5 @@ private bool advanceFrame()
return CurrentTime = time;
}
protected class ReplayMouseState : osu.Framework.Input.States.MouseState
{
public ReplayMouseState(Vector2 position)
{
Position = position;
}
}
protected class ReplayKeyboardState : osu.Framework.Input.States.KeyboardState
{
public ReplayKeyboardState(List<Key> keys)
{
foreach (var key in keys)
Keys.Add(key);
}
}
}
}