diff --git a/Luna b/Luna index 78216203..8fc11b99 160000 --- a/Luna +++ b/Luna @@ -1 +1 @@ -Subproject commit 78216203f4570a6194fce9422204d8abb536c828 +Subproject commit 8fc11b993d8504982acd95b8d39e6ee7046c1347 diff --git a/Penumbra/Mods/Manager/ModStorage.cs b/Penumbra/Mods/Manager/ModStorage.cs index bec06f17..15d86866 100644 --- a/Penumbra/Mods/Manager/ModStorage.cs +++ b/Penumbra/Mods/Manager/ModStorage.cs @@ -1,94 +1,88 @@ -using OtterGui.Classes; -using OtterGui.Widgets; - -namespace Penumbra.Mods.Manager; - -public class ModCombo(Func> generator) : FilterComboCache(generator, MouseWheelType.None, Penumbra.Log) -{ - protected override bool IsVisible(int globalIndex, LowerString filter) - => Items[globalIndex].Name.Contains(filter); - - protected override string ToString(Mod obj) - => obj.Name; -} - -public class ModStorage : IReadOnlyList -{ - /// The actual list of mods. - protected readonly List Mods = []; - - public int Count - => Mods.Count; - - public Mod this[int idx] - => Mods[idx]; - - public Mod this[Index idx] - => Mods[idx]; - - public IEnumerator GetEnumerator() - => Mods.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - => GetEnumerator(); - - /// - /// Try to obtain a mod by its directory name (unique identifier). - /// - public bool TryGetMod(string identifier, [NotNullWhen(true)] out Mod? mod) - { - foreach (var m in Mods) - { - if (string.Equals(m.Identifier, identifier, StringComparison.OrdinalIgnoreCase)) - { - mod = m; - return true; - } - } - - mod = null; - return false; - } - - /// - /// Try to obtain a mod by its directory name (unique identifier, preferred), - /// or the first mod of the given name if no directory fits. - /// - public bool TryGetMod(string identifier, string modName, [NotNullWhen(true)] out Mod? mod) - { - mod = null; - foreach (var m in Mods) - { - if (string.Equals(m.Identifier, identifier, StringComparison.OrdinalIgnoreCase)) - { - mod = m; - return true; - } - - if (m.Name == modName) - mod ??= m; - } - - return mod != null; - } - - /// - /// An easily accessible set of new mods. - /// Mods are added when they are created or imported. - /// Mods are removed when they are deleted or when they are toggled in any collection. - /// Also gets cleared on mod rediscovery. - /// - private readonly HashSet _newMods = []; - - public bool IsNew(Mod mod) - => _newMods.Contains(mod); - - public void SetNew(Mod mod) - => _newMods.Add(mod); - - public void SetKnown(Mod mod) - => _newMods.Remove(mod); - - public void ClearNewMods() - => _newMods.Clear(); -} +using OtterGui.Classes; +using OtterGui.Widgets; + +namespace Penumbra.Mods.Manager; + +public class ModCombo(Func> generator) : FilterComboCache(generator, MouseWheelType.None, Penumbra.Log) +{ + protected override bool IsVisible(int globalIndex, LowerString filter) + => Items[globalIndex].Name.Contains(filter); + + protected override string ToString(Mod obj) + => obj.Name; +} + +public class ModStorage : IReadOnlyList +{ + /// The actual list of mods. + protected readonly List Mods = []; + + public int Count + => Mods.Count; + + public Mod this[int idx] + => Mods[idx]; + + public Mod this[Index idx] + => Mods[idx]; + + public IEnumerator GetEnumerator() + => Mods.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + /// + /// Try to obtain a mod by its directory name (unique identifier). + /// + public bool TryGetMod(string identifier, [NotNullWhen(true)] out Mod? mod) + { + mod = this.FirstOrDefault(m => string.Equals(m.Identifier, identifier, StringComparison.OrdinalIgnoreCase)); + return mod is not null; + } + + /// + /// Try to obtain a mod by its directory name (unique identifier, preferred), + /// or the first mod of the given name if no directory fits. + /// + public bool TryGetMod(string identifier, string modName, [NotNullWhen(true)] out Mod? mod) + { + if (modName.Length is 0) + return TryGetMod(identifier, out mod); + + mod = null; + foreach (var m in Mods) + { + if (string.Equals(m.Identifier, identifier, StringComparison.OrdinalIgnoreCase)) + { + mod = m; + return true; + } + + if (m.Name == modName) + mod ??= m; + } + + return mod != null; + } + + /// + /// An easily accessible set of new mods. + /// Mods are added when they are created or imported. + /// Mods are removed when they are deleted or when they are toggled in any collection. + /// Also gets cleared on mod rediscovery. + /// + private readonly HashSet _newMods = []; + + public bool IsNew(Mod mod) + => _newMods.Contains(mod); + + public void SetNew(Mod mod) + => _newMods.Add(mod); + + public void SetKnown(Mod mod) + => _newMods.Remove(mod); + + public void ClearNewMods() + => _newMods.Clear(); +}