1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 09:23:06 +08:00

Add test coverage for legacy beatmap combo offsets

This commit is contained in:
Salman Ahmed 2021-05-05 09:22:19 +03:00
parent 4cdfdcaddf
commit 71d3b44c78

View File

@ -1,6 +1,8 @@
// 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.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
@ -11,6 +13,7 @@ using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Skinning;
using osu.Game.Tests.Beatmaps;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Tests
{
@ -77,23 +80,96 @@ namespace osu.Game.Rulesets.Osu.Tests
AddAssert("is custom user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestSkin.Colours));
}
[TestCase(true, true)]
[TestCase(true, false)]
[TestCase(false, true)]
[TestCase(false, false)]
public void TestLegacyOffsetWithBeatmapColours(bool userHasCustomColours, bool useBeatmapSkin)
{
TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, true, getHitCirclesWithLegacyOffsets());
base.TestBeatmapComboColours(userHasCustomColours, useBeatmapSkin);
assertCorrectObjectComboColours("is beatmap skin colours with legacy offsets applied",
TestBeatmapSkin.Colours,
(i, obj) => i + 1 + obj.LegacyBeatmapComboOffset);
}
[TestCase(true)]
[TestCase(false)]
public void TestLegacyOffsetWithIgnoredBeatmapColours(bool useBeatmapSkin)
{
TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, true, getHitCirclesWithLegacyOffsets());
base.TestBeatmapComboColoursOverride(useBeatmapSkin);
assertCorrectObjectComboColours("is user skin colours without legacy offsets applied",
TestSkin.Colours,
(i, _) => i + 1);
}
private void assertCorrectObjectComboColours(string description, Color4[] expectedColours, Func<int, OsuHitObject, int> nextExpectedComboIndex)
{
AddUntilStep("wait for objects to become alive", () =>
TestPlayer.DrawableRuleset.Playfield.AllHitObjects.Count() == TestPlayer.DrawableRuleset.Objects.Count());
AddAssert(description, () =>
{
int index = 0;
foreach (var drawable in TestPlayer.DrawableRuleset.Playfield.AllHitObjects)
{
index = nextExpectedComboIndex(index, (OsuHitObject)drawable.HitObject);
if (drawable.AccentColour.Value != expectedColours[index % expectedColours.Length])
return false;
}
return true;
});
}
private static IEnumerable<OsuHitObject> getHitCirclesWithLegacyOffsets()
{
var hitObjects = new List<OsuHitObject>();
for (int i = 0; i < 5; i++)
{
hitObjects.Add(new HitCircle
{
StartTime = i,
Position = new Vector2(256, 192),
NewCombo = true,
LegacyBeatmapComboOffset = i,
});
}
return hitObjects;
}
private class OsuCustomSkinWorkingBeatmap : CustomSkinWorkingBeatmap
{
public OsuCustomSkinWorkingBeatmap(AudioManager audio, bool hasColours)
: base(createBeatmap(), audio, hasColours)
public OsuCustomSkinWorkingBeatmap(AudioManager audio, bool hasColours, IEnumerable<OsuHitObject> hitObjects = null)
: base(createBeatmap(hitObjects), audio, hasColours)
{
}
private static IBeatmap createBeatmap() =>
new Beatmap
private static IBeatmap createBeatmap(IEnumerable<OsuHitObject> hitObjects)
{
var beatmap = new Beatmap
{
BeatmapInfo =
{
BeatmapSet = new BeatmapSetInfo(),
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { new HitCircle { Position = new Vector2(256, 192) } }
};
beatmap.HitObjects.AddRange(hitObjects ?? new[]
{
new HitCircle { Position = new Vector2(256, 192) }
});
return beatmap;
}
}
}
}