mirror of
https://github.com/ppy/osu.git
synced 2026-06-02 00:20:40 +08:00
Reduce code duplication
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
@@ -40,19 +41,17 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
|
||||
var hitObjects = taikoBeatmap.HitObjects.Select(ho =>
|
||||
{
|
||||
if (ho is DrumRoll drumRoll)
|
||||
switch (ho)
|
||||
{
|
||||
var newDrumRoll = new ClassicDrumRoll(drumRoll);
|
||||
return newDrumRoll;
|
||||
}
|
||||
case DrumRoll drumRoll:
|
||||
return new ClassicDrumRoll(drumRoll);
|
||||
|
||||
if (ho is Swell swell)
|
||||
{
|
||||
var newSwell = new ClassicSwell(swell);
|
||||
return newSwell;
|
||||
}
|
||||
case Swell swell:
|
||||
return new ClassicSwell(swell);
|
||||
|
||||
return ho;
|
||||
default:
|
||||
return ho;
|
||||
}
|
||||
}).ToList();
|
||||
|
||||
taikoBeatmap.HitObjects = hitObjects;
|
||||
@@ -73,33 +72,35 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
|
||||
public override Judgement CreateJudgement() => new TaikoClassicDrumRollJudgement();
|
||||
|
||||
protected override void CreateTicks(CancellationToken cancellationToken)
|
||||
protected override List<TaikoHitObject> CreateTicks(CancellationToken cancellationToken)
|
||||
{
|
||||
if (TickSpacing == 0)
|
||||
return;
|
||||
List<TaikoHitObject> oldTicks = base.CreateTicks(cancellationToken);
|
||||
|
||||
bool first = true;
|
||||
|
||||
for (double t = StartTime; t < EndTime + TickSpacing / 2; t += TickSpacing)
|
||||
List<TaikoHitObject> newTicks = oldTicks.Select(oldTick =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
AddNested(new ClassicDrumRollTick
|
||||
if (oldTick is DrumRollTick drumRollTick)
|
||||
{
|
||||
FirstTick = first,
|
||||
TickSpacing = TickSpacing,
|
||||
StartTime = t,
|
||||
IsStrong = IsStrong
|
||||
});
|
||||
return new ClassicDrumRollTick(drumRollTick);
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
return oldTick;
|
||||
}).ToList();
|
||||
|
||||
return newTicks;
|
||||
}
|
||||
}
|
||||
|
||||
private class ClassicDrumRollTick : DrumRollTick
|
||||
{
|
||||
public override Judgement CreateJudgement() => new TaikoClassicDrumRollTickJudgement();
|
||||
|
||||
public ClassicDrumRollTick(DrumRollTick original)
|
||||
{
|
||||
StartTime = original.StartTime;
|
||||
Samples = original.Samples;
|
||||
FirstTick = original.FirstTick;
|
||||
TickSpacing = original.TickSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
private class ClassicSwell : Swell
|
||||
@@ -118,12 +119,12 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
|
||||
private class TaikoClassicDrumRollJudgement : TaikoDrumRollJudgement
|
||||
{
|
||||
public override HitResult MaxResult => HitResult.LargeBonus;
|
||||
public override HitResult MaxResult => HitResult.IgnoreHit;
|
||||
}
|
||||
|
||||
private class TaikoClassicDrumRollTickJudgement : TaikoDrumRollTickJudgement
|
||||
{
|
||||
public override HitResult MaxResult => HitResult.LargeBonus;
|
||||
public override HitResult MaxResult => HitResult.SmallBonus;
|
||||
}
|
||||
|
||||
private class TaikoClassicSwellJudgement : TaikoSwellJudgement
|
||||
@@ -143,7 +144,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
if (timeOffset < 0)
|
||||
return;
|
||||
|
||||
ApplyResult(r => r.Type = HitResult.IgnoreMiss);
|
||||
ApplyResult(r => r.Type = HitResult.IgnoreHit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,52 +152,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
||||
{
|
||||
public override bool DisplayResult => false;
|
||||
|
||||
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
||||
{
|
||||
if (userTriggered)
|
||||
{
|
||||
DrawableSwellTick nextTick = null;
|
||||
|
||||
foreach (var t in Ticks)
|
||||
{
|
||||
if (!t.Result.HasResult)
|
||||
{
|
||||
nextTick = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nextTick?.TriggerResult(true);
|
||||
|
||||
int numHits = Ticks.Count(r => r.IsHit);
|
||||
|
||||
AnimateCompletion(numHits);
|
||||
|
||||
if (numHits == HitObject.RequiredHits)
|
||||
ApplyResult(r => r.Type = HitResult.LargeBonus);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeOffset < 0)
|
||||
return;
|
||||
|
||||
int numHits = 0;
|
||||
|
||||
foreach (var tick in Ticks)
|
||||
{
|
||||
if (tick.IsHit)
|
||||
{
|
||||
numHits++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tick.Result.HasResult)
|
||||
tick.TriggerResult(false);
|
||||
}
|
||||
|
||||
ApplyResult(r => r.Type = numHits > HitObject.RequiredHits / 2 ? HitResult.SmallBonus : HitResult.IgnoreMiss);
|
||||
}
|
||||
}
|
||||
protected override HitResult OkResult => HitResult.SmallBonus;
|
||||
}
|
||||
|
||||
public void Update(Playfield playfield)
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
/// </summary>
|
||||
private const double ring_appear_offset = 100;
|
||||
|
||||
protected readonly Container<DrawableSwellTick> Ticks;
|
||||
protected virtual HitResult OkResult => HitResult.Ok;
|
||||
private readonly Container<DrawableSwellTick> ticks;
|
||||
private readonly Container bodyContainer;
|
||||
private readonly CircularContainer targetRing;
|
||||
private readonly CircularContainer expandingRing;
|
||||
@@ -114,7 +115,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
}
|
||||
});
|
||||
|
||||
AddInternal(Ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
|
||||
AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@@ -132,20 +133,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
|
||||
protected void AnimateCompletion(int numHits)
|
||||
{
|
||||
float completion = (float)numHits / HitObject.RequiredHits;
|
||||
|
||||
expandingRing
|
||||
.FadeTo(expandingRing.Alpha + Math.Clamp(completion / 16, 0.1f, 0.6f), 50)
|
||||
.Then()
|
||||
.FadeTo(completion / 8, 2000, Easing.OutQuint);
|
||||
|
||||
MainPiece.Drawable.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint);
|
||||
|
||||
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void OnFree()
|
||||
{
|
||||
base.OnFree();
|
||||
@@ -162,7 +149,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
switch (hitObject)
|
||||
{
|
||||
case DrawableSwellTick tick:
|
||||
Ticks.Add(tick);
|
||||
ticks.Add(tick);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +157,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
protected override void ClearNestedHitObjects()
|
||||
{
|
||||
base.ClearNestedHitObjects();
|
||||
Ticks.Clear(false);
|
||||
ticks.Clear(false);
|
||||
}
|
||||
|
||||
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
||||
@@ -190,7 +177,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
{
|
||||
DrawableSwellTick nextTick = null;
|
||||
|
||||
foreach (var t in Ticks)
|
||||
foreach (var t in ticks)
|
||||
{
|
||||
if (!t.Result.HasResult)
|
||||
{
|
||||
@@ -201,12 +188,21 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
|
||||
nextTick?.TriggerResult(true);
|
||||
|
||||
int numHits = Ticks.Count(r => r.IsHit);
|
||||
int numHits = ticks.Count(r => r.IsHit);
|
||||
|
||||
AnimateCompletion(numHits);
|
||||
float completion = (float)numHits / HitObject.RequiredHits;
|
||||
|
||||
expandingRing
|
||||
.FadeTo(expandingRing.Alpha + Math.Clamp(completion / 16, 0.1f, 0.6f), 50)
|
||||
.Then()
|
||||
.FadeTo(completion / 8, 2000, Easing.OutQuint);
|
||||
|
||||
MainPiece.Drawable.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint);
|
||||
|
||||
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
|
||||
|
||||
if (numHits == HitObject.RequiredHits)
|
||||
ApplyResult(r => r.Type = HitResult.Great);
|
||||
ApplyResult(r => r.Type = r.Judgement.MaxResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -215,7 +211,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
|
||||
int numHits = 0;
|
||||
|
||||
foreach (var tick in Ticks)
|
||||
foreach (var tick in ticks)
|
||||
{
|
||||
if (tick.IsHit)
|
||||
{
|
||||
@@ -227,7 +223,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
tick.TriggerResult(false);
|
||||
}
|
||||
|
||||
ApplyResult(r => r.Type = numHits > HitObject.RequiredHits / 2 ? HitResult.Ok : r.Judgement.MinResult);
|
||||
ApplyResult(r => r.Type = numHits > HitObject.RequiredHits / 2 ? OkResult : r.Judgement.MinResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
@@ -75,7 +76,10 @@ namespace osu.Game.Rulesets.Taiko.Objects
|
||||
|
||||
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
|
||||
{
|
||||
CreateTicks(cancellationToken);
|
||||
foreach (TaikoHitObject tick in CreateTicks(cancellationToken))
|
||||
{
|
||||
AddNested(tick);
|
||||
}
|
||||
|
||||
RequiredGoodHits = NestedHitObjects.Count * Math.Min(0.15, 0.05 + 0.10 / 6 * overallDifficulty);
|
||||
RequiredGreatHits = NestedHitObjects.Count * Math.Min(0.30, 0.10 + 0.20 / 6 * overallDifficulty);
|
||||
@@ -83,10 +87,12 @@ namespace osu.Game.Rulesets.Taiko.Objects
|
||||
base.CreateNestedHitObjects(cancellationToken);
|
||||
}
|
||||
|
||||
protected virtual void CreateTicks(CancellationToken cancellationToken)
|
||||
protected virtual List<TaikoHitObject> CreateTicks(CancellationToken cancellationToken)
|
||||
{
|
||||
List<TaikoHitObject> ticks = new List<TaikoHitObject>();
|
||||
|
||||
if (TickSpacing == 0)
|
||||
return;
|
||||
return ticks;
|
||||
|
||||
bool first = true;
|
||||
|
||||
@@ -94,7 +100,7 @@ namespace osu.Game.Rulesets.Taiko.Objects
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
AddNested(new DrumRollTick
|
||||
ticks.Add(new DrumRollTick
|
||||
{
|
||||
FirstTick = first,
|
||||
TickSpacing = TickSpacing,
|
||||
@@ -104,6 +110,8 @@ namespace osu.Game.Rulesets.Taiko.Objects
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
public override Judgement CreateJudgement() => new TaikoDrumRollJudgement();
|
||||
|
||||
Reference in New Issue
Block a user