2022-01-29 05:59:53 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mania.Mods;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mania.Difficulty;
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Tests.Mods
|
|
|
|
{
|
|
|
|
public class TestSceneManiaModHoldOff : ModTestScene
|
|
|
|
{
|
|
|
|
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMapHasNoHoldNotes()
|
|
|
|
{
|
|
|
|
var testBeatmap = createModdedBeatmap();
|
|
|
|
Assert.False(testBeatmap.HitObjects.OfType<HoldNote>().Any());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCorrectNoteValues()
|
|
|
|
{
|
|
|
|
var testBeatmap = createRawBeatmap();
|
|
|
|
var noteValues = new List<double>(testBeatmap.HitObjects.OfType<HoldNote>().Count());
|
2022-01-29 13:05:23 +08:00
|
|
|
|
|
|
|
foreach (HoldNote h in testBeatmap.HitObjects.OfType<HoldNote>())
|
|
|
|
{
|
2022-01-29 13:06:43 +08:00
|
|
|
noteValues.Add(ManiaModHoldOff.GetNoteDurationInBeatLength(h, testBeatmap));
|
2022-01-29 05:59:53 +08:00
|
|
|
}
|
2022-01-29 13:05:23 +08:00
|
|
|
|
2022-01-29 05:59:53 +08:00
|
|
|
noteValues.Sort();
|
|
|
|
Assert.AreEqual(noteValues, new List<double> { 0.125, 0.250, 0.500, 1.000, 2.000 });
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(ManiaModHoldOff.BeatDivisors.Whole)]
|
|
|
|
[TestCase(ManiaModHoldOff.BeatDivisors.Half)]
|
|
|
|
[TestCase(ManiaModHoldOff.BeatDivisors.Quarter)]
|
|
|
|
[TestCase(ManiaModHoldOff.BeatDivisors.Eighth)]
|
2022-01-29 13:05:23 +08:00
|
|
|
public void TestCorrectObjectCount(ManiaModHoldOff.BeatDivisors minBeatSnap)
|
|
|
|
{
|
2022-01-29 05:59:53 +08:00
|
|
|
/*
|
|
|
|
This test is to ensure that, given that end notes are enabled,
|
|
|
|
the mod produces the expected number of objects when the mod is applied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Mod settings will be set to include the correct beat snap value
|
|
|
|
var rawBeatmap = createRawBeatmap();
|
|
|
|
var testBeatmap = createModdedBeatmap(minBeatSnap);
|
|
|
|
|
|
|
|
// Calculate expected number of objects
|
|
|
|
int expectedObjectCount = 0;
|
2022-01-29 13:05:23 +08:00
|
|
|
double beatSnapValue = 1 / (Math.Pow(2, (int)minBeatSnap));
|
2022-01-29 05:59:53 +08:00
|
|
|
|
2022-01-29 13:05:23 +08:00
|
|
|
foreach (ManiaHitObject h in rawBeatmap.HitObjects)
|
|
|
|
{
|
2022-01-29 05:59:53 +08:00
|
|
|
// Both notes and hold notes account for at least one object
|
|
|
|
expectedObjectCount++;
|
2022-01-29 13:05:23 +08:00
|
|
|
|
|
|
|
if (h.GetType() == typeof(HoldNote))
|
|
|
|
{
|
2022-01-29 13:06:43 +08:00
|
|
|
double noteValue = ManiaModHoldOff.GetNoteDurationInBeatLength((HoldNote)h, rawBeatmap);
|
2022-01-29 13:05:23 +08:00
|
|
|
|
|
|
|
if (noteValue >= beatSnapValue)
|
|
|
|
{
|
2022-01-29 05:59:53 +08:00
|
|
|
// Should generate an end note if it's longer than the minimum note value
|
|
|
|
expectedObjectCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:43 +08:00
|
|
|
Assert.That(testBeatmap.HitObjects.Count == expectedObjectCount);
|
2022-01-29 05:59:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-01-29 13:05:23 +08:00
|
|
|
public void TestDifficultyIncrease()
|
|
|
|
{
|
2022-01-29 05:59:53 +08:00
|
|
|
// A lower minimum beat snap divisor should only make the map harder, never easier
|
|
|
|
// (as more notes can be spawned)
|
2022-01-29 13:06:43 +08:00
|
|
|
var beatmaps = new[]
|
2022-01-29 13:05:23 +08:00
|
|
|
{
|
2022-01-29 13:06:43 +08:00
|
|
|
createModdedBeatmap(),
|
2022-01-29 05:59:53 +08:00
|
|
|
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Half),
|
|
|
|
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Quarter),
|
|
|
|
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Eighth),
|
|
|
|
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Sixteenth)
|
|
|
|
};
|
|
|
|
|
2022-01-29 13:06:43 +08:00
|
|
|
double[] mapDifficulties = new double[beatmaps.Length];
|
2022-01-29 13:05:23 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < mapDifficulties.Length; i++)
|
|
|
|
{
|
2022-01-29 05:59:53 +08:00
|
|
|
var workingBeatmap = new TestWorkingBeatmap(beatmaps[i]);
|
|
|
|
var difficultyCalculator = new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, workingBeatmap);
|
|
|
|
mapDifficulties[i] = difficultyCalculator.Calculate().StarRating;
|
2022-01-29 13:05:23 +08:00
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
Assert.LessOrEqual(mapDifficulties[i - 1], mapDifficulties[i]);
|
|
|
|
Assert.LessOrEqual(beatmaps[i - 1].HitObjects.Count, beatmaps[i].HitObjects.Count);
|
2022-01-29 05:59:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 13:05:23 +08:00
|
|
|
private static ManiaBeatmap createModdedBeatmap(ManiaModHoldOff.BeatDivisors minBeatSnap = ManiaModHoldOff.BeatDivisors.Whole)
|
2022-01-29 05:59:53 +08:00
|
|
|
{
|
|
|
|
var beatmap = createRawBeatmap();
|
2022-01-29 13:06:43 +08:00
|
|
|
var holdOffMod = new ManiaModHoldOff
|
|
|
|
{
|
|
|
|
MinBeatSnap = { Value = minBeatSnap }
|
|
|
|
};
|
2022-01-29 05:59:53 +08:00
|
|
|
Assert.AreEqual(holdOffMod.MinBeatSnap.Value, minBeatSnap);
|
|
|
|
|
|
|
|
foreach (var hitObject in beatmap.HitObjects)
|
|
|
|
hitObject.ApplyDefaults(beatmap.ControlPointInfo, new BeatmapDifficulty());
|
|
|
|
|
|
|
|
holdOffMod.ApplyToBeatmap(beatmap);
|
|
|
|
|
2022-01-29 13:06:43 +08:00
|
|
|
return beatmap;
|
2022-01-29 05:59:53 +08:00
|
|
|
}
|
2022-01-29 13:05:23 +08:00
|
|
|
|
2022-01-29 05:59:53 +08:00
|
|
|
private static ManiaBeatmap createRawBeatmap()
|
|
|
|
{
|
|
|
|
var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 });
|
2022-01-29 13:05:23 +08:00
|
|
|
beatmap.ControlPointInfo.Add(0.0, new TimingControlPoint { BeatLength = 1000 }); // Set BPM to 60
|
2022-01-29 05:59:53 +08:00
|
|
|
|
|
|
|
// Add test hit objects
|
|
|
|
beatmap.HitObjects.Add(new Note { StartTime = 4000 });
|
|
|
|
beatmap.HitObjects.Add(new Note { StartTime = 4500 });
|
2022-01-29 13:05:23 +08:00
|
|
|
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 125 }); // 1/8 note
|
|
|
|
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 250 }); // 1/4 note
|
|
|
|
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 500 }); // 1/2 note
|
2022-01-29 05:59:53 +08:00
|
|
|
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 1000 }); // 1/1 note
|
|
|
|
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 2000 }); // 2/1 note
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|