Restore catcher state on revert judgement result

This commit is contained in:
ekrctb 2020-12-08 15:02:55 +09:00
parent 0213f77b4b
commit cb76a2d7b5
4 changed files with 62 additions and 9 deletions

View File

@ -56,6 +56,24 @@ namespace osu.Game.Rulesets.Catch.Tests
}; };
}); });
[Test]
public void TestCatcherStateRevert()
{
DrawableCatchHitObject drawableObject = null;
JudgementResult result = null;
AddStep("catch kiai fruit", () =>
{
drawableObject = createDrawableObject(new TestKiaiFruit());
result = attemptCatch(drawableObject);
});
checkState(CatcherAnimationState.Kiai);
AddStep("revert result", () =>
{
catcher.OnRevertResult(drawableObject, result);
});
checkState(CatcherAnimationState.Idle);
}
[Test] [Test]
public void TestCatcherCatchWidth() public void TestCatcherCatchWidth()
{ {
@ -170,17 +188,19 @@ namespace osu.Game.Rulesets.Catch.Tests
private void attemptCatch(CatchHitObject hitObject, int count = 1) private void attemptCatch(CatchHitObject hitObject, int count = 1)
{ {
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
attemptCatch(createDrawableObject(hitObject));
}
private JudgementResult attemptCatch(DrawableCatchHitObject drawableObject)
{ {
var drawableObject = createDrawableObject(hitObject); drawableObject.HitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
var result = new JudgementResult(hitObject, new CatchJudgement()) var result = new CatchJudgementResult(drawableObject.HitObject, drawableObject.HitObject.CreateJudgement())
{ {
Type = catcher.CanCatch(hitObject) ? HitResult.Great : HitResult.Miss Type = catcher.CanCatch(drawableObject.HitObject) ? HitResult.Great : HitResult.Miss
}; };
catcher.OnNewResult(drawableObject, result); catcher.OnNewResult(drawableObject, result);
} return result;
} }
private DrawableCatchHitObject createDrawableObject(CatchHitObject hitObject) private DrawableCatchHitObject createDrawableObject(CatchHitObject hitObject)

View File

@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using JetBrains.Annotations;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Catch.Judgements
{
public class CatchJudgementResult : JudgementResult
{
/// <summary>
/// The catcher animation state prior to this judgement.
/// </summary>
public CatcherAnimationState CatcherAnimationState;
public CatchJudgementResult([NotNull] HitObject hitObject, [NotNull] Judgement judgement)
: base(hitObject, judgement)
{
}
}
}

View File

@ -5,7 +5,9 @@ using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Utils; using osu.Game.Utils;
@ -52,6 +54,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
public override bool RemoveWhenNotAlive => IsOnPlate; public override bool RemoveWhenNotAlive => IsOnPlate;
protected override JudgementResult CreateResult(Judgement judgement) => new CatchJudgementResult(HitObject, judgement);
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)
{ {
if (CheckPosition == null) return; if (CheckPosition == null) return;

View File

@ -14,6 +14,7 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Catch.Skinning; using osu.Game.Rulesets.Catch.Skinning;
@ -210,6 +211,9 @@ namespace osu.Game.Rulesets.Catch.UI
public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result) public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result)
{ {
var catchResult = (CatchJudgementResult)result;
catchResult.CatcherAnimationState = CurrentState;
if (!(drawableObject.HitObject is PalpableCatchHitObject hitObject)) return; if (!(drawableObject.HitObject is PalpableCatchHitObject hitObject)) return;
if (result.IsHit) if (result.IsHit)
@ -238,6 +242,8 @@ namespace osu.Game.Rulesets.Catch.UI
public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result) public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result)
{ {
var catchResult = (CatchJudgementResult)result;
updateState(catchResult.CatcherAnimationState);
} }
/// <summary> /// <summary>