mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Remove deleted designs from automated design sets.
This commit is contained in:
parent
db6687d896
commit
869618e6d3
2 changed files with 35 additions and 2 deletions
|
|
@ -13,12 +13,13 @@ using Glamourer.Services;
|
|||
using Glamourer.Structs;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OtterGui;
|
||||
using OtterGui.Filesystem;
|
||||
using Penumbra.GameData.Actors;
|
||||
|
||||
namespace Glamourer.Automation;
|
||||
|
||||
public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
||||
public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDisposable
|
||||
{
|
||||
public const int CurrentVersion = 1;
|
||||
|
||||
|
|
@ -28,6 +29,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
private readonly DesignManager _designs;
|
||||
private readonly ActorService _actors;
|
||||
private readonly AutomationChanged _event;
|
||||
private readonly DesignChanged _designEvent;
|
||||
|
||||
private readonly List<AutoDesignSet> _data = new();
|
||||
private readonly Dictionary<ActorIdentifier, AutoDesignSet> _enabled = new();
|
||||
|
|
@ -36,17 +38,22 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
=> _enabled;
|
||||
|
||||
public AutoDesignManager(JobService jobs, ActorService actors, SaveService saveService, DesignManager designs, AutomationChanged @event,
|
||||
FixedDesignMigrator migrator, DesignFileSystem fileSystem)
|
||||
FixedDesignMigrator migrator, DesignFileSystem fileSystem, DesignChanged designEvent)
|
||||
{
|
||||
_jobs = jobs;
|
||||
_actors = actors;
|
||||
_saveService = saveService;
|
||||
_designs = designs;
|
||||
_event = @event;
|
||||
_designEvent = designEvent;
|
||||
_designEvent.Subscribe(OnDesignChange, DesignChanged.Priority.AutoDesignManager);
|
||||
Load();
|
||||
migrator.ConsumeMigratedData(_actors, fileSystem, this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
=> _designEvent.Unsubscribe(OnDesignChange);
|
||||
|
||||
public IEnumerator<AutoDesignSet> GetEnumerator()
|
||||
=> _data.GetEnumerator();
|
||||
|
||||
|
|
@ -538,4 +545,27 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
|||
_ => Array.Empty<ActorIdentifier>(),
|
||||
};
|
||||
}
|
||||
|
||||
private void OnDesignChange(DesignChanged.Type type, Design design, object? data)
|
||||
{
|
||||
if (type is not DesignChanged.Type.Deleted)
|
||||
return;
|
||||
|
||||
foreach (var (set, idx) in this.WithIndex())
|
||||
{
|
||||
var deleted = 0;
|
||||
for (var i = 0; i < set.Designs.Count; ++i)
|
||||
{
|
||||
if (set.Designs[i].Design != design)
|
||||
continue;
|
||||
|
||||
DeleteDesign(set, i--);
|
||||
++deleted;
|
||||
}
|
||||
|
||||
if (deleted > 0)
|
||||
Glamourer.Log.Information(
|
||||
$"Removed {deleted} automated designs from automated design set {idx} due to deletion of {design.Incognito}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ public sealed class DesignChanged : EventWrapper<Action<DesignChanged.Type, Desi
|
|||
|
||||
/// <seealso cref="Gui.Tabs.DesignTab.DesignFileSystemSelector.OnDesignChange"/>
|
||||
DesignFileSystemSelector = -1,
|
||||
|
||||
/// <seealso cref="Automation.AutoDesignManager.OnDesignChange"/>
|
||||
AutoDesignManager = 1,
|
||||
}
|
||||
|
||||
public DesignChanged()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue