mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Ensure duplicate mods cannot be defined
This commit is contained in:
@ -51,14 +51,31 @@ namespace osu.Game.Utils
|
||||
/// <returns>Whether all <see cref="Mod"/>s in the combination are compatible with each-other.</returns>
|
||||
public static bool CheckCompatibleSet(IEnumerable<Mod> combination, [NotNullWhen(false)] out List<Mod>? invalidMods)
|
||||
{
|
||||
combination = FlattenMods(combination).ToArray();
|
||||
var mods = FlattenMods(combination).ToArray();
|
||||
invalidMods = null;
|
||||
|
||||
foreach (var mod in combination)
|
||||
// ensure there are no duplicate mod definitions.
|
||||
for (int i = 0; i < mods.Length; i++)
|
||||
{
|
||||
var candidate = mods[i];
|
||||
|
||||
for (int j = i + 1; j < mods.Length; j++)
|
||||
{
|
||||
var m = mods[j];
|
||||
|
||||
if (candidate.Equals(m))
|
||||
{
|
||||
invalidMods ??= new List<Mod>();
|
||||
invalidMods.Add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var mod in mods)
|
||||
{
|
||||
foreach (var type in mod.IncompatibleMods)
|
||||
{
|
||||
foreach (var invalid in combination.Where(m => type.IsInstanceOfType(m)))
|
||||
foreach (var invalid in mods.Where(m => type.IsInstanceOfType(m)))
|
||||
{
|
||||
if (invalid == mod)
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user