mirror of
https://github.com/osukey/osukey.git
synced 2025-05-10 08:07:18 +09:00
Add function of computing position range occupied by hit objects
This commit is contained in:
parent
1bff4373b3
commit
60f876511d
@ -1,7 +1,10 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Game.Rulesets.Catch.Objects;
|
using osu.Game.Rulesets.Catch.Objects;
|
||||||
|
using osu.Game.Rulesets.Catch.UI;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.UI.Scrolling;
|
using osu.Game.Rulesets.UI.Scrolling;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -20,5 +23,41 @@ namespace osu.Game.Rulesets.Catch.Edit
|
|||||||
{
|
{
|
||||||
return new Vector2(hitObject.OriginalX, hitObjectContainer.PositionAtTime(hitObject.StartTime));
|
return new Vector2(hitObject.OriginalX, hitObjectContainer.PositionAtTime(hitObject.StartTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the range of horizontal position occupied by the hit object.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <see cref="TinyDroplet"/>s are excluded and returns <see cref="PositionRange.EMPTY"/>.
|
||||||
|
/// </remarks>
|
||||||
|
public static PositionRange GetPositionRange(HitObject hitObject)
|
||||||
|
{
|
||||||
|
switch (hitObject)
|
||||||
|
{
|
||||||
|
case Fruit fruit:
|
||||||
|
return new PositionRange(fruit.OriginalX);
|
||||||
|
|
||||||
|
case Droplet droplet:
|
||||||
|
return droplet is TinyDroplet ? PositionRange.EMPTY : new PositionRange(droplet.OriginalX);
|
||||||
|
|
||||||
|
case JuiceStream _:
|
||||||
|
return GetPositionRange(hitObject.NestedHitObjects);
|
||||||
|
|
||||||
|
case BananaShower _:
|
||||||
|
// A banana shower occupies the whole screen width.
|
||||||
|
return new PositionRange(0, CatchPlayfield.WIDTH);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return PositionRange.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the range of horizontal position occupied by the hit objects.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <see cref="TinyDroplet"/>s are excluded.
|
||||||
|
/// </remarks>
|
||||||
|
public static PositionRange GetPositionRange(IEnumerable<HitObject> hitObjects) => hitObjects.Select(GetPositionRange).Aggregate(PositionRange.EMPTY, PositionRange.Union);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
osu.Game.Rulesets.Catch/Edit/PositionRange.cs
Normal file
33
osu.Game.Rulesets.Catch/Edit/PositionRange.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Catch.Edit
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a closed interval of horizontal positions in the playfield.
|
||||||
|
/// </summary>
|
||||||
|
public readonly struct PositionRange
|
||||||
|
{
|
||||||
|
public readonly float Min;
|
||||||
|
public readonly float Max;
|
||||||
|
|
||||||
|
public PositionRange(float value)
|
||||||
|
: this(value, value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PositionRange(float min, float max)
|
||||||
|
{
|
||||||
|
Min = min;
|
||||||
|
Max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PositionRange Union(PositionRange a, PositionRange b) => new PositionRange(Math.Min(a.Min, b.Min), Math.Max(a.Max, b.Max));
|
||||||
|
|
||||||
|
public static readonly PositionRange EMPTY = new PositionRange(float.PositiveInfinity, float.NegativeInfinity);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user