mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Test that changing ruleset resets mods
This commit is contained in:
parent
970aa811bd
commit
15bd7e4f1f
@ -8,11 +8,15 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
|
using osu.Game.Rulesets.Taiko;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
using osu.Game.Screens.Select.Carousel;
|
using osu.Game.Screens.Select.Carousel;
|
||||||
using osu.Game.Screens.Select.Filter;
|
using osu.Game.Screens.Select.Filter;
|
||||||
@ -29,6 +33,10 @@ namespace osu.Game.Tests.Visual
|
|||||||
private WorkingBeatmap defaultBeatmap;
|
private WorkingBeatmap defaultBeatmap;
|
||||||
private DatabaseContextFactory factory;
|
private DatabaseContextFactory factory;
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
|
||||||
|
private readonly Bindable<IEnumerable<Mod>> selectedMods = new Bindable<IEnumerable<Mod>>(new Mod[] { });
|
||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(SongSelect),
|
typeof(SongSelect),
|
||||||
@ -49,6 +57,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
private class TestSongSelect : PlaySongSelect
|
private class TestSongSelect : PlaySongSelect
|
||||||
{
|
{
|
||||||
|
public new Bindable<RulesetInfo> Ruleset => base.Ruleset;
|
||||||
|
|
||||||
public WorkingBeatmap CurrentBeatmap => Beatmap.Value;
|
public WorkingBeatmap CurrentBeatmap => Beatmap.Value;
|
||||||
public WorkingBeatmap CurrentBeatmapDetailsBeatmap => BeatmapDetails.Beatmap;
|
public WorkingBeatmap CurrentBeatmapDetailsBeatmap => BeatmapDetails.Beatmap;
|
||||||
public new BeatmapCarousel Carousel => base.Carousel;
|
public new BeatmapCarousel Carousel => base.Carousel;
|
||||||
@ -143,11 +153,42 @@ namespace osu.Game.Tests.Visual
|
|||||||
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection");
|
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRulesetChangeResetsMods()
|
||||||
|
{
|
||||||
|
changeRuleset(0);
|
||||||
|
|
||||||
|
changeMods(new OsuModHardRock());
|
||||||
|
|
||||||
|
int actionIndex = 0;
|
||||||
|
int modChangeIndex = 0;
|
||||||
|
int rulesetChangeIndex = 0;
|
||||||
|
|
||||||
|
AddStep("change ruleset", () =>
|
||||||
|
{
|
||||||
|
songSelect.CurrentBeatmap.Mods.ValueChanged += onModChange;
|
||||||
|
songSelect.Ruleset.ValueChanged += onRulesetChange;
|
||||||
|
|
||||||
|
Ruleset.Value = new TaikoRuleset().RulesetInfo;
|
||||||
|
|
||||||
|
songSelect.CurrentBeatmap.Mods.ValueChanged -= onModChange;
|
||||||
|
songSelect.Ruleset.ValueChanged -= onRulesetChange;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("mods changed before ruleset", () => modChangeIndex < rulesetChangeIndex);
|
||||||
|
AddAssert("empty mods", () => !selectedMods.Value.Any());
|
||||||
|
|
||||||
|
void onModChange(IEnumerable<Mod> mods) => modChangeIndex = actionIndex++;
|
||||||
|
void onRulesetChange(RulesetInfo ruleset) => rulesetChangeIndex = actionIndex--;
|
||||||
|
}
|
||||||
|
|
||||||
private void importForRuleset(int id) => AddStep($"import test map for ruleset {id}", () => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())));
|
private void importForRuleset(int id) => AddStep($"import test map for ruleset {id}", () => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())));
|
||||||
|
|
||||||
private static int importId;
|
private static int importId;
|
||||||
private int getImportId() => ++importId;
|
private int getImportId() => ++importId;
|
||||||
|
|
||||||
|
private void changeMods(params Mod[] mods) => AddStep($"change mods to {string.Join(", ", mods.Select(m => m.ShortenedName))}", () => selectedMods.Value = mods);
|
||||||
|
|
||||||
private void changeRuleset(int id) => AddStep($"change ruleset to {id}", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == id));
|
private void changeRuleset(int id) => AddStep($"change ruleset to {id}", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == id));
|
||||||
|
|
||||||
private void addManyTestMaps()
|
private void addManyTestMaps()
|
||||||
|
Loading…
Reference in New Issue
Block a user