1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 10:32:55 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
3.3 KiB
C#
Raw Normal View History

2021-08-09 01:45:13 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-08-09 01:45:13 +08:00
using System.Linq;
2021-08-11 03:42:41 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Beatmaps;
2021-08-09 01:45:13 +08:00
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
{
2021-08-11 03:42:41 +08:00
public class CatchModMirror : ModMirror, IApplicableToBeatmap
2021-08-09 01:45:13 +08:00
{
public override string Description => "Fruits are flipped horizontally.";
2021-08-09 02:27:48 +08:00
2021-08-11 03:42:41 +08:00
/// <remarks>
/// <see cref="IApplicableToBeatmap"/> is used instead of <see cref="IApplicableToHitObject"/>,
/// as <see cref="CatchBeatmapProcessor"/> applies offsets in <see cref="CatchBeatmapProcessor.PostProcess"/>.
/// <see cref="IApplicableToBeatmap"/> runs after post-processing, while <see cref="IApplicableToHitObject"/> runs before it.
/// </remarks>
public void ApplyToBeatmap(IBeatmap beatmap)
{
foreach (var hitObject in beatmap.HitObjects)
applyToHitObject(hitObject);
}
private void applyToHitObject(HitObject hitObject)
2021-08-09 01:45:13 +08:00
{
2021-08-09 14:57:18 +08:00
var catchObject = (CatchHitObject)hitObject;
2021-08-11 03:51:46 +08:00
switch (catchObject)
{
case Fruit fruit:
mirrorEffectiveX(fruit);
break;
case JuiceStream juiceStream:
mirrorEffectiveX(juiceStream);
mirrorJuiceStreamPath(juiceStream);
break;
case BananaShower bananaShower:
mirrorBananaShower(bananaShower);
break;
}
}
/// <summary>
/// Mirrors the effective X position of <paramref name="catchObject"/> and its nested hit objects.
/// </summary>
private static void mirrorEffectiveX(CatchHitObject catchObject)
{
2021-08-09 01:45:13 +08:00
catchObject.OriginalX = CatchPlayfield.WIDTH - catchObject.OriginalX;
2021-08-11 03:42:41 +08:00
catchObject.XOffset = -catchObject.XOffset;
2021-08-09 01:45:13 +08:00
foreach (var nested in catchObject.NestedHitObjects.Cast<CatchHitObject>())
2021-08-11 03:42:41 +08:00
{
2021-08-09 01:45:13 +08:00
nested.OriginalX = CatchPlayfield.WIDTH - nested.OriginalX;
2021-08-11 03:42:41 +08:00
nested.XOffset = -nested.XOffset;
}
2021-08-11 03:51:46 +08:00
}
2021-08-09 01:45:13 +08:00
2021-08-11 03:51:46 +08:00
/// <summary>
/// Mirrors the path of the <paramref name="juiceStream"/>.
/// </summary>
private static void mirrorJuiceStreamPath(JuiceStream juiceStream)
{
var controlPoints = juiceStream.Path.ControlPoints.Select(p => new PathControlPoint(p.Position, p.Type)).ToArray();
2021-08-11 03:51:46 +08:00
foreach (var point in controlPoints)
point.Position = new Vector2(-point.Position.X, point.Position.Y);
2021-08-09 01:45:13 +08:00
2021-08-11 03:51:46 +08:00
juiceStream.Path = new SliderPath(controlPoints, juiceStream.Path.ExpectedDistance.Value);
}
/// <summary>
/// Mirrors X positions of all bananas in the <paramref name="bananaShower"/>.
/// </summary>
private static void mirrorBananaShower(BananaShower bananaShower)
{
foreach (var banana in bananaShower.NestedHitObjects.OfType<Banana>())
banana.XOffset = CatchPlayfield.WIDTH - banana.XOffset;
2021-08-09 01:45:13 +08:00
}
}
}