// 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.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Beatmaps; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Objects; using osuTK; namespace osu.Game.Rulesets.Catch.Mods { public class CatchModMirror : ModMirror, IApplicableToBeatmap { public override string Description => "Fruits are flipped horizontally."; /// /// is used instead of , /// as applies offsets in . /// runs after post-processing, while runs before it. /// public void ApplyToBeatmap(IBeatmap beatmap) { foreach (var hitObject in beatmap.HitObjects) applyToHitObject(hitObject); } private void applyToHitObject(HitObject hitObject) { var catchObject = (CatchHitObject)hitObject; switch (catchObject) { case Fruit fruit: mirrorEffectiveX(fruit); break; case JuiceStream juiceStream: mirrorEffectiveX(juiceStream); mirrorJuiceStreamPath(juiceStream); break; case BananaShower bananaShower: mirrorBananaShower(bananaShower); break; } } /// /// Mirrors the effective X position of and its nested hit objects. /// private static void mirrorEffectiveX(CatchHitObject catchObject) { catchObject.OriginalX = CatchPlayfield.WIDTH - catchObject.OriginalX; catchObject.XOffset = -catchObject.XOffset; foreach (var nested in catchObject.NestedHitObjects.Cast()) { nested.OriginalX = CatchPlayfield.WIDTH - nested.OriginalX; nested.XOffset = -nested.XOffset; } } /// /// Mirrors the path of the . /// private static void mirrorJuiceStreamPath(JuiceStream juiceStream) { var controlPoints = juiceStream.Path.ControlPoints.Select(p => new PathControlPoint(p.Position, p.Type)).ToArray(); foreach (var point in controlPoints) point.Position = new Vector2(-point.Position.X, point.Position.Y); juiceStream.Path = new SliderPath(controlPoints, juiceStream.Path.ExpectedDistance.Value); } /// /// Mirrors X positions of all bananas in the . /// private static void mirrorBananaShower(BananaShower bananaShower) { foreach (var banana in bananaShower.NestedHitObjects.OfType()) banana.XOffset = CatchPlayfield.WIDTH - banana.XOffset; } } }