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

Mania mod invert revork #27508

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 26 additions & 11 deletions osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mods;
Expand All @@ -29,6 +31,9 @@ public class ManiaModInvert : Mod, IApplicableAfterBeatmapConversion

public override Type[] IncompatibleMods => new[] { typeof(ManiaModHoldOff) };

[SettingSource("Invert Long Notes", "Invert long notes into nothing.")]
public BindableBool FullInvert { get; } = new BindableBool();

public void ApplyToBeatmap(IBeatmap beatmap)
{
var maniaBeatmap = (ManiaBeatmap)beatmap;
Expand All @@ -39,24 +44,34 @@ public void ApplyToBeatmap(IBeatmap beatmap)
{
var newColumnObjects = new List<ManiaHitObject>();

var locations = column.OfType<Note>().Select(n => (startTime: n.StartTime, samples: n.Samples))
.Concat(column.OfType<HoldNote>().SelectMany(h => new[]
{
(startTime: h.StartTime, samples: h.GetNodeSamples(0)),
(startTime: h.EndTime, samples: h.GetNodeSamples(1))
}))
.OrderBy(h => h.startTime).ToList();
List<(double startTime, IList<HitSampleInfo> samples, string type)> locations;

if (FullInvert.Value)
locations = column.OfType<Note>().Select(n => (startTime: n.StartTime, samples: n.Samples, type: "note"))
.Concat(column.OfType<HoldNote>().SelectMany(h => new[]
{
(startTime: h.StartTime, samples: h.GetNodeSamples(0), type: "release"),
(startTime: h.EndTime, samples: h.GetNodeSamples(1), type: "note")
}))
.OrderBy(h => h.startTime).ToList();
else
locations = column.Select(n => (startTime: n.StartTime, samples: n.Samples, type: "note"))
.OrderBy(h => h.startTime).ToList();

for (int i = 0; i < locations.Count - 1; i++)
{
// Full duration of the hold note.
double duration = locations[i + 1].startTime - locations[i].startTime;
if (locations[i].type == "release")
continue;

// Beat length at the end of the hold note.
double beatLength = beatmap.ControlPointInfo.TimingPointAt(locations[i + 1].startTime).BeatLength;

// Decrease the duration by at most a 1/4 beat to ensure there's no instantaneous notes.
duration = Math.Max(duration / 2, duration - beatLength / 4);
// Full duration of the hold note.
double duration = locations[i + 1].startTime - locations[i].startTime;

if (locations[i + 1].type != "release")
// Decrease the duration by at most a 1/4 beat to ensure there's no instantaneous notes.
duration = Math.Max(duration / 2, duration - beatLength / 4);

newColumnObjects.Add(new HoldNote
{
Expand Down