// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.UI.Scrolling; using osuTK; namespace osu.Game.Rulesets.Catch.Edit { /// /// Utility functions used by the editor. /// public static class CatchHitObjectUtils { /// /// Get the position of the hit object in the playfield based on and . /// public static Vector2 GetStartPosition(ScrollingHitObjectContainer hitObjectContainer, CatchHitObject hitObject) { return new Vector2(hitObject.OriginalX, hitObjectContainer.PositionAtTime(hitObject.StartTime)); } /// /// Get the range of horizontal position occupied by the hit object. /// /// /// s are excluded and returns . /// 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; } } /// /// Get the range of horizontal position occupied by the hit objects. /// /// /// s are excluded. /// public static PositionRange GetPositionRange(IEnumerable hitObjects) => hitObjects.Select(GetPositionRange).Aggregate(PositionRange.EMPTY, PositionRange.Union); } }