mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Move catcher state changing logic to OnNewResult method
This commit is contained in:
parent
88db7823b2
commit
0213f77b4b
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -12,8 +13,11 @@ using osu.Framework.Testing;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
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.Judgements;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.Tests
|
namespace osu.Game.Rulesets.Catch.Tests
|
||||||
@ -169,7 +173,32 @@ namespace osu.Game.Rulesets.Catch.Tests
|
|||||||
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
||||||
|
|
||||||
for (var i = 0; i < count; i++)
|
for (var i = 0; i < count; i++)
|
||||||
catcher.AttemptCatch(hitObject);
|
{
|
||||||
|
var drawableObject = createDrawableObject(hitObject);
|
||||||
|
var result = new JudgementResult(hitObject, new CatchJudgement())
|
||||||
|
{
|
||||||
|
Type = catcher.CanCatch(hitObject) ? HitResult.Great : HitResult.Miss
|
||||||
|
};
|
||||||
|
catcher.OnNewResult(drawableObject, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawableCatchHitObject createDrawableObject(CatchHitObject hitObject)
|
||||||
|
{
|
||||||
|
switch (hitObject)
|
||||||
|
{
|
||||||
|
case Banana banana:
|
||||||
|
return new DrawableBanana(banana);
|
||||||
|
|
||||||
|
case Droplet droplet:
|
||||||
|
return new DrawableDroplet(droplet);
|
||||||
|
|
||||||
|
case Fruit fruit:
|
||||||
|
return new DrawableFruit(fruit);
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(hitObject));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestCatcher : Catcher
|
public class TestCatcher : Catcher
|
||||||
|
@ -58,10 +58,9 @@ namespace osu.Game.Rulesets.Catch.Tests
|
|||||||
|
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
bool caught = area.AttemptCatch(fruit);
|
|
||||||
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement())
|
area.OnNewResult(drawable, new JudgementResult(fruit, new CatchJudgement())
|
||||||
{
|
{
|
||||||
Type = caught ? HitResult.Great : HitResult.Miss
|
Type = area.MovableCatcher.CanCatch(fruit) ? HitResult.Great : HitResult.Miss
|
||||||
});
|
});
|
||||||
|
|
||||||
drawable.Expire();
|
drawable.Expire();
|
||||||
|
@ -81,7 +81,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
((DrawableCatchHitObject)d).CheckPosition = checkIfWeCanCatch;
|
((DrawableCatchHitObject)d).CheckPosition = checkIfWeCanCatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool checkIfWeCanCatch(CatchHitObject obj) => CatcherArea.AttemptCatch(obj);
|
private bool checkIfWeCanCatch(CatchHitObject obj) => CatcherArea.MovableCatcher.CanCatch(obj);
|
||||||
|
|
||||||
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
|
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
|
||||||
=> CatcherArea.OnNewResult((DrawableCatchHitObject)judgedObject, result);
|
=> CatcherArea.OnNewResult((DrawableCatchHitObject)judgedObject, result);
|
||||||
|
@ -17,6 +17,7 @@ using osu.Game.Configuration;
|
|||||||
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;
|
||||||
|
using osu.Game.Rulesets.Judgements;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -190,11 +191,9 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
internal static float CalculateCatchWidth(BeatmapDifficulty difficulty) => CalculateCatchWidth(calculateScale(difficulty));
|
internal static float CalculateCatchWidth(BeatmapDifficulty difficulty) => CalculateCatchWidth(calculateScale(difficulty));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Let the catcher attempt to catch a fruit.
|
/// Determine if this catcher can catch a <see cref="CatchHitObject"/> in the current position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The fruit to catch.</param>
|
public bool CanCatch(CatchHitObject hitObject)
|
||||||
/// <returns>Whether the catch is possible.</returns>
|
|
||||||
public bool AttemptCatch(CatchHitObject hitObject)
|
|
||||||
{
|
{
|
||||||
if (!(hitObject is PalpableCatchHitObject fruit))
|
if (!(hitObject is PalpableCatchHitObject fruit))
|
||||||
return false;
|
return false;
|
||||||
@ -205,21 +204,25 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
var catchObjectPosition = fruit.X;
|
var catchObjectPosition = fruit.X;
|
||||||
var catcherPosition = Position.X;
|
var catcherPosition = Position.X;
|
||||||
|
|
||||||
var validCatch =
|
return catchObjectPosition >= catcherPosition - halfCatchWidth &&
|
||||||
catchObjectPosition >= catcherPosition - halfCatchWidth &&
|
catchObjectPosition <= catcherPosition + halfCatchWidth;
|
||||||
catchObjectPosition <= catcherPosition + halfCatchWidth;
|
}
|
||||||
|
|
||||||
if (validCatch)
|
public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result)
|
||||||
placeCaughtObject(fruit);
|
{
|
||||||
|
if (!(drawableObject.HitObject is PalpableCatchHitObject hitObject)) return;
|
||||||
|
|
||||||
|
if (result.IsHit)
|
||||||
|
placeCaughtObject(hitObject);
|
||||||
|
|
||||||
// droplet doesn't affect the catcher state
|
// droplet doesn't affect the catcher state
|
||||||
if (fruit is TinyDroplet) return validCatch;
|
if (hitObject is TinyDroplet) return;
|
||||||
|
|
||||||
if (validCatch && fruit.HyperDash)
|
if (result.IsHit && hitObject.HyperDash)
|
||||||
{
|
{
|
||||||
var target = fruit.HyperDashTarget;
|
var target = hitObject.HyperDashTarget;
|
||||||
var timeDifference = target.StartTime - fruit.StartTime;
|
var timeDifference = target.StartTime - hitObject.StartTime;
|
||||||
double positionDifference = target.X - catcherPosition;
|
double positionDifference = target.X - X;
|
||||||
var velocity = positionDifference / Math.Max(1.0, timeDifference - 1000.0 / 60.0);
|
var velocity = positionDifference / Math.Max(1.0, timeDifference - 1000.0 / 60.0);
|
||||||
|
|
||||||
SetHyperDashState(Math.Abs(velocity), target.X);
|
SetHyperDashState(Math.Abs(velocity), target.X);
|
||||||
@ -227,12 +230,14 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
else
|
else
|
||||||
SetHyperDashState();
|
SetHyperDashState();
|
||||||
|
|
||||||
if (validCatch)
|
if (result.IsHit)
|
||||||
updateState(fruit.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle);
|
updateState(hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle);
|
||||||
else if (!(fruit is Banana))
|
else if (!(hitObject is Banana))
|
||||||
updateState(CatcherAnimationState.Fail);
|
updateState(CatcherAnimationState.Fail);
|
||||||
|
}
|
||||||
|
|
||||||
return validCatch;
|
public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -5,7 +5,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Catch.Judgements;
|
using osu.Game.Rulesets.Catch.Judgements;
|
||||||
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.Replays;
|
using osu.Game.Rulesets.Catch.Replays;
|
||||||
using osu.Game.Rulesets.Judgements;
|
using osu.Game.Rulesets.Judgements;
|
||||||
@ -42,6 +41,8 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
public void OnNewResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
public void OnNewResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
||||||
{
|
{
|
||||||
|
MovableCatcher.OnNewResult(hitObject, result);
|
||||||
|
|
||||||
if (!result.Type.IsScorable())
|
if (!result.Type.IsScorable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -56,12 +57,10 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
comboDisplay.OnNewResult(hitObject, result);
|
comboDisplay.OnNewResult(hitObject, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result)
|
public void OnRevertResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
||||||
=> comboDisplay.OnRevertResult(fruit, result);
|
|
||||||
|
|
||||||
public bool AttemptCatch(CatchHitObject obj)
|
|
||||||
{
|
{
|
||||||
return MovableCatcher.AttemptCatch(obj);
|
comboDisplay.OnRevertResult(hitObject, result);
|
||||||
|
MovableCatcher.OnRevertResult(hitObject, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user