mirror of
https://github.com/ppy/osu.git
synced 2024-09-21 23:27:25 +08:00
Add function to check for (and return) invalid mods
This commit is contained in:
parent
b9832c1b2d
commit
ead8262257
@ -83,6 +83,48 @@ namespace osu.Game.Utils
|
|||||||
.All(m => allowedSet.Contains(m.GetType()));
|
.All(m => allowedSet.Contains(m.GetType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check the provided combination of mods are valid for a local gameplay session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mods">The mods to check.</param>
|
||||||
|
/// <param name="invalidMods">Invalid mods, if any where found. Can 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, out Mod[]? invalidMods)
|
||||||
|
{
|
||||||
|
mods = mods.ToArray();
|
||||||
|
|
||||||
|
List<Mod>? foundInvalid = null;
|
||||||
|
|
||||||
|
void addInvalid(Mod mod)
|
||||||
|
{
|
||||||
|
foundInvalid ??= new List<Mod>();
|
||||||
|
foundInvalid.Add(mod);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var mod in mods)
|
||||||
|
{
|
||||||
|
bool valid = mod.Type != ModType.System
|
||||||
|
&& mod.HasImplementation
|
||||||
|
&& !(mod is MultiMod);
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
// if this mod was found as invalid, we can exclude it before potentially excluding more incompatible types.
|
||||||
|
addInvalid(mod);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var type in mod.IncompatibleMods)
|
||||||
|
{
|
||||||
|
foreach (var invalid in mods.Where(m => type.IsInstanceOfType(m)))
|
||||||
|
addInvalid(invalid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidMods = foundInvalid?.ToArray();
|
||||||
|
return foundInvalid == null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Flattens a set of <see cref="Mod"/>s, returning a new set with all <see cref="MultiMod"/>s removed.
|
/// Flattens a set of <see cref="Mod"/>s, returning a new set with all <see cref="MultiMod"/>s removed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user