diff --git a/osu.Game/Rulesets/UI/DrawableRuleset.cs b/osu.Game/Rulesets/UI/DrawableRuleset.cs
index c8af3be980..5c57a92cd1 100644
--- a/osu.Game/Rulesets/UI/DrawableRuleset.cs
+++ b/osu.Game/Rulesets/UI/DrawableRuleset.cs
@@ -262,6 +262,17 @@ namespace osu.Game.Rulesets.UI
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 @@ namespace osu.Game.Rulesets.UI
/// The replay, null for local input.
public abstract void SetReplayScore(Score replayScore);
+ ///
+ /// Sets a replay to be used to record gameplay.
+ ///
+ /// The target to be recorded to.
+ public abstract void SetRecordTarget(Replay recordingReplay);
+
///
/// Invoked when the interactive user requests resuming from a paused state.
/// Allows potentially delaying the resume process until an interaction is performed.
diff --git a/osu.Game/Rulesets/UI/RulesetInputManager.cs b/osu.Game/Rulesets/UI/RulesetInputManager.cs
index 043e0f56cc..ba30fe28d5 100644
--- a/osu.Game/Rulesets/UI/RulesetInputManager.cs
+++ b/osu.Game/Rulesets/UI/RulesetInputManager.cs
@@ -24,7 +24,7 @@ using MouseState = osu.Framework.Input.States.MouseState;
namespace osu.Game.Rulesets.UI
{
- public abstract class RulesetInputManager : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler
+ public abstract class RulesetInputManager : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler
where T : struct
{
private ReplayRecorder recorder;
@@ -184,6 +184,11 @@ namespace osu.Game.Rulesets.UI
ReplayInputHandler ReplayInputHandler { get; set; }
}
+ public interface IHasRecordingHandler
+ {
+ public ReplayRecorder Recorder { set; }
+ }
+
///
/// Supports attaching a .
/// Keys will be populated automatically and a receptor will be injected inside.
diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs
index a120963abd..8fee516f2b 100644
--- a/osu.Game/Screens/Play/Player.cs
+++ b/osu.Game/Screens/Play/Player.cs
@@ -19,6 +19,7 @@ using osu.Game.Configuration;
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 @@ namespace osu.Game.Screens.Play
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
+ protected override void LoadComplete()
+ {
+ base.LoadComplete();
+
+ PrepareReplay();
+ }
+
+ private Replay recordingReplay;
+
+ ///
+ /// Run any recording / playback setup for replays.
+ ///
+ protected virtual void PrepareReplay()
+ {
+ DrawableRuleset.SetRecordTarget(recordingReplay = new Replay());
+ }
+
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config)
{
diff --git a/osu.Game/Screens/Play/ReplayPlayer.cs b/osu.Game/Screens/Play/ReplayPlayer.cs
index b040549efc..8708b5f634 100644
--- a/osu.Game/Screens/Play/ReplayPlayer.cs
+++ b/osu.Game/Screens/Play/ReplayPlayer.cs
@@ -18,9 +18,8 @@ namespace osu.Game.Screens.Play
this.score = score;
}
- protected override void LoadComplete()
+ protected override void PrepareReplay()
{
- base.LoadComplete();
DrawableRuleset?.SetReplayScore(score);
}