From 895d9f09635f2f10b2a56bb48c8502d74c3f4434 Mon Sep 17 00:00:00 2001 From: anya-hichu Date: Wed, 25 Sep 2024 18:30:29 +0200 Subject: [PATCH] Apply mod associations from design links --- .../Gui/Tabs/DesignTab/ModAssociationsTab.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Glamourer/Gui/Tabs/DesignTab/ModAssociationsTab.cs b/Glamourer/Gui/Tabs/DesignTab/ModAssociationsTab.cs index 1f1e1ad..777f75b 100644 --- a/Glamourer/Gui/Tabs/DesignTab/ModAssociationsTab.cs +++ b/Glamourer/Gui/Tabs/DesignTab/ModAssociationsTab.cs @@ -3,6 +3,7 @@ using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.Utility; using Dalamud.Utility; using Glamourer.Designs; +using Glamourer.Designs.Links; using Glamourer.Interop.Penumbra; using ImGuiNET; using OtterGui; @@ -82,7 +83,7 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect public void ApplyAll() { - foreach (var (mod, settings) in selector.Selected!.AssociatedMods) + foreach (var (mod, settings) in GetAllAssociatedMods(selector.Selected!)) penumbra.SetMod(mod, settings); } @@ -242,4 +243,26 @@ public class ModAssociationsTab(PenumbraService penumbra, DesignFileSystemSelect _modCombo.Draw("##new", currentName.IsNullOrEmpty() ? "Select new Mod..." : currentName, string.Empty, ImGui.GetContentRegionAvail().X, ImGui.GetTextLineHeight()); } + + private static Dictionary GetAllAssociatedMods(Design design) + { + var associatedMods = new Dictionary(); + var designLinks = design.Links; + + foreach (var (mod, settings) in designLinks.Before.SelectMany(GetAllLinkAssociatedMods)) + associatedMods.TryAdd(mod, settings); + + foreach (var (mod, settings) in design.AssociatedMods) + associatedMods.TryAdd(mod, settings); + + foreach (var (mod, settings) in designLinks.After.SelectMany(GetAllLinkAssociatedMods)) + associatedMods.TryAdd(mod, settings); + + return associatedMods; + } + + private static Dictionary GetAllLinkAssociatedMods(DesignLink designLink) + { + return GetAllAssociatedMods(designLink.Link); + } }