mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-15 05:04:16 +01:00
Fix inefficient fetching of mod settings.
This commit is contained in:
parent
12fa14e1c6
commit
f6e74c06cc
2 changed files with 25 additions and 4 deletions
|
|
@ -115,7 +115,7 @@ public class ModAssociationsTab
|
|||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
var (_, newSettings) = _penumbra.GetMods().FirstOrDefault(m => m.Mod == mod);
|
||||
var newSettings = _penumbra.GetModSettings(mod);
|
||||
if (ImGui.IsItemClicked())
|
||||
updatedMod = (mod, newSettings);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,17 +110,38 @@ public unsafe class PenumbraService : IDisposable
|
|||
remove => _modSettingChanged.Event -= value;
|
||||
}
|
||||
|
||||
public ModSettings GetModSettings(in Mod mod)
|
||||
{
|
||||
if (!Available)
|
||||
return ModSettings.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var collection = _currentCollection.Invoke(ApiCollectionType.Current);
|
||||
var (ec, tuple) = _getCurrentSettings.Invoke(collection, mod.DirectoryName, string.Empty, false);
|
||||
if (ec is not PenumbraApiEc.Success)
|
||||
return ModSettings.Empty;
|
||||
|
||||
return tuple.HasValue ? new ModSettings(tuple.Value.Item3, tuple.Value.Item2, tuple.Value.Item1) : ModSettings.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Glamourer.Log.Error($"Error fetching mod settings for {mod.DirectoryName} from Penumbra:\n{ex}");
|
||||
return ModSettings.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<(Mod Mod, ModSettings Settings)> GetMods()
|
||||
{
|
||||
if (!Available)
|
||||
return Array.Empty<(Mod Mod, ModSettings Settings)>();
|
||||
return [];
|
||||
|
||||
try
|
||||
{
|
||||
var allMods = _getMods.Invoke();
|
||||
var collection = _currentCollection.Invoke(ApiCollectionType.Current);
|
||||
return allMods
|
||||
.Select(m => (m.Item1, m.Item2, _getCurrentSettings.Invoke(collection, m.Item1, m.Item2, true)))
|
||||
.Select(m => (m.Item1, m.Item2, _getCurrentSettings.Invoke(collection, m.Item1, m.Item2, false)))
|
||||
.Where(t => t.Item3.Item1 is PenumbraApiEc.Success)
|
||||
.Select(t => (new Mod(t.Item2, t.Item1),
|
||||
!t.Item3.Item2.HasValue
|
||||
|
|
@ -135,7 +156,7 @@ public unsafe class PenumbraService : IDisposable
|
|||
catch (Exception ex)
|
||||
{
|
||||
Glamourer.Log.Error($"Error fetching mods from Penumbra:\n{ex}");
|
||||
return Array.Empty<(Mod Mod, ModSettings Settings)>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue