mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-15 21:24:18 +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 Glamourer.Structs;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using OtterGui;
|
||||||
using OtterGui.Filesystem;
|
using OtterGui.Filesystem;
|
||||||
using Penumbra.GameData.Actors;
|
using Penumbra.GameData.Actors;
|
||||||
|
|
||||||
namespace Glamourer.Automation;
|
namespace Glamourer.Automation;
|
||||||
|
|
||||||
public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDisposable
|
||||||
{
|
{
|
||||||
public const int CurrentVersion = 1;
|
public const int CurrentVersion = 1;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
||||||
private readonly DesignManager _designs;
|
private readonly DesignManager _designs;
|
||||||
private readonly ActorService _actors;
|
private readonly ActorService _actors;
|
||||||
private readonly AutomationChanged _event;
|
private readonly AutomationChanged _event;
|
||||||
|
private readonly DesignChanged _designEvent;
|
||||||
|
|
||||||
private readonly List<AutoDesignSet> _data = new();
|
private readonly List<AutoDesignSet> _data = new();
|
||||||
private readonly Dictionary<ActorIdentifier, AutoDesignSet> _enabled = new();
|
private readonly Dictionary<ActorIdentifier, AutoDesignSet> _enabled = new();
|
||||||
|
|
@ -36,17 +38,22 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
||||||
=> _enabled;
|
=> _enabled;
|
||||||
|
|
||||||
public AutoDesignManager(JobService jobs, ActorService actors, SaveService saveService, DesignManager designs, AutomationChanged @event,
|
public AutoDesignManager(JobService jobs, ActorService actors, SaveService saveService, DesignManager designs, AutomationChanged @event,
|
||||||
FixedDesignMigrator migrator, DesignFileSystem fileSystem)
|
FixedDesignMigrator migrator, DesignFileSystem fileSystem, DesignChanged designEvent)
|
||||||
{
|
{
|
||||||
_jobs = jobs;
|
_jobs = jobs;
|
||||||
_actors = actors;
|
_actors = actors;
|
||||||
_saveService = saveService;
|
_saveService = saveService;
|
||||||
_designs = designs;
|
_designs = designs;
|
||||||
_event = @event;
|
_event = @event;
|
||||||
|
_designEvent = designEvent;
|
||||||
|
_designEvent.Subscribe(OnDesignChange, DesignChanged.Priority.AutoDesignManager);
|
||||||
Load();
|
Load();
|
||||||
migrator.ConsumeMigratedData(_actors, fileSystem, this);
|
migrator.ConsumeMigratedData(_actors, fileSystem, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
=> _designEvent.Unsubscribe(OnDesignChange);
|
||||||
|
|
||||||
public IEnumerator<AutoDesignSet> GetEnumerator()
|
public IEnumerator<AutoDesignSet> GetEnumerator()
|
||||||
=> _data.GetEnumerator();
|
=> _data.GetEnumerator();
|
||||||
|
|
||||||
|
|
@ -538,4 +545,27 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
|
||||||
_ => Array.Empty<ActorIdentifier>(),
|
_ => 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"/>
|
/// <seealso cref="Gui.Tabs.DesignTab.DesignFileSystemSelector.OnDesignChange"/>
|
||||||
DesignFileSystemSelector = -1,
|
DesignFileSystemSelector = -1,
|
||||||
|
|
||||||
|
/// <seealso cref="Automation.AutoDesignManager.OnDesignChange"/>
|
||||||
|
AutoDesignManager = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
public DesignChanged()
|
public DesignChanged()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue