Skip to content

Commit 2d8a74d

Browse files
authored
Merge pull request #23520 from jtbiddle/snap-colour-mod
Add "Synesthesia" mod for osu! ruleset
2 parents f8b94ed + 6d32206 commit 2d8a74d

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using osu.Game.Beatmaps;
5+
using osu.Game.Graphics;
6+
using osu.Game.Rulesets.Mods;
7+
using osu.Game.Rulesets.Objects;
8+
using osu.Game.Rulesets.Objects.Drawables;
9+
using osu.Game.Rulesets.Osu.Objects.Drawables;
10+
using osu.Game.Screens.Edit;
11+
using osuTK.Graphics;
12+
13+
namespace osu.Game.Rulesets.Osu.Mods
14+
{
15+
/// <summary>
16+
/// Mod that colours <see cref="HitObject"/>s based on the musical division they are on
17+
/// </summary>
18+
public class OsuModSynesthesia : ModSynesthesia, IApplicableToBeatmap, IApplicableToDrawableHitObject
19+
{
20+
private readonly OsuColour colours = new OsuColour();
21+
22+
private IBeatmap? currentBeatmap { get; set; }
23+
24+
public void ApplyToBeatmap(IBeatmap beatmap)
25+
{
26+
//Store a reference to the current beatmap to look up the beat divisor when notes are drawn
27+
if (currentBeatmap != beatmap)
28+
currentBeatmap = beatmap;
29+
}
30+
31+
public void ApplyToDrawableHitObject(DrawableHitObject d)
32+
{
33+
if (currentBeatmap == null) return;
34+
35+
Color4? timingBasedColour = null;
36+
37+
d.HitObjectApplied += _ =>
38+
{
39+
// slider tails are a painful edge case, as their start time is offset 36ms back (see `LegacyLastTick`).
40+
// to work around this, look up the slider tail's parenting slider's end time instead to ensure proper snap.
41+
double snapTime = d is DrawableSliderTail tail
42+
? tail.Slider.GetEndTime()
43+
: d.HitObject.StartTime;
44+
timingBasedColour = BindableBeatDivisor.GetColourFor(currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(snapTime), colours);
45+
};
46+
47+
// Need to set this every update to ensure it doesn't get overwritten by DrawableHitObject.OnApply() -> UpdateComboColour().
48+
d.OnUpdate += _ =>
49+
{
50+
if (timingBasedColour != null)
51+
d.AccentColour.Value = timingBasedColour.Value;
52+
};
53+
}
54+
}
55+
}

osu.Game.Rulesets.Osu/OsuRuleset.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
204204
new MultiMod(new OsuModMagnetised(), new OsuModRepel()),
205205
new ModAdaptiveSpeed(),
206206
new OsuModFreezeFrame(),
207-
new OsuModBubbles()
207+
new OsuModBubbles(),
208+
new OsuModSynesthesia()
208209
};
209210

210211
case ModType.System:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using osu.Framework.Localisation;
5+
6+
namespace osu.Game.Rulesets.Mods
7+
{
8+
/// <summary>
9+
/// Mod that colours hitobjects based on the musical division they are on
10+
/// </summary>
11+
public class ModSynesthesia : Mod
12+
{
13+
public override string Name => "Synesthesia";
14+
public override string Acronym => "SY";
15+
public override LocalisableString Description => "Colours hit objects based on the rhythm.";
16+
public override double ScoreMultiplier => 1;
17+
public override ModType Type => ModType.Fun;
18+
}
19+
}

0 commit comments

Comments
 (0)