mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 13:23:22 +08:00
Implement mania invert mod
This commit is contained in:
parent
ab0d6b7d5a
commit
583760100a
@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Rulesets.Mania.Mods;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Tests.Mods
|
||||
{
|
||||
public class TestSceneManiaModInvert : ModTestScene
|
||||
{
|
||||
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
|
||||
|
||||
[Test]
|
||||
public void TestInversion() => CreateModTest(new ModTestData
|
||||
{
|
||||
Mod = new ManiaModInvert(),
|
||||
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2
|
||||
});
|
||||
}
|
||||
}
|
@ -220,6 +220,7 @@ namespace osu.Game.Rulesets.Mania
|
||||
new ManiaModDualStages(),
|
||||
new ManiaModMirror(),
|
||||
new ManiaModDifficultyAdjust(),
|
||||
new ManiaModInvert(),
|
||||
};
|
||||
|
||||
case ModType.Automation:
|
||||
|
68
osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs
Normal file
68
osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs
Normal file
@ -0,0 +1,68 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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.";
|
||||
|
||||
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();
|
||||
|
||||
for (int i = 0; i < locations.Count - 1; i += 2)
|
||||
{
|
||||
newColumnObjects.Add(new HoldNote
|
||||
{
|
||||
Column = column.Key,
|
||||
StartTime = locations[i].startTime,
|
||||
Duration = locations[i + 1].startTime - locations[i].startTime,
|
||||
Samples = locations[i].samples,
|
||||
NodeSamples = new List<IList<HitSampleInfo>>
|
||||
{
|
||||
locations[i].samples,
|
||||
locations[i + 1].samples
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
newObjects.AddRange(newColumnObjects);
|
||||
}
|
||||
|
||||
maniaBeatmap.HitObjects = newObjects.OrderBy(h => h.StartTime).ToList();
|
||||
|
||||
// No breaks
|
||||
maniaBeatmap.Breaks.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -102,14 +102,14 @@ namespace osu.Game.Rulesets.Mania.Objects
|
||||
{
|
||||
StartTime = StartTime,
|
||||
Column = Column,
|
||||
Samples = getNodeSamples(0),
|
||||
Samples = GetNodeSamples(0),
|
||||
});
|
||||
|
||||
AddNested(Tail = new TailNote
|
||||
{
|
||||
StartTime = EndTime,
|
||||
Column = Column,
|
||||
Samples = getNodeSamples((NodeSamples?.Count - 1) ?? 1),
|
||||
Samples = GetNodeSamples((NodeSamples?.Count - 1) ?? 1),
|
||||
});
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace osu.Game.Rulesets.Mania.Objects
|
||||
|
||||
protected override HitWindows CreateHitWindows() => HitWindows.Empty;
|
||||
|
||||
private IList<HitSampleInfo> getNodeSamples(int nodeIndex) =>
|
||||
public IList<HitSampleInfo> GetNodeSamples(int nodeIndex) =>
|
||||
nodeIndex < NodeSamples?.Count ? NodeSamples[nodeIndex] : Samples;
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,15 @@ namespace osu.Game.Beatmaps
|
||||
// Convert
|
||||
IBeatmap converted = converter.Convert();
|
||||
|
||||
// Apply conversion mods to the result
|
||||
foreach (var mod in mods.OfType<IApplicableAfterBeatmapConversion>())
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
mod.ApplyToBeatmap(converted);
|
||||
}
|
||||
|
||||
// Apply difficulty mods
|
||||
if (mods.Any(m => m is IApplicableToDifficulty))
|
||||
{
|
||||
|
19
osu.Game/Rulesets/Mods/IApplicableAfterBeatmapConversion.cs
Normal file
19
osu.Game/Rulesets/Mods/IApplicableAfterBeatmapConversion.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for a <see cref="Mod"/> that applies changes to the <see cref="IBeatmap"/> generated by the <see cref="BeatmapConverter{TObject}"/>.
|
||||
/// </summary>
|
||||
public interface IApplicableAfterBeatmapConversion : IApplicableMod
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies this <see cref="Mod"/> to the <see cref="IBeatmap"/> after conversion has taken place.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The converted <see cref="IBeatmap"/>.</param>
|
||||
void ApplyToBeatmap(IBeatmap beatmap);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user