Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Synesthesia mod #655

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions osu.Game.Rulesets.Sentakki/Mods/SentakkiModSynesthesia.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Sentakki.Objects.Drawables;
using osu.Game.Screens.Edit;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Sentakki.Mods;

/// <summary>
/// Mod that colours <see cref="HitObject"/>s based on the musical division they are on
/// </summary>
public class SentakkiModSynesthesia : ModSynesthesia, IApplicableToBeatmap, IApplicableToDrawableHitObject
{
private readonly OsuColour colours = new OsuColour();

private IBeatmap? currentBeatmap { get; set; }

public void ApplyToBeatmap(IBeatmap beatmap)
{
//Store a reference to the current beatmap to look up the beat divisor when notes are drawn
if (currentBeatmap != beatmap)
currentBeatmap = beatmap;
}

public void ApplyToDrawableHitObject(DrawableHitObject d)
{
if (currentBeatmap == null) return;

Color4? timingBasedColour = null;

d.HitObjectApplied += _ =>
{
// Slide bodies have a shootdelay, so we take into account that time too
double snapTime = d.HitObject.StartTime + (d is DrawableSlideBody s ? s.HitObject.ShootDelay : 0);
timingBasedColour = BindableBeatDivisor.GetColourFor(currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(snapTime), colours);
};

// 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;
};
}
}

1 change: 1 addition & 0 deletions osu.Game.Rulesets.Sentakki/SentakkiRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
new SentakkiModSpin(),
new SentakkiModMuted(),
new ModAdaptiveSpeed(),
new SentakkiModSynesthesia()
};

case ModType.System:
Expand Down
Loading