2020-08-18 00:40:55 +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.
|
|
|
|
|
2020-08-18 16:40:44 +08:00
|
|
|
using System;
|
2020-08-18 00:40:55 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-08-18 16:23:11 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-08-18 00:40:55 +08:00
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Mods
|
|
|
|
{
|
|
|
|
public class ManiaModInvert : Mod, IApplicableAfterBeatmapConversion
|
|
|
|
{
|
|
|
|
public override string Name => "Invert";
|
|
|
|
|
|
|
|
public override string Acronym => "IN";
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
public override string Description => "Hold the keys. To the beat.";
|
|
|
|
|
2020-08-18 16:23:11 +08:00
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.YinYang;
|
|
|
|
|
2020-08-18 00:40:55 +08:00
|
|
|
public override ModType Type => ModType.Conversion;
|
|
|
|
|
|
|
|
public void ApplyToBeatmap(IBeatmap beatmap)
|
|
|
|
{
|
|
|
|
var maniaBeatmap = (ManiaBeatmap)beatmap;
|
|
|
|
|
|
|
|
var newObjects = new List<ManiaHitObject>();
|
|
|
|
|
|
|
|
foreach (var column in maniaBeatmap.HitObjects.GroupBy(h => h.Column))
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2020-08-18 16:40:44 +08:00
|
|
|
for (int i = 0; i < locations.Count - 1; i++)
|
2020-08-18 00:40:55 +08:00
|
|
|
{
|
2020-08-18 16:40:44 +08:00
|
|
|
// Full duration of the hold note.
|
|
|
|
double duration = locations[i + 1].startTime - locations[i].startTime;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2020-08-18 00:40:55 +08:00
|
|
|
newColumnObjects.Add(new HoldNote
|
|
|
|
{
|
|
|
|
Column = column.Key,
|
|
|
|
StartTime = locations[i].startTime,
|
2020-08-18 16:40:44 +08:00
|
|
|
Duration = duration,
|
2020-08-20 21:38:47 +08:00
|
|
|
NodeSamples = new List<IList<HitSampleInfo>> { locations[i].samples, new List<HitSampleInfo>() }
|
2020-08-18 00:40:55 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
newObjects.AddRange(newColumnObjects);
|
|
|
|
}
|
|
|
|
|
|
|
|
maniaBeatmap.HitObjects = newObjects.OrderBy(h => h.StartTime).ToList();
|
|
|
|
|
|
|
|
// No breaks
|
|
|
|
maniaBeatmap.Breaks.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|