2023-05-13 10:07:25 +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.
|
2023-05-13 10:43:28 +08:00
|
|
|
|
2023-05-13 10:07:25 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2023-06-19 23:47:01 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2023-05-13 10:07:25 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
2023-06-19 19:09:53 +08:00
|
|
|
using osuTK.Graphics;
|
2023-05-13 10:07:25 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Mod that colours <see cref="HitObject"/>s based on the musical division they are on
|
|
|
|
/// </summary>
|
2023-06-08 15:52:28 +08:00
|
|
|
public class OsuModSynesthesia : ModSynesthesia, IApplicableToBeatmap, IApplicableToDrawableHitObject
|
2023-05-13 10:07:25 +08:00
|
|
|
{
|
2023-05-13 13:13:39 +08:00
|
|
|
private readonly OsuColour colours = new OsuColour();
|
2023-05-13 10:07:25 +08:00
|
|
|
|
2023-05-13 13:13:39 +08:00
|
|
|
private IBeatmap? currentBeatmap { get; set; }
|
2023-05-13 10:07:25 +08:00
|
|
|
|
|
|
|
public void ApplyToBeatmap(IBeatmap beatmap)
|
|
|
|
{
|
|
|
|
//Store a reference to the current beatmap to look up the beat divisor when notes are drawn
|
2023-05-13 13:13:39 +08:00
|
|
|
if (currentBeatmap != beatmap)
|
|
|
|
currentBeatmap = beatmap;
|
2023-05-13 10:07:25 +08:00
|
|
|
}
|
|
|
|
|
2023-06-19 19:09:53 +08:00
|
|
|
public void ApplyToDrawableHitObject(DrawableHitObject d)
|
2023-05-13 10:07:25 +08:00
|
|
|
{
|
2023-06-08 15:52:28 +08:00
|
|
|
if (currentBeatmap == null) return;
|
2023-05-13 10:07:25 +08:00
|
|
|
|
2023-06-19 19:09:53 +08:00
|
|
|
Color4? timingBasedColour = null;
|
|
|
|
|
2023-06-19 23:47:01 +08:00
|
|
|
d.HitObjectApplied += _ =>
|
|
|
|
{
|
2023-09-29 13:40:44 +08:00
|
|
|
// slider tails are a painful edge case, as their start time is offset 36ms back (see `LastTick`).
|
2023-06-19 23:47:01 +08:00
|
|
|
// to work around this, look up the slider tail's parenting slider's end time instead to ensure proper snap.
|
|
|
|
double snapTime = d is DrawableSliderTail tail
|
|
|
|
? tail.Slider.GetEndTime()
|
|
|
|
: d.HitObject.StartTime;
|
|
|
|
timingBasedColour = BindableBeatDivisor.GetColourFor(currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(snapTime), colours);
|
|
|
|
};
|
2023-06-19 19:09:53 +08:00
|
|
|
|
|
|
|
// Need to set this every update to ensure it doesn't get overwritten by DrawableHitObject.OnApply() -> UpdateComboColour().
|
|
|
|
d.OnUpdate += _ =>
|
|
|
|
{
|
|
|
|
if (timingBasedColour != null)
|
|
|
|
d.AccentColour.Value = timingBasedColour.Value;
|
|
|
|
};
|
2023-05-13 10:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|