1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 14:27:25 +08:00

Introduce base class for hitobjects that can be strong

This commit is contained in:
Bartłomiej Dach 2020-12-13 12:36:39 +01:00
parent 1ddc896b76
commit f74567e8eb
13 changed files with 56 additions and 60 deletions

View File

@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
IsCentre = (hitObject as Hit)?.Type == HitType.Centre, IsCentre = (hitObject as Hit)?.Type == HitType.Centre,
IsDrumRoll = hitObject is DrumRoll, IsDrumRoll = hitObject is DrumRoll,
IsSwell = hitObject is Swell, IsSwell = hitObject is Swell,
IsStrong = ((TaikoHitObject)hitObject).IsStrong IsStrong = (hitObject as TaikoStrongHitObject)?.IsStrong == true
}; };
} }

View File

@ -65,8 +65,8 @@ namespace osu.Game.Rulesets.Taiko.Beatmaps
converted.HitObjects = converted.HitObjects.GroupBy(t => t.StartTime).Select(x => converted.HitObjects = converted.HitObjects.GroupBy(t => t.StartTime).Select(x =>
{ {
TaikoHitObject first = x.First(); TaikoHitObject first = x.First();
if (x.Skip(1).Any() && first.CanBeStrong) if (x.Skip(1).Any() && first is TaikoStrongHitObject strong)
first.IsStrong = true; strong.IsStrong = true;
return first; return first;
}).ToList(); }).ToList();
} }

View File

@ -96,7 +96,7 @@ namespace osu.Game.Rulesets.Taiko.Edit
base.UpdateTernaryStates(); base.UpdateTernaryStates();
selectionRimState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim); selectionRimState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim);
selectionStrongState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<TaikoHitObject>(), h => h.IsStrong); selectionStrongState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<TaikoStrongHitObject>(), h => h.IsStrong);
} }
} }
} }

View File

@ -158,7 +158,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
base.LoadSamples(); base.LoadSamples();
if (HitObject.CanBeStrong) if (HitObject is TaikoStrongHitObject)
isStrong.Value = getStrongSamples().Any(); isStrong.Value = getStrongSamples().Any();
} }

View File

@ -15,7 +15,7 @@ using osuTK;
namespace osu.Game.Rulesets.Taiko.Objects namespace osu.Game.Rulesets.Taiko.Objects
{ {
public class DrumRoll : TaikoHitObject, IHasPath public class DrumRoll : TaikoStrongHitObject, IHasPath
{ {
/// <summary> /// <summary>
/// Drum roll distance that results in a duration of 1 speed-adjusted beat length. /// Drum roll distance that results in a duration of 1 speed-adjusted beat length.

View File

@ -7,7 +7,7 @@ using osu.Game.Rulesets.Taiko.Judgements;
namespace osu.Game.Rulesets.Taiko.Objects namespace osu.Game.Rulesets.Taiko.Objects
{ {
public class DrumRollTick : TaikoHitObject public class DrumRollTick : TaikoStrongHitObject
{ {
/// <summary> /// <summary>
/// Whether this is the first (initial) tick of the slider. /// Whether this is the first (initial) tick of the slider.

View File

@ -5,7 +5,7 @@ using osu.Framework.Bindables;
namespace osu.Game.Rulesets.Taiko.Objects namespace osu.Game.Rulesets.Taiko.Objects
{ {
public class Hit : TaikoHitObject public class Hit : TaikoStrongHitObject
{ {
public readonly Bindable<HitType> TypeBindable = new Bindable<HitType>(); public readonly Bindable<HitType> TypeBindable = new Bindable<HitType>();

View File

@ -17,8 +17,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
set => Duration = value - StartTime; set => Duration = value - StartTime;
} }
public override bool CanBeStrong => false;
public double Duration { get; set; } public double Duration { get; set; }
/// <summary> /// <summary>

View File

@ -1,9 +1,6 @@
// 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.Threading;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -19,47 +16,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
/// </summary> /// </summary>
public const float DEFAULT_SIZE = 0.45f; public const float DEFAULT_SIZE = 0.45f;
/// <summary>
/// Scale multiplier for a strong drawable taiko hit object.
/// </summary>
public const float STRONG_SCALE = 1.4f;
/// <summary>
/// Default size of a strong drawable taiko hit object.
/// </summary>
public const float DEFAULT_STRONG_SIZE = DEFAULT_SIZE * STRONG_SCALE;
public readonly Bindable<bool> IsStrongBindable = new BindableBool();
/// <summary>
/// Whether this <see cref="TaikoHitObject"/> can be made a "strong" (large) hit.
/// </summary>
public virtual bool CanBeStrong => true;
/// <summary>
/// Whether this HitObject is a "strong" type.
/// Strong hit objects give more points for hitting the hit object with both keys.
/// </summary>
public bool IsStrong
{
get => IsStrongBindable.Value;
set
{
if (value && !CanBeStrong)
throw new InvalidOperationException($"Object of type {GetType()} cannot be strong");
IsStrongBindable.Value = value;
}
}
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
{
base.CreateNestedHitObjects(cancellationToken);
if (IsStrong)
AddNested(new StrongNestedHitObject { StartTime = this.GetEndTime() });
}
public override Judgement CreateJudgement() => new TaikoJudgement(); public override Judgement CreateJudgement() => new TaikoJudgement();
protected override HitWindows CreateHitWindows() => new TaikoHitWindows(); protected override HitWindows CreateHitWindows() => new TaikoHitWindows();

View File

@ -0,0 +1,42 @@
// 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 System.Threading;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Taiko.Objects
{
public abstract class TaikoStrongHitObject : TaikoHitObject
{
/// <summary>
/// Scale multiplier for a strong drawable taiko hit object.
/// </summary>
public const float STRONG_SCALE = 1.4f;
/// <summary>
/// Default size of a strong drawable taiko hit object.
/// </summary>
public const float DEFAULT_STRONG_SIZE = DEFAULT_SIZE * STRONG_SCALE;
public readonly Bindable<bool> IsStrongBindable = new BindableBool();
/// <summary>
/// Whether this HitObject is a "strong" type.
/// Strong hit objects give more points for hitting the hit object with both keys.
/// </summary>
public bool IsStrong
{
get => IsStrongBindable.Value;
set => IsStrongBindable.Value = value;
}
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
{
base.CreateNestedHitObjects(cancellationToken);
if (IsStrong)
AddNested(new StrongNestedHitObject { StartTime = this.GetEndTime() });
}
}
}

View File

@ -102,13 +102,13 @@ namespace osu.Game.Rulesets.Taiko.Replays
if (hit.Type == HitType.Centre) if (hit.Type == HitType.Centre)
{ {
actions = h.IsStrong actions = hit.IsStrong
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre } ? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
: new[] { hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre }; : new[] { hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre };
} }
else else
{ {
actions = h.IsStrong actions = hit.IsStrong
? new[] { TaikoAction.LeftRim, TaikoAction.RightRim } ? new[] { TaikoAction.LeftRim, TaikoAction.RightRim }
: new[] { hitButton ? TaikoAction.LeftRim : TaikoAction.RightRim }; : new[] { hitButton ? TaikoAction.LeftRim : TaikoAction.RightRim };
} }

View File

@ -73,7 +73,7 @@ namespace osu.Game.Rulesets.Taiko.UI
/// </summary> /// </summary>
public void VisualiseSecondHit() public void VisualiseSecondHit()
{ {
this.ResizeTo(new Vector2(TaikoHitObject.DEFAULT_STRONG_SIZE), 50); this.ResizeTo(new Vector2(TaikoStrongHitObject.DEFAULT_STRONG_SIZE), 50);
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Taiko.UI
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Size = new Vector2(border_thickness, (1 - TaikoHitObject.DEFAULT_STRONG_SIZE) / 2f), Size = new Vector2(border_thickness, (1 - TaikoStrongHitObject.DEFAULT_STRONG_SIZE) / 2f),
Alpha = 0.1f Alpha = 0.1f
}, },
new CircularContainer new CircularContainer
@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Taiko.UI
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Size = new Vector2(TaikoHitObject.DEFAULT_STRONG_SIZE), Size = new Vector2(TaikoStrongHitObject.DEFAULT_STRONG_SIZE),
Masking = true, Masking = true,
BorderColour = Color4.White, BorderColour = Color4.White,
BorderThickness = border_thickness, BorderThickness = border_thickness,
@ -83,7 +83,7 @@ namespace osu.Game.Rulesets.Taiko.UI
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Size = new Vector2(border_thickness, (1 - TaikoHitObject.DEFAULT_STRONG_SIZE) / 2f), Size = new Vector2(border_thickness, (1 - TaikoStrongHitObject.DEFAULT_STRONG_SIZE) / 2f),
Alpha = 0.1f Alpha = 0.1f
}, },
}; };