From 52006e96f16589c4d9fe4e0dbd39afe8a73b2a20 Mon Sep 17 00:00:00 2001 From: fgsfds <4870330+fgsfds@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:06:21 +0500 Subject: [PATCH] auto enable/disable dependencies --- src/Avalonia/Core/ViewModels/ModsViewModel.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Avalonia/Core/ViewModels/ModsViewModel.cs b/src/Avalonia/Core/ViewModels/ModsViewModel.cs index 2fa60cdd..307ce89a 100644 --- a/src/Avalonia/Core/ViewModels/ModsViewModel.cs +++ b/src/Avalonia/Core/ViewModels/ModsViewModel.cs @@ -10,6 +10,7 @@ using Mods.Providers; using System.Collections.Immutable; using System.Diagnostics; +using System.Linq; namespace BuildLauncher.ViewModels { @@ -146,12 +147,29 @@ private void ModCheckboxPressed(object? obj) if (!mod.IsEnabled) { + var deps = ModsList.Where(x => x.DependentAddons?.ContainsKey(mod.Id) ?? false); + _installedAddonsProvider.DisableAddon(new(mod.Id, mod.Version)); + + foreach (var depMod in deps) + { + _installedAddonsProvider.DisableAddon(new(depMod.Id, depMod.Version)); + } } else if (mod.IsEnabled) { + var dependencies = mod.DependentAddons; + var depMods = dependencies is null ? [] : ModsList.Where(x => dependencies.ContainsKey(x.Id)); + _installedAddonsProvider.EnableAddon(new(mod.Id, mod.Version)); + + foreach (var depMod in depMods) + { + _installedAddonsProvider.EnableAddon(new(depMod.Id, depMod.Version)); + } } + + OnPropertyChanged(nameof(ModsList)); } #endregion