Implement in player

This commit is contained in:
Dean Herbert 2020-03-23 19:31:43 +09:00
parent 14a85a84bf
commit 617149fb27
4 changed files with 42 additions and 3 deletions

View File

@ -262,6 +262,17 @@ private void addHitObject(TObject hitObject)
Playfield.Add(drawableObject);
}
public override void SetRecordTarget(Replay recordingReplay)
{
if (!(KeyBindingInputManager is IHasRecordingHandler recordingInputHandler))
throw new InvalidOperationException($"A {nameof(KeyBindingInputManager)} which supports recording is not available");
var recorder = CreateReplayRecorder(recordingReplay);
recorder.ScreenSpaceToGamefield = Playfield.ScreenSpaceToGamefield;
recordingInputHandler.Recorder = recorder;
}
public override void SetReplayScore(Score replayScore)
{
if (!(KeyBindingInputManager is IHasReplayHandler replayInputManager))
@ -472,6 +483,12 @@ public HitWindows FirstAvailableHitWindows
/// <param name="replayScore">The replay, null for local input.</param>
public abstract void SetReplayScore(Score replayScore);
/// <summary>
/// Sets a replay to be used to record gameplay.
/// </summary>
/// <param name="recordingReplay">The target to be recorded to.</param>
public abstract void SetRecordTarget(Replay recordingReplay);
/// <summary>
/// Invoked when the interactive user requests resuming from a paused state.
/// Allows potentially delaying the resume process until an interaction is performed.

View File

@ -24,7 +24,7 @@
namespace osu.Game.Rulesets.UI
{
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler
where T : struct
{
private ReplayRecorder recorder;
@ -184,6 +184,11 @@ public interface IHasReplayHandler
ReplayInputHandler ReplayInputHandler { get; set; }
}
public interface IHasRecordingHandler
{
public ReplayRecorder Recorder { set; }
}
/// <summary>
/// Supports attaching a <see cref="KeyCounterDisplay"/>.
/// Keys will be populated automatically and a receptor will be injected inside.

View File

@ -19,6 +19,7 @@
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
@ -118,6 +119,23 @@ public Player(bool allowPause = true, bool showResults = true)
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
protected override void LoadComplete()
{
base.LoadComplete();
PrepareReplay();
}
private Replay recordingReplay;
/// <summary>
/// Run any recording / playback setup for replays.
/// </summary>
protected virtual void PrepareReplay()
{
DrawableRuleset.SetRecordTarget(recordingReplay = new Replay());
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config)
{

View File

@ -18,9 +18,8 @@ public ReplayPlayer(Score score, bool allowPause = true, bool showResults = true
this.score = score;
}
protected override void LoadComplete()
protected override void PrepareReplay()
{
base.LoadComplete();
DrawableRuleset?.SetReplayScore(score);
}