mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:12:57 +08:00
Make song select ensure current beatmap is always playable in the active ruleset.
- Add a to TestCasePlaySongSelect testing this scenario
This commit is contained in:
parent
e7bd4ea0c7
commit
fb724ca8a7
@ -10,6 +10,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Select;
|
||||
@ -53,10 +54,14 @@ namespace osu.Game.Tests.Visual
|
||||
public WorkingBeatmap CurrentBeatmap => Beatmap.Value;
|
||||
public WorkingBeatmap CurrentBeatmapDetailsBeatmap => BeatmapDetails.Beatmap;
|
||||
public new BeatmapCarousel Carousel => base.Carousel;
|
||||
|
||||
public void SetRuleset(RulesetInfo ruleset) => Ruleset.Value = ruleset;
|
||||
|
||||
public int? RulesetID => Ruleset.Value.ID;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game)
|
||||
private void load(OsuGameBase game, OsuConfigManager config)
|
||||
{
|
||||
TestSongSelect songSelect = null;
|
||||
|
||||
@ -113,6 +118,24 @@ namespace osu.Game.Tests.Visual
|
||||
AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
|
||||
AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
|
||||
AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
|
||||
|
||||
AddWaitStep(5);
|
||||
|
||||
AddStep(@"Set unplayable WorkingBeatmap", () =>
|
||||
{
|
||||
var testMap = manager.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID != 0);
|
||||
songSelect.SetRuleset(rulesets.AvailableRulesets.First());
|
||||
game.Beatmap.Value = manager.GetWorkingBeatmap(testMap);
|
||||
});
|
||||
AddAssert(@"WorkingBeatmap changed to playable ruleset", () => songSelect.RulesetID == 0 && game.Beatmap.Value.BeatmapInfo.RulesetID == 0);
|
||||
AddStep(@"Disallow beatmap conversion", () =>
|
||||
{
|
||||
config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps).Value = false;
|
||||
game.Beatmap.Value = manager.GetWorkingBeatmap(manager.GetAllUsableBeatmapSets().First().Beatmaps.First());
|
||||
});
|
||||
loadNewSongSelect();
|
||||
AddWaitStep(3);
|
||||
AddAssert(@"Ruleset matches beatmap", () => songSelect.RulesetID == game.Beatmap.Value.BeatmapInfo.RulesetID);
|
||||
}
|
||||
|
||||
private BeatmapSetInfo createTestBeatmapSet(int i)
|
||||
@ -134,7 +157,8 @@ namespace osu.Game.Tests.Visual
|
||||
new BeatmapInfo
|
||||
{
|
||||
OnlineBeatmapID = 1234 + i,
|
||||
Ruleset = rulesets.AvailableRulesets.First(),
|
||||
Ruleset = rulesets.AvailableRulesets.ElementAt(0),
|
||||
RulesetID = 0,
|
||||
Path = "normal.osu",
|
||||
Version = "Normal",
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
@ -145,8 +169,9 @@ namespace osu.Game.Tests.Visual
|
||||
new BeatmapInfo
|
||||
{
|
||||
OnlineBeatmapID = 1235 + i,
|
||||
Ruleset = rulesets.AvailableRulesets.First(),
|
||||
Path = "hard.osu",
|
||||
Ruleset = rulesets.AvailableRulesets.First(r => r.ID != 0),
|
||||
RulesetID = 1,
|
||||
Path = "hard.taiko",
|
||||
Version = "Hard",
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
{
|
||||
@ -156,8 +181,9 @@ namespace osu.Game.Tests.Visual
|
||||
new BeatmapInfo
|
||||
{
|
||||
OnlineBeatmapID = 1236 + i,
|
||||
Ruleset = rulesets.AvailableRulesets.First(),
|
||||
Path = "insane.osu",
|
||||
Ruleset = rulesets.AvailableRulesets.ElementAt(2),
|
||||
RulesetID = 2,
|
||||
Path = "insane.fruits",
|
||||
Version = "Insane",
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
@ -9,12 +10,14 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
@ -63,6 +66,8 @@ namespace osu.Game.Screens.Select
|
||||
private SampleChannel sampleChangeDifficulty;
|
||||
private SampleChannel sampleChangeBeatmap;
|
||||
|
||||
private Bindable<bool> rulesetConversionAllowed;
|
||||
|
||||
private CancellationTokenSource initialAddSetsTask;
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
@ -179,7 +184,7 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours)
|
||||
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours, OsuConfigManager config)
|
||||
{
|
||||
dependencies.CacheAs(this);
|
||||
|
||||
@ -194,6 +199,8 @@ namespace osu.Game.Screens.Select
|
||||
if (this.beatmaps == null)
|
||||
this.beatmaps = beatmaps;
|
||||
|
||||
rulesetConversionAllowed = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps);
|
||||
|
||||
if (osu != null)
|
||||
Ruleset.BindTo(osu.Ruleset);
|
||||
|
||||
@ -217,7 +224,10 @@ namespace osu.Game.Screens.Select
|
||||
Beatmap.ValueChanged += b =>
|
||||
{
|
||||
if (IsCurrentScreen)
|
||||
{
|
||||
Carousel.SelectBeatmap(b?.BeatmapInfo);
|
||||
ensurePlayableRuleset();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -316,6 +326,7 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
base.OnEntering(last);
|
||||
|
||||
ensurePlayableRuleset();
|
||||
Content.FadeInFromZero(250);
|
||||
FilterControl.Activate();
|
||||
}
|
||||
@ -441,6 +452,34 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
private void ensurePlayableRuleset()
|
||||
{
|
||||
if (Beatmap.IsDefault)
|
||||
// DummyBeatmap won't be playable anyway
|
||||
return;
|
||||
|
||||
bool conversionAllowed = rulesetConversionAllowed.Value;
|
||||
int? currentRuleset = Ruleset.Value.ID;
|
||||
int beatmapRuleset = Beatmap.Value.BeatmapInfo.RulesetID;
|
||||
|
||||
if (currentRuleset == beatmapRuleset || conversionAllowed && beatmapRuleset == 0)
|
||||
// Current beatmap is playable, nothing more to do
|
||||
return;
|
||||
|
||||
// Otherwise, first check if the current beatmapset has any playable beatmaps
|
||||
BeatmapInfo beatmap = Beatmap.Value.BeatmapSetInfo.Beatmaps?.FirstOrDefault(b => b.RulesetID == currentRuleset || conversionAllowed && b.RulesetID == 0);
|
||||
|
||||
// If it does then update the WorkingBeatmap
|
||||
if (beatmap != null)
|
||||
{
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap);
|
||||
return;
|
||||
}
|
||||
|
||||
// If it doesn't, then update the current ruleset so that the current beatmap is playable
|
||||
Ruleset.Value = Beatmap.Value.BeatmapInfo.Ruleset;
|
||||
}
|
||||
|
||||
private void onBeatmapSetAdded(BeatmapSetInfo s) => Carousel.UpdateBeatmapSet(s);
|
||||
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Carousel.RemoveBeatmapSet(s);
|
||||
private void onBeatmapRestored(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
|
||||
|
Loading…
Reference in New Issue
Block a user