mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09: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:
@ -10,6 +10,7 @@ using osu.Framework.Allocation;
|
|||||||
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.Configuration;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
@ -53,10 +54,14 @@ namespace osu.Game.Tests.Visual
|
|||||||
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;
|
||||||
|
|
||||||
|
public void SetRuleset(RulesetInfo ruleset) => Ruleset.Value = ruleset;
|
||||||
|
|
||||||
|
public int? RulesetID => Ruleset.Value.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuGameBase game)
|
private void load(OsuGameBase game, OsuConfigManager config)
|
||||||
{
|
{
|
||||||
TestSongSelect songSelect = null;
|
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 Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
|
||||||
AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
|
AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
|
||||||
AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
|
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)
|
private BeatmapSetInfo createTestBeatmapSet(int i)
|
||||||
@ -134,7 +157,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
new BeatmapInfo
|
new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 1234 + i,
|
OnlineBeatmapID = 1234 + i,
|
||||||
Ruleset = rulesets.AvailableRulesets.First(),
|
Ruleset = rulesets.AvailableRulesets.ElementAt(0),
|
||||||
|
RulesetID = 0,
|
||||||
Path = "normal.osu",
|
Path = "normal.osu",
|
||||||
Version = "Normal",
|
Version = "Normal",
|
||||||
BaseDifficulty = new BeatmapDifficulty
|
BaseDifficulty = new BeatmapDifficulty
|
||||||
@ -145,8 +169,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
new BeatmapInfo
|
new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 1235 + i,
|
OnlineBeatmapID = 1235 + i,
|
||||||
Ruleset = rulesets.AvailableRulesets.First(),
|
Ruleset = rulesets.AvailableRulesets.First(r => r.ID != 0),
|
||||||
Path = "hard.osu",
|
RulesetID = 1,
|
||||||
|
Path = "hard.taiko",
|
||||||
Version = "Hard",
|
Version = "Hard",
|
||||||
BaseDifficulty = new BeatmapDifficulty
|
BaseDifficulty = new BeatmapDifficulty
|
||||||
{
|
{
|
||||||
@ -156,8 +181,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
new BeatmapInfo
|
new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 1236 + i,
|
OnlineBeatmapID = 1236 + i,
|
||||||
Ruleset = rulesets.AvailableRulesets.First(),
|
Ruleset = rulesets.AvailableRulesets.ElementAt(2),
|
||||||
Path = "insane.osu",
|
RulesetID = 2,
|
||||||
|
Path = "insane.fruits",
|
||||||
Version = "Insane",
|
Version = "Insane",
|
||||||
BaseDifficulty = new BeatmapDifficulty
|
BaseDifficulty = new BeatmapDifficulty
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
@ -9,12 +10,14 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
@ -63,6 +66,8 @@ namespace osu.Game.Screens.Select
|
|||||||
private SampleChannel sampleChangeDifficulty;
|
private SampleChannel sampleChangeDifficulty;
|
||||||
private SampleChannel sampleChangeBeatmap;
|
private SampleChannel sampleChangeBeatmap;
|
||||||
|
|
||||||
|
private Bindable<bool> rulesetConversionAllowed;
|
||||||
|
|
||||||
private CancellationTokenSource initialAddSetsTask;
|
private CancellationTokenSource initialAddSetsTask;
|
||||||
|
|
||||||
private DependencyContainer dependencies;
|
private DependencyContainer dependencies;
|
||||||
@ -179,7 +184,7 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(permitNulls: true)]
|
[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);
|
dependencies.CacheAs(this);
|
||||||
|
|
||||||
@ -194,6 +199,8 @@ namespace osu.Game.Screens.Select
|
|||||||
if (this.beatmaps == null)
|
if (this.beatmaps == null)
|
||||||
this.beatmaps = beatmaps;
|
this.beatmaps = beatmaps;
|
||||||
|
|
||||||
|
rulesetConversionAllowed = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps);
|
||||||
|
|
||||||
if (osu != null)
|
if (osu != null)
|
||||||
Ruleset.BindTo(osu.Ruleset);
|
Ruleset.BindTo(osu.Ruleset);
|
||||||
|
|
||||||
@ -217,7 +224,10 @@ namespace osu.Game.Screens.Select
|
|||||||
Beatmap.ValueChanged += b =>
|
Beatmap.ValueChanged += b =>
|
||||||
{
|
{
|
||||||
if (IsCurrentScreen)
|
if (IsCurrentScreen)
|
||||||
|
{
|
||||||
Carousel.SelectBeatmap(b?.BeatmapInfo);
|
Carousel.SelectBeatmap(b?.BeatmapInfo);
|
||||||
|
ensurePlayableRuleset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,6 +326,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
|
||||||
|
ensurePlayableRuleset();
|
||||||
Content.FadeInFromZero(250);
|
Content.FadeInFromZero(250);
|
||||||
FilterControl.Activate();
|
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 onBeatmapSetAdded(BeatmapSetInfo s) => Carousel.UpdateBeatmapSet(s);
|
||||||
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Carousel.RemoveBeatmapSet(s);
|
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Carousel.RemoveBeatmapSet(s);
|
||||||
private void onBeatmapRestored(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
|
private void onBeatmapRestored(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
|
||||||
|
Reference in New Issue
Block a user