From fcf9a599ddbcb6b83fffdd034bd2f32f46fb79e1 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 24 Mar 2017 14:24:10 +0900 Subject: [PATCH] Implement taiko auto replays. --- osu.Game.Modes.Taiko/LegacyTaikoReplay.cs | 4 + osu.Game.Modes.Taiko/TaikoAutoReplay.cs | 121 ++++++++++++++++++ .../osu.Game.Modes.Taiko.csproj | 1 + 3 files changed, 126 insertions(+) create mode 100644 osu.Game.Modes.Taiko/TaikoAutoReplay.cs diff --git a/osu.Game.Modes.Taiko/LegacyTaikoReplay.cs b/osu.Game.Modes.Taiko/LegacyTaikoReplay.cs index 3e6ccd4ac7..0b59c9ddd4 100644 --- a/osu.Game.Modes.Taiko/LegacyTaikoReplay.cs +++ b/osu.Game.Modes.Taiko/LegacyTaikoReplay.cs @@ -11,6 +11,10 @@ namespace osu.Game.Modes.Taiko { public class LegacyTaikoReplay : LegacyReplay { + protected LegacyTaikoReplay() + { + } + public LegacyTaikoReplay(StreamReader reader) : base(reader) { diff --git a/osu.Game.Modes.Taiko/TaikoAutoReplay.cs b/osu.Game.Modes.Taiko/TaikoAutoReplay.cs new file mode 100644 index 0000000000..2a5cac419a --- /dev/null +++ b/osu.Game.Modes.Taiko/TaikoAutoReplay.cs @@ -0,0 +1,121 @@ +// 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.Modes.Taiko.Objects; +using osu.Game.Modes.Objects.Types; + +namespace osu.Game.Modes.Taiko +{ + public class TaikoAutoReplay : LegacyTaikoReplay + { + private readonly List hitObjects; + + public TaikoAutoReplay(List hitObjects) + { + this.hitObjects = hitObjects; + + createAutoReplay(); + } + + private void createAutoReplay() + { + bool hitButton = true; + + Frames.Add(new LegacyReplayFrame(-100000, 320, 240, LegacyButtonState.None)); + Frames.Add(new LegacyReplayFrame(hitObjects[0].StartTime - 1000, 320, 240, LegacyButtonState.None)); + + for (int i = 0; i < hitObjects.Count; i++) + { + TaikoHitObject h = hitObjects[i]; + + LegacyButtonState button; + + IHasEndTime endTimeData = h as IHasEndTime; + double endTime = endTimeData?.EndTime ?? h.StartTime; + + Bash sp = h as Bash; + if (sp != null) + { + int d = 0; + int count = 0; + int req = sp.RequiredHits; + double hitRate = sp.Duration / req; + for (double j = h.StartTime; j < endTime; j += hitRate) + { + switch (d) + { + default: + button = LegacyButtonState.Left1; + break; + case 1: + button = LegacyButtonState.Right1; + break; + case 2: + button = LegacyButtonState.Left2; + break; + case 3: + button = LegacyButtonState.Right2; + break; + } + + Frames.Add(new LegacyReplayFrame(j, 0, 0, button)); + d = (d + 1) % 4; + if (++count > req) + break; + } + } + else if (h is DrumRoll) + { + DrumRoll d = h as DrumRoll; + + double delay = d.TickTimeDistance; + + double time = d.StartTime; + + for (int j = 0; j < d.TotalTicks; j++) + { + Frames.Add(new LegacyReplayFrame((int)time, 0, 0, hitButton ? LegacyButtonState.Left1 : LegacyButtonState.Left2)); + time += delay; + hitButton = !hitButton; + } + } + else + { + Hit hit = h as Hit; + + if (hit.Type == HitType.Centre) + { + if (h.Accented) + button = LegacyButtonState.Right1 | LegacyButtonState.Right2; + else + button = hitButton ? LegacyButtonState.Right1 : LegacyButtonState.Right2; + } + else + { + if (h.Accented) + button = LegacyButtonState.Left1 | LegacyButtonState.Left2; + else + button = hitButton ? LegacyButtonState.Left1 : LegacyButtonState.Left2; + } + + Frames.Add(new LegacyReplayFrame(h.StartTime, 0, 0, button)); + } + + Frames.Add(new LegacyReplayFrame(endTime + 1, 0, 0, LegacyButtonState.None)); + + if (i < hitObjects.Count - 1) + { + double waitTime = hitObjects[i + 1].StartTime - 1000; + if (waitTime > endTime) + Frames.Add(new LegacyReplayFrame(waitTime, 0, 0, LegacyButtonState.None)); + } + + hitButton = !hitButton; + } + + //Player.currentScore.Replay = InputManager.ReplayScore.Replay; + //Player.currentScore.PlayerName = "mekkadosu!"; + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj index f3d8c5b2d6..dde92240d1 100644 --- a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj +++ b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj @@ -59,6 +59,7 @@ +