Fix inefficient fetching of mod settings.

This commit is contained in:
Ottermandias 2024-04-05 13:27:40 +02:00
parent 12fa14e1c6
commit f6e74c06cc
2 changed files with 25 additions and 4 deletions

View file

@ -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);

View file

@ -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 [];
}
}