From 33fdc2c1d6210898150726457adfe62e48509937 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 Jan 2018 18:35:28 +0900 Subject: [PATCH 1/2] Add very basic replay handling --- osu.Game.Rulesets.Catch/CatchInputManager.cs | 3 +- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../Mods/CatchModAutoplay.cs | 24 +++++++++ .../Replays/CatchAutoGenerator.cs | 54 +++++++++++++++++++ .../Replays/CatchFramedReplayInputHandler.cs | 32 +++++++++++ .../Replays/CatchReplayFrame.cs | 17 ++++++ .../UI/CatchRulesetContainer.cs | 4 ++ osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 17 +++++- .../osu.Game.Rulesets.Catch.csproj | 4 ++ 9 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs create mode 100644 osu.Game.Rulesets.Catch/Replays/CatchAutoGenerator.cs create mode 100644 osu.Game.Rulesets.Catch/Replays/CatchFramedReplayInputHandler.cs create mode 100644 osu.Game.Rulesets.Catch/Replays/CatchReplayFrame.cs diff --git a/osu.Game.Rulesets.Catch/CatchInputManager.cs b/osu.Game.Rulesets.Catch/CatchInputManager.cs index d1851d31bf..f57952f95e 100644 --- a/osu.Game.Rulesets.Catch/CatchInputManager.cs +++ b/osu.Game.Rulesets.Catch/CatchInputManager.cs @@ -22,6 +22,7 @@ public enum CatchAction [Description("Move right")] MoveRight, [Description("Engage dash")] - Dash + Dash, + PositionUpdate } } diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 0d52046485..08bc94863b 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -81,7 +81,7 @@ public override IEnumerable GetModsFor(ModType type) { Mods = new Mod[] { - new ModAutoplay(), + new CatchModAutoplay(), new ModCinema(), }, }, diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs new file mode 100644 index 0000000000..8ff08ab825 --- /dev/null +++ b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Catch.Replays; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Users; + +namespace osu.Game.Rulesets.Catch.Mods +{ + public class CatchModAutoplay : ModAutoplay + { + protected override Score CreateReplayScore(Beatmap beatmap) + { + return new Score + { + User = new User { Username = "osu!salad!" }, + Replay = new CatchAutoGenerator(beatmap).Generate(), + }; + } + } +} diff --git a/osu.Game.Rulesets.Catch/Replays/CatchAutoGenerator.cs b/osu.Game.Rulesets.Catch/Replays/CatchAutoGenerator.cs new file mode 100644 index 0000000000..bc53e6e869 --- /dev/null +++ b/osu.Game.Rulesets.Catch/Replays/CatchAutoGenerator.cs @@ -0,0 +1,54 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Replays; +using osu.Game.Users; + +namespace osu.Game.Rulesets.Catch.Replays +{ + internal class CatchAutoGenerator : AutoGenerator + { + public const double RELEASE_DELAY = 20; + + public CatchAutoGenerator(Beatmap beatmap) + : base(beatmap) + { + Replay = new Replay { User = new User { Username = @"Autoplay" } }; + } + + protected Replay Replay; + + public override Replay Generate() + { + // Todo: Realistically this shouldn't be needed, but the first frame is skipped with the way replays are currently handled + Replay.Frames.Add(new CatchReplayFrame(-100000, 0)); + + foreach (var obj in Beatmap.HitObjects) + { + switch (obj) + { + case Fruit _: + Replay.Frames.Add(new CatchReplayFrame(obj.StartTime, obj.X)); + break; + } + + foreach (var nestedObj in obj.NestedHitObjects.Cast()) + { + switch (nestedObj) + { + case BananaShower.Banana _: + case TinyDroplet _: + case Droplet _: + Replay.Frames.Add(new CatchReplayFrame(nestedObj.StartTime, nestedObj.X)); + break; + } + } + } + + return Replay; + } + } +} diff --git a/osu.Game.Rulesets.Catch/Replays/CatchFramedReplayInputHandler.cs b/osu.Game.Rulesets.Catch/Replays/CatchFramedReplayInputHandler.cs new file mode 100644 index 0000000000..146e31fa69 --- /dev/null +++ b/osu.Game.Rulesets.Catch/Replays/CatchFramedReplayInputHandler.cs @@ -0,0 +1,32 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using osu.Framework.Input; +using osu.Game.Rulesets.Replays; + +namespace osu.Game.Rulesets.Catch.Replays +{ + public class CatchFramedReplayInputHandler : FramedReplayInputHandler + { + public CatchFramedReplayInputHandler(Replay replay) + : base(replay) + { + } + + public override List GetPendingStates() => new List + { + new CatchReplayState + { + PressedActions = new List { CatchAction.PositionUpdate }, + CatcherX = ((CatchReplayFrame)CurrentFrame).MouseX + }, + new CatchReplayState { PressedActions = new List() }, + }; + + public class CatchReplayState : ReplayState + { + public float? CatcherX { get; set; } + } + } +} diff --git a/osu.Game.Rulesets.Catch/Replays/CatchReplayFrame.cs b/osu.Game.Rulesets.Catch/Replays/CatchReplayFrame.cs new file mode 100644 index 0000000000..c47f60ec3c --- /dev/null +++ b/osu.Game.Rulesets.Catch/Replays/CatchReplayFrame.cs @@ -0,0 +1,17 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Replays; + +namespace osu.Game.Rulesets.Catch.Replays +{ + public class CatchReplayFrame : ReplayFrame + { + public override bool IsImportant => MouseX > 0; + + public CatchReplayFrame(double time, float? x = null) + : base(time, x ?? -1, null, ReplayButtonState.None) + { + } + } +} diff --git a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs index a146014ca4..08808a445e 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs @@ -6,8 +6,10 @@ using osu.Game.Rulesets.Catch.Beatmaps; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawable; +using osu.Game.Rulesets.Catch.Replays; using osu.Game.Rulesets.Catch.Scoring; using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; @@ -23,6 +25,8 @@ public CatchRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isFor public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(this); + protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new CatchFramedReplayInputHandler(replay); + protected override BeatmapProcessor CreateBeatmapProcessor() => new CatchBeatmapProcessor(); protected override BeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index c70cb15b40..1837086d9c 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -13,6 +13,7 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects.Drawable; +using osu.Game.Rulesets.Catch.Replays; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; @@ -21,7 +22,7 @@ namespace osu.Game.Rulesets.Catch.UI { - public class CatcherArea : Container + public class CatcherArea : Container, IKeyBindingHandler { public const float CATCHER_SIZE = 172; @@ -72,6 +73,20 @@ public void OnJudgement(DrawableCatchHitObject fruit, Judgement judgement) } } + public bool OnPressed(CatchAction action) + { + if (action != CatchAction.PositionUpdate) return false; + + CatchFramedReplayInputHandler.CatchReplayState state = (CatchFramedReplayInputHandler.CatchReplayState)GetContainingInputManager().CurrentState; + + if (state.CatcherX.HasValue) + MovableCatcher.X = state.CatcherX.Value; + + return true; + } + + public bool OnReleased(CatchAction action) => false; + public bool AttemptCatch(CatchHitObject obj) => MovableCatcher.AttemptCatch(obj); public class Catcher : Container, IKeyBindingHandler diff --git a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj index 566ec385fc..4d17fa6570 100644 --- a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj +++ b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj @@ -60,11 +60,15 @@ + + + + From 90bcec42d7ef99a48676b0d171f41203b5b30857 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 12 Jan 2018 20:48:58 +0900 Subject: [PATCH 2/2] Remove unused using --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 08bc94863b..5e70239c7c 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -10,7 +10,6 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; -using osu.Game.Rulesets.Catch.Objects; namespace osu.Game.Rulesets.Catch {