mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-01-03 06:13:45 +01:00
Add toggle for always applying mod associations.
This commit is contained in:
parent
818bf71032
commit
d10043a69a
6 changed files with 84 additions and 21 deletions
67
Glamourer/Interop/Penumbra/ModSettingApplier.cs
Normal file
67
Glamourer/Interop/Penumbra/ModSettingApplier.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using Glamourer.Designs.Links;
|
||||
using Glamourer.Interop.Structs;
|
||||
using Glamourer.State;
|
||||
using OtterGui.Services;
|
||||
|
||||
namespace Glamourer.Interop.Penumbra;
|
||||
|
||||
public class ModSettingApplier(PenumbraService penumbra, Configuration config, ObjectManager objects) : IService
|
||||
{
|
||||
public void HandleStateApplication(ActorState state, MergedDesign design)
|
||||
{
|
||||
if (!config.AlwaysApplyAssociatedMods || design.AssociatedMods.Count == 0)
|
||||
return;
|
||||
|
||||
objects.Update();
|
||||
if (!objects.TryGetValue(state.Identifier, out var data))
|
||||
{
|
||||
Glamourer.Log.Verbose(
|
||||
$"[Mod Applier] No mod settings applied because no actor for {state.Identifier} could be found to associate collection.");
|
||||
return;
|
||||
}
|
||||
|
||||
var collections = new HashSet<string>();
|
||||
|
||||
foreach (var actor in data.Objects)
|
||||
{
|
||||
var collection = penumbra.GetActorCollection(actor);
|
||||
if (collection.Length == 0)
|
||||
{
|
||||
Glamourer.Log.Verbose($"[Mod Applier] Could not obtain associated collection for {actor.Utf8Name}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!collections.Add(collection))
|
||||
continue;
|
||||
|
||||
foreach (var (mod, setting) in design.AssociatedMods)
|
||||
{
|
||||
var message = penumbra.SetMod(mod, setting, collection);
|
||||
if (message.Length > 0)
|
||||
Glamourer.Log.Verbose($"[Mod Applier] Error applying mod settings: {message}");
|
||||
else
|
||||
Glamourer.Log.Verbose($"[Mod Applier] Set mod settings for {mod.DirectoryName} in {collection}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public (List<string> Messages, int Applied, string Collection) ApplyModSettings(IReadOnlyDictionary<Mod, ModSettings> settings, Actor actor)
|
||||
{
|
||||
var collection = penumbra.GetActorCollection(actor);
|
||||
if (collection.Length <= 0)
|
||||
return ([$"Could not obtain associated collection for {actor.Utf8Name}."], 0, string.Empty);
|
||||
|
||||
var messages = new List<string>();
|
||||
var appliedMods = 0;
|
||||
foreach (var (mod, setting) in settings)
|
||||
{
|
||||
var message = penumbra.SetMod(mod, setting, collection);
|
||||
if (message.Length > 0)
|
||||
messages.Add($"Error applying mod settings: {message}");
|
||||
else
|
||||
++appliedMods;
|
||||
}
|
||||
|
||||
return (messages, appliedMods, collection);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue