mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Add base DrawableHitObject + HitObjectStartTimeComparer.
This commit is contained in:
55
osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs
Normal file
55
osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares two hit objects by their start time, falling back to creation order if their start time is equal.
|
||||
/// </summary>
|
||||
public class HitObjectStartTimeComparer : Drawable.CreationOrderDepthComparer
|
||||
{
|
||||
public override int Compare(Drawable x, Drawable y)
|
||||
{
|
||||
var hitObjectX = x as DrawableHitObject;
|
||||
var hitObjectY = y as DrawableHitObject;
|
||||
|
||||
// If either of the two drawables are not hit objects, fall back to the base comparer
|
||||
if ((hitObjectX ?? hitObjectY) == null)
|
||||
return base.Compare(x, y);
|
||||
|
||||
// Compare by start time
|
||||
int i = hitObjectX.HitObject.StartTime.CompareTo(hitObjectY.HitObject.StartTime);
|
||||
if (i != 0)
|
||||
return i;
|
||||
|
||||
return base.Compare(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two hit objects by their start time, falling back to creation order if their start time is equal.
|
||||
/// This will compare the two hit objects in reverse order.
|
||||
/// </summary>
|
||||
public class HitObjectReverseStartTimeComparer : Drawable.ReverseCreationOrderDepthComparer
|
||||
{
|
||||
public override int Compare(Drawable x, Drawable y)
|
||||
{
|
||||
var hitObjectX = x as DrawableHitObject;
|
||||
var hitObjectY = y as DrawableHitObject;
|
||||
|
||||
// If either of the two drawables are not hit objects, fall back to the base comparer
|
||||
if ((hitObjectX ?? hitObjectY) == null)
|
||||
return base.Compare(x, y);
|
||||
|
||||
// Compare by start time
|
||||
int i = hitObjectY.HitObject.StartTime.CompareTo(hitObjectX.HitObject.StartTime);
|
||||
if (i != 0)
|
||||
return i;
|
||||
|
||||
return base.Compare(x, y);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user