Skip to content

Commit

Permalink
Extract helper property for accessing all mods
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed May 11, 2022
1 parent 11ae1da commit 83ba06e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Func<Mod, bool> IsValidMod

private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
private readonly Dictionary<ModType, IReadOnlyList<ModState>> localAvailableMods = new Dictionary<ModType, IReadOnlyList<ModState>>();
private IEnumerable<ModState> allLocalAvailableMods => localAvailableMods.SelectMany(pair => pair.Value);

private readonly BindableBool customisationVisible = new BindableBool();

Expand Down Expand Up @@ -294,7 +295,7 @@ private void createLocalMods()

private void filterMods()
{
foreach (var modState in localAvailableMods.Values.SelectMany(m => m))
foreach (var modState in allLocalAvailableMods)
modState.Filtered.Value = !modState.Mod.HasImplementation || !IsValidMod.Invoke(modState.Mod);
}

Expand Down Expand Up @@ -372,7 +373,7 @@ private void updateFromExternalSelection()

var newSelection = new List<Mod>();

foreach (var modState in localAvailableMods.SelectMany(pair => pair.Value))
foreach (var modState in allLocalAvailableMods)
{
var matchingSelectedMod = SelectedMods.Value.SingleOrDefault(selected => selected.GetType() == modState.Mod.GetType());

Expand All @@ -399,10 +400,9 @@ private void updateFromInternalSelection()
if (externalSelectionUpdateInProgress)
return;

var candidateSelection = localAvailableMods.SelectMany(pair => pair.Value)
.Where(modState => modState.Active.Value)
.Select(modState => modState.Mod)
.ToArray();
var candidateSelection = allLocalAvailableMods.Where(modState => modState.Active.Value)
.Select(modState => modState.Mod)
.ToArray();

// the following guard intends to check cases where we've already replaced potentially-external mod references with our own and avoid endless recursion.
// TODO: replace custom comparer with System.Collections.Generic.ReferenceEqualityComparer when fully on .NET 6
Expand Down

0 comments on commit 83ba06e

Please sign in to comment.