1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Update mod per discussion + create test

This commit is contained in:
Spooghetti420 2022-01-27 20:56:51 +00:00
parent 400633bd99
commit 3e068e564d
3 changed files with 128 additions and 1 deletions

View File

@ -0,0 +1,52 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Tests.Visual;
using osu.Game.Rulesets.Mania.Tests;
using System.Collections.Generic;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Mania.Beatmaps;
namespace osu.Game.Rulesets.Mania.Tests.Mods
{
public class TestSceneManiaModNoHolds : ModTestScene
{
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
[Test]
public void TestMapHasNoHeldNotes()
{
var testBeatmap = createBeatmap();
Assert.That(!testBeatmap.HitObjects.OfType<HoldNote>().Any());
}
private static IBeatmap createBeatmap()
{
var beatmap = createRawBeatmap();
var noHoldsMod = new ManiaModNoHolds();
foreach (var hitObject in beatmap.HitObjects)
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
noHoldsMod.ApplyToBeatmap(beatmap);
return beatmap;
}
private static IBeatmap createRawBeatmap()
{
var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 });
beatmap.HitObjects.Add(new Note { StartTime = 1000 });
beatmap.HitObjects.Add(new HoldNote { StartTime = 1000, EndTime = 3000 });
return beatmap;
}
}
}

View File

@ -244,7 +244,7 @@ namespace osu.Game.Rulesets.Mania
new ManiaModClassic(),
new ManiaModInvert(),
new ManiaModConstantSpeed(),
new ManiaModNoLongNotes()
new ManiaModNoHolds()
};
case ModType.Automation:

View File

@ -0,0 +1,75 @@
// 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.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mods;
using osu.Framework.Graphics.Sprites;
using System;
using System.Collections.Generic;
using osu.Game.Audio;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Framework.Utils;
using osu.Game.Overlays.Settings;
using osu.Framework.Bindables;
using osu.Game.Configuration;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mania.Mods
{
public class ManiaModNoHolds : Mod, IApplicableAfterBeatmapConversion
{
public override string Name => "No Holds";
public override string Acronym => "NH";
public override double ScoreMultiplier => 1;
public override string Description => @"Turns all hold notes into normal notes. No coordination required.";
public override IconUsage? Icon => FontAwesome.Solid.DotCircle;
public override ModType Type => ModType.Conversion;
[SettingSource("Add end notes", "Also add a note at the end of a hold note")]
public BindableBool AddEndNotes { get; } = new BindableBool
{
Default = true,
Value = true
};
public void ApplyToBeatmap(IBeatmap beatmap)
{
var maniaBeatmap = (ManiaBeatmap)beatmap;
var newObjects = new List<ManiaHitObject>();
foreach (var h in beatmap.HitObjects.OfType<HoldNote>())
{
// Add a note for the beginning of the hold note
newObjects.Add(new Note
{
Column = h.Column,
StartTime = h.StartTime,
Samples = h.GetNodeSamples(0)
});
// Don't add an end note if the duration is shorter than some threshold, or end notes are disabled
if (AddEndNotes.Value && h.Duration > 200)
{
newObjects.Add(new Note
{
Column = h.Column,
StartTime = h.EndTime,
Samples = h.GetNodeSamples((h.NodeSamples?.Count - 1) ?? 1)
});
}
}
maniaBeatmap.HitObjects = maniaBeatmap.HitObjects.OfType<Note>().Concat(newObjects).OrderBy(h => h.StartTime).ToList();
}
}
}