1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 16:37:26 +08:00

Compute required mods list once per update

This commit is contained in:
Salman Ahmed 2024-02-23 16:51:52 +03:00
parent f94cd4483c
commit 918577d530

View File

@ -35,28 +35,28 @@ namespace osu.Game.Screens.OnlinePlay.Match
BeatmapInfo = { Value = Beatmap?.BeatmapInfo } BeatmapInfo = { Value = Beatmap?.BeatmapInfo }
}; };
private readonly List<Mod> roomMods = new List<Mod>();
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
selectedItem?.BindValueChanged(_ => SelectedMods.TriggerChange());
}
protected override IEnumerable<Mod> AllSelectedMods selectedItem?.BindValueChanged(_ =>
{
get
{ {
IEnumerable<Mod> allMods = SelectedMods.Value; roomMods.Clear();
if (selectedItem?.Value != null) if (selectedItem?.Value != null)
{ {
var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance(); var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance();
Debug.Assert(rulesetInstance != null); Debug.Assert(rulesetInstance != null);
allMods = allMods.Concat(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance))); roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
} }
return allMods; SelectedMods.TriggerChange();
} });
} }
protected override IEnumerable<Mod> AllSelectedMods => roomMods.Concat(base.AllSelectedMods);
} }
public partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay public partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay
@ -67,27 +67,27 @@ namespace osu.Game.Screens.OnlinePlay.Match
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } = null!; private RulesetStore rulesets { get; set; } = null!;
private readonly List<Mod> roomMods = new List<Mod>();
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
selectedItem?.BindValueChanged(_ => Mods.TriggerChange());
}
protected override IEnumerable<Mod> SelectedMods selectedItem?.BindValueChanged(_ =>
{
get
{ {
IEnumerable<Mod> selectedMods = Mods.Value; roomMods.Clear();
if (selectedItem?.Value != null) if (selectedItem?.Value != null)
{ {
var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance(); var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance();
Debug.Assert(rulesetInstance != null); Debug.Assert(rulesetInstance != null);
selectedMods = selectedMods.Concat(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance))); roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
} }
return selectedMods; Mods.TriggerChange();
} });
} }
protected override IEnumerable<Mod> SelectedMods => roomMods.Concat(base.SelectedMods);
} }
} }