diff --git a/osu.Game.Modes.Osu/OsuAutoReplay.cs b/osu.Game.Modes.Osu/OsuAutoReplay.cs index cc5859602a..ae85bd72d8 100644 --- a/osu.Game.Modes.Osu/OsuAutoReplay.cs +++ b/osu.Game.Modes.Osu/OsuAutoReplay.cs @@ -15,7 +15,7 @@ using osu.Game.Modes.Replays; namespace osu.Game.Modes.Osu { - public class OsuAutoReplay : FramedReplay + public class OsuAutoReplay : Replay { private static readonly Vector2 spinner_centre = new Vector2(256, 192); diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index 096c0dcc29..5ce3ff273e 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -101,7 +101,7 @@ namespace osu.Game.Database using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) - score.Replay = score.CreateLegacyReplayFrom(reader); + score.Replay = score.CreateReplay(reader); } } diff --git a/osu.Game/Modes/Mods/Mod.cs b/osu.Game/Modes/Mods/Mod.cs index c53c6faa21..b6f09b8506 100644 --- a/osu.Game/Modes/Mods/Mod.cs +++ b/osu.Game/Modes/Mods/Mod.cs @@ -157,7 +157,7 @@ namespace osu.Game.Modes.Mods public void Apply(HitRenderer hitRenderer) { - hitRenderer.InputManager.ReplayInputHandler = CreateReplayScore(hitRenderer.Beatmap)?.Replay?.CreateInputHandler(); + hitRenderer.SetReplay(CreateReplayScore(hitRenderer.Beatmap)?.Replay); } } diff --git a/osu.Game/Modes/Replays/FramedReplay.cs b/osu.Game/Modes/Replays/FramedReplay.cs deleted file mode 100644 index 53b258e28b..0000000000 --- a/osu.Game/Modes/Replays/FramedReplay.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Collections.Generic; -using osu.Game.Input.Handlers; - -namespace osu.Game.Modes.Replays -{ - public abstract class FramedReplay : Replay - { - protected List Frames = new List(); - - public override ReplayInputHandler CreateInputHandler() => new FramedReplayInputHandler(Frames); - } -} \ No newline at end of file diff --git a/osu.Game/Modes/Replays/FramedReplayInputHandler.cs b/osu.Game/Modes/Replays/FramedReplayInputHandler.cs index d72c023539..ae20ece515 100644 --- a/osu.Game/Modes/Replays/FramedReplayInputHandler.cs +++ b/osu.Game/Modes/Replays/FramedReplayInputHandler.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; using System.Collections.Generic; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Input; @@ -17,18 +20,20 @@ namespace osu.Game.Modes.Replays /// public class FramedReplayInputHandler : ReplayInputHandler { - private readonly List replayContent; + private readonly Replay replay; - public ReplayFrame CurrentFrame => !hasFrames ? null : replayContent[currentFrameIndex]; - public ReplayFrame NextFrame => !hasFrames ? null : replayContent[nextFrameIndex]; + protected List Frames => replay.Frames; + + public ReplayFrame CurrentFrame => !hasFrames ? null : Frames[currentFrameIndex]; + public ReplayFrame NextFrame => !hasFrames ? null : Frames[nextFrameIndex]; private int currentFrameIndex; - private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, replayContent.Count - 1); + private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, Frames.Count - 1); - public FramedReplayInputHandler(List replayContent) + public FramedReplayInputHandler(Replay replay) { - this.replayContent = replayContent; + this.replay = replay; } private bool advanceFrame() @@ -75,7 +80,7 @@ namespace osu.Game.Modes.Replays }; } - public bool AtLastFrame => currentFrameIndex == replayContent.Count - 1; + public bool AtLastFrame => currentFrameIndex == Frames.Count - 1; public bool AtFirstFrame => currentFrameIndex == 0; public Vector2 Size => new Vector2(512, 384); @@ -91,7 +96,7 @@ namespace osu.Game.Modes.Replays /// public bool FrameAccuratePlayback = true; - private bool hasFrames => replayContent.Count > 0; + private bool hasFrames => Frames.Count > 0; private bool inImportantSection => FrameAccuratePlayback && diff --git a/osu.Game/Modes/Replays/LegacyFramedReplay.cs b/osu.Game/Modes/Replays/LegacyFramedReplay.cs deleted file mode 100644 index 3b99614f5e..0000000000 --- a/osu.Game/Modes/Replays/LegacyFramedReplay.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.IO; -using osu.Game.IO.Legacy; - -namespace osu.Game.Modes.Replays -{ - /// - /// Reads a replay from a legacy replay file (.osr v1) - /// - public class LegacyFramedReplay : FramedReplay - { - public LegacyFramedReplay(StreamReader reader) - { - float lastTime = 0; - - foreach (var l in reader.ReadToEnd().Split(',')) - { - var split = l.Split('|'); - - if (split.Length < 4 || float.Parse(split[0]) < 0) continue; - - lastTime += float.Parse(split[0]); - - Frames.Add(new ReplayFrame( - lastTime, - float.Parse(split[1]), - 384 - float.Parse(split[2]), - (ReplayButtonState)int.Parse(split[3]) - )); - } - } - - public class LegacyReplayFrame : ReplayFrame - { - public LegacyReplayFrame(Stream s) : this(new SerializationReader(s)) - { - } - - public LegacyReplayFrame(SerializationReader sr) - { - ButtonState = (ReplayButtonState)sr.ReadByte(); - - byte bt = sr.ReadByte(); - if (bt > 0)//Handle Pre-Taiko compatible replays. - ButtonState = ReplayButtonState.Right1; - - MouseX = sr.ReadSingle(); - MouseY = sr.ReadSingle(); - Time = sr.ReadInt32(); - } - - public void ReadFromStream(SerializationReader sr) - { - throw new NotImplementedException(); - } - - public void WriteToStream(SerializationWriter sw) - { - sw.Write((byte)ButtonState); - sw.Write((byte)0); - sw.Write(MouseX); - sw.Write(MouseY); - sw.Write(Time); - } - } - } -} diff --git a/osu.Game/Modes/Replays/Replay.cs b/osu.Game/Modes/Replays/Replay.cs index c1ae952b77..62f60358e0 100644 --- a/osu.Game/Modes/Replays/Replay.cs +++ b/osu.Game/Modes/Replays/Replay.cs @@ -1,12 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Game.Input.Handlers; +using System.Collections.Generic; namespace osu.Game.Modes.Replays { - public abstract class Replay + public class Replay { - public virtual ReplayInputHandler CreateInputHandler() => null; + public List Frames = new List(); } } \ No newline at end of file diff --git a/osu.Game/Modes/Scoring/Score.cs b/osu.Game/Modes/Scoring/Score.cs index 70777a77ef..c998b11f77 100644 --- a/osu.Game/Modes/Scoring/Score.cs +++ b/osu.Game/Modes/Scoring/Score.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Database; using osu.Game.Modes.Mods; @@ -46,11 +47,34 @@ namespace osu.Game.Modes.Scoring public DateTime Date; /// - /// Creates a legacy replay which is read from a stream. + /// Creates a replay which is read from a stream. /// /// The stream reader. /// The replay. - public virtual Replay CreateLegacyReplayFrom(StreamReader reader) => new LegacyFramedReplay(reader); + public virtual Replay CreateReplay(StreamReader reader) + { + var frames = new List(); + + float lastTime = 0; + + foreach (var l in reader.ReadToEnd().Split(',')) + { + var split = l.Split('|'); + + if (split.Length < 4 || float.Parse(split[0]) < 0) continue; + + lastTime += float.Parse(split[0]); + + frames.Add(new ReplayFrame( + lastTime, + float.Parse(split[1]), + 384 - float.Parse(split[2]), + (ReplayButtonState)int.Parse(split[3]) + )); + } + + return new Replay { Frames = frames }; + } // [JsonProperty(@"count50")] 0, //[JsonProperty(@"count100")] 0, diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index 3d108b895d..8581d12244 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using osu.Game.Modes.Replays; using osu.Game.Modes.Scoring; namespace osu.Game.Modes.UI @@ -68,6 +69,10 @@ namespace osu.Game.Modes.UI /// /// The input manager. protected virtual KeyConversionInputManager CreateKeyConversionInputManager() => new KeyConversionInputManager(); + + protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); + + public void SetReplay(Replay replay) => InputManager.ReplayInputHandler = CreateReplayInputHandler(replay); } /// diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 66196670b8..8ac86c5c67 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -125,7 +125,7 @@ namespace osu.Game Beatmap.Value = BeatmapDatabase.GetWorkingBeatmap(s.Beatmap); - menu.Push(new PlayerLoader(new Player { ReplayInputHandler = s.Replay.CreateInputHandler() })); + menu.Push(new PlayerLoader(new ReplayPlayer(s.Replay))); } protected override void LoadComplete() diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 0554c0e77b..73d397b24b 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -15,7 +15,6 @@ using osu.Framework.Screens; using osu.Framework.Timing; using osu.Game.Configuration; using osu.Game.Database; -using osu.Game.Input.Handlers; using osu.Game.Modes; using osu.Game.Modes.UI; using osu.Game.Screens.Backgrounds; @@ -34,7 +33,7 @@ namespace osu.Game.Screens.Play internal override bool HasLocalCursorDisplayed => !hasReplayLoaded && !IsPaused; - private bool hasReplayLoaded => hitRenderer.InputManager.ReplayInputHandler != null; + private bool hasReplayLoaded => HitRenderer.InputManager.ReplayInputHandler != null; public BeatmapInfo BeatmapInfo; @@ -53,7 +52,7 @@ namespace osu.Game.Screens.Play private Ruleset ruleset; private ScoreProcessor scoreProcessor; - private HitRenderer hitRenderer; + protected HitRenderer HitRenderer; private Bindable dimLevel; private SkipButton skipButton; @@ -112,9 +111,9 @@ namespace osu.Game.Screens.Play }); ruleset = Ruleset.GetRuleset(Beatmap.PlayMode); - hitRenderer = ruleset.CreateHitRendererWith(Beatmap); + HitRenderer = ruleset.CreateHitRendererWith(Beatmap); - scoreProcessor = hitRenderer.CreateScoreProcessor(); + scoreProcessor = HitRenderer.CreateScoreProcessor(); hudOverlay = new StandardHudOverlay(); hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys()); @@ -133,13 +132,10 @@ namespace osu.Game.Screens.Play }; - if (ReplayInputHandler != null) - hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler; - - hudOverlay.BindHitRenderer(hitRenderer); + hudOverlay.BindHitRenderer(HitRenderer); //bind HitRenderer to ScoreProcessor and ourselves (for a pass situation) - hitRenderer.OnAllJudged += onCompletion; + HitRenderer.OnAllJudged += onCompletion; //bind ScoreProcessor to ourselves (for a fail situation) scoreProcessor.Failed += onFail; @@ -152,7 +148,7 @@ namespace osu.Game.Screens.Play Clock = interpolatedSourceClock, Children = new Drawable[] { - hitRenderer, + HitRenderer, skipButton = new SkipButton { Alpha = 0 @@ -336,8 +332,6 @@ namespace osu.Game.Screens.Play private Bindable mouseWheelDisabled; - public ReplayInputHandler ReplayInputHandler; - protected override bool OnWheel(InputState state) => mouseWheelDisabled.Value && !IsPaused; } } \ No newline at end of file diff --git a/osu.Game/Screens/Play/ReplayPlayer.cs b/osu.Game/Screens/Play/ReplayPlayer.cs new file mode 100644 index 0000000000..4593656a2e --- /dev/null +++ b/osu.Game/Screens/Play/ReplayPlayer.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes.Replays; + +namespace osu.Game.Screens.Play +{ + public class ReplayPlayer : Player + { + public Replay Replay; + + public ReplayPlayer(Replay replay) + { + Replay = replay; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + HitRenderer.SetReplay(Replay); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index a3ece6d5ca..0dc2da48d1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -96,10 +96,9 @@ - + - @@ -125,7 +124,6 @@ - @@ -202,6 +200,7 @@ +