1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Bring back behaviour of checking incompatibility on gameplay validity

This commit is contained in:
Salman Ahmed 2022-05-04 17:21:19 +03:00
parent 20e277d2e5
commit 8f04db5df5
3 changed files with 28 additions and 14 deletions

View File

@ -134,6 +134,18 @@ namespace osu.Game.Tests.Mods
private static readonly object[] invalid_mod_test_scenarios =
{
// incompatible pair.
new object[]
{
new Mod[] { new OsuModDoubleTime(), new OsuModHalfTime() },
new[] { typeof(OsuModDoubleTime), typeof(OsuModHalfTime) }
},
// incompatible pair with derived class.
new object[]
{
new Mod[] { new OsuModNightcore(), new OsuModHalfTime() },
new[] { typeof(OsuModNightcore), typeof(OsuModHalfTime) }
},
// system mod.
new object[]
{

View File

@ -577,16 +577,11 @@ namespace osu.Game
if (SelectedMods.Disabled)
return;
var validMods = mods.NewValue;
if (!ModUtils.CheckCompatibleSet(validMods, out var incompatible))
validMods = validMods.Except(incompatible).ToArray();
if (!ModUtils.CheckValidForGameplay(validMods, out var invalid))
validMods = validMods.Except(invalid).ToArray();
// ensure we always have a valid set of mods.
SelectedMods.Value = validMods;
if (!ModUtils.CheckValidForGameplay(mods.NewValue, out var invalid))
{
// ensure we always have a valid set of mods.
SelectedMods.Value = mods.NewValue.Except(invalid).ToArray();
}
}
#endregion

View File

@ -112,7 +112,7 @@ namespace osu.Game.Utils
/// <param name="invalidMods">Invalid mods, if any were found. Will be null if all mods were valid.</param>
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
public static bool CheckValidForGameplay(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
=> checkValid(mods, m => m.Type != ModType.System && m.HasImplementation && !(m is MultiMod), out invalidMods);
=> checkValid(mods, m => m.Type != ModType.System && m.HasImplementation && !(m is MultiMod), out invalidMods, true);
/// <summary>
/// Checks that all <see cref="Mod"/>s in a combination are valid as "required mods" in a multiplayer match session.
@ -121,7 +121,7 @@ namespace osu.Game.Utils
/// <param name="invalidMods">Invalid mods, if any were found. Will be null if all mods were valid.</param>
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
public static bool CheckValidRequiredModsForMultiplayer(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
=> checkValid(mods, m => m.IsPlayable(ModUsage.MultiplayerGlobal), out invalidMods);
=> checkValid(mods, m => m.IsPlayable(ModUsage.MultiplayerGlobal), out invalidMods, true);
/// <summary>
/// Checks that all <see cref="Mod"/>s in a combination are valid as "free mods" in a multiplayer match session.
@ -130,13 +130,20 @@ namespace osu.Game.Utils
/// <param name="invalidMods">Invalid mods, if any were found. Will be null if all mods were valid.</param>
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
public static bool CheckValidFreeModsForMultiplayer(IEnumerable<Mod> mods, [NotNullWhen(false)] out List<Mod>? invalidMods)
=> checkValid(mods, m => m.IsPlayable(ModUsage.MultiplayerLocal), out invalidMods);
=> checkValid(mods, m => m.IsPlayable(ModUsage.MultiplayerLocal), out invalidMods, false);
private static bool checkValid(IEnumerable<Mod> mods, Predicate<Mod> valid, [NotNullWhen(false)] out List<Mod>? invalidMods)
private static bool checkValid(IEnumerable<Mod> mods, Predicate<Mod> valid, [NotNullWhen(false)] out List<Mod>? invalidMods, bool checkCompatibility)
{
mods = mods.ToArray();
invalidMods = null;
if (checkCompatibility)
{
// exclude multi mods from compatibility checks.
// the loop below automatically marks all multi mods as not valid for gameplay anyway.
CheckCompatibleSet(mods.Where(m => !(m is MultiMod)), out invalidMods);
}
foreach (var mod in mods)
{
if (!valid(mod))