Move tick handling to DrawableSpinner itself

This commit is contained in:
Dean Herbert
2020-07-21 19:03:17 +09:00
parent 05102bc1ba
commit 947f4e0d4c
4 changed files with 86 additions and 94 deletions

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public readonly SpinnerDisc Disc;
public readonly SpinnerTicks Ticks;
public readonly SpinnerSpmCounter SpmCounter;
private readonly SpinnerBonusComponent bonusComponent;
private readonly SpinnerBonusDisplay bonusDisplay;
private readonly Container mainContainer;
@ -126,7 +126,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Y = 120,
Alpha = 0
},
bonusComponent = new SpinnerBonusComponent(this, ticks)
bonusDisplay = new SpinnerBonusDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -199,6 +199,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (userTriggered || Time.Current < Spinner.EndTime)
return;
// Trigger a miss result for remaining ticks to avoid infinite gameplay.
foreach (var tick in ticks.Where(t => !t.IsHit))
tick.TriggerResult(HitResult.Miss);
ApplyResult(r =>
{
if (Progress >= 1)
@ -230,7 +234,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Ticks.Rotation = Disc.Rotation;
SpmCounter.SetRotation(Disc.CumulativeRotation);
bonusComponent.SetRotation(Disc.CumulativeRotation);
updateBonusScore();
float relativeCircleScale = Spinner.Scale * circle.DrawHeight / mainContainer.DrawHeight;
float targetScale = relativeCircleScale + (1 - relativeCircleScale) * Progress;
@ -239,6 +244,37 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
symbol.Rotation = (float)Interpolation.Lerp(symbol.Rotation, Disc.Rotation / 2, Math.Clamp(Math.Abs(Time.Elapsed) / 40, 0, 1));
}
private int wholeSpins;
private void updateBonusScore()
{
if (ticks.Count == 0)
return;
int spins = (int)(Disc.CumulativeRotation / 360);
while (wholeSpins != spins)
{
if (wholeSpins < spins)
{
var tick = ticks.FirstOrDefault(t => !t.IsHit);
if (tick != null)
{
tick.TriggerResult(HitResult.Great);
if (tick is DrawableSpinnerBonusTick)
bonusDisplay.SetBonusCount(spins - Spinner.SpinsRequired);
}
wholeSpins++;
}
else
{
wholeSpins--;
}
}
}
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();