diff --git a/Penumbra.Api b/Penumbra.Api index 7ae46f0d..70f04683 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit 7ae46f0d09f40b36a5b2d10382db46fbfb729117 +Subproject commit 70f046830cc7cd35b3480b12b7efe94182477fbb diff --git a/Penumbra/Api/Api/CollectionApi.cs b/Penumbra/Api/Api/CollectionApi.cs index 964da1a5..c40feb12 100644 --- a/Penumbra/Api/Api/CollectionApi.cs +++ b/Penumbra/Api/Api/CollectionApi.cs @@ -2,6 +2,7 @@ using OtterGui.Services; using Penumbra.Api.Enums; using Penumbra.Collections; using Penumbra.Collections.Manager; +using Penumbra.Mods; namespace Penumbra.Api.Api; @@ -23,11 +24,27 @@ public class CollectionApi(CollectionManager collections, ApiHelpers helpers) : .Select(c => (c.Identity.Id, c.Identity.Name))); list.AddRange(collections.Storage - .Where(c => string.Equals(c.Identity.Name, identifier, StringComparison.OrdinalIgnoreCase) && !list.Contains((c.Identity.Id, c.Identity.Name))) + .Where(c => string.Equals(c.Identity.Name, identifier, StringComparison.OrdinalIgnoreCase) + && !list.Contains((c.Identity.Id, c.Identity.Name))) .Select(c => (c.Identity.Id, c.Identity.Name))); return list; } + public Func CheckCurrentChangedItemFunc() + { + var weakRef = new WeakReference(collections); + return s => + { + if (!weakRef.TryGetTarget(out var c)) + throw new ObjectDisposedException("The underlying collection storage of this IPC container was disposed."); + + if (!c.Active.Current.ChangedItems.TryGetValue(s, out var d)) + return []; + + return d.Item1.Select(m => (m is Mod mod ? mod.Identifier : string.Empty, m.Name.Text)).ToArray(); + }; + } + public Dictionary GetChangedItemsForCollection(Guid collectionId) { try @@ -74,7 +91,8 @@ public class CollectionApi(CollectionManager collections, ApiHelpers helpers) : } public Guid[] GetCollectionByName(string name) - => collections.Storage.Where(c => string.Equals(name, c.Identity.Name, StringComparison.OrdinalIgnoreCase)).Select(c => c.Identity.Id).ToArray(); + => collections.Storage.Where(c => string.Equals(name, c.Identity.Name, StringComparison.OrdinalIgnoreCase)).Select(c => c.Identity.Id) + .ToArray(); public (PenumbraApiEc, (Guid Id, string Name)? OldCollection) SetCollection(ApiCollectionType type, Guid? collectionId, bool allowCreateNew, bool allowDelete) diff --git a/Penumbra/Api/IpcProviders.cs b/Penumbra/Api/IpcProviders.cs index 085e57ca..d54faa6c 100644 --- a/Penumbra/Api/IpcProviders.cs +++ b/Penumbra/Api/IpcProviders.cs @@ -29,6 +29,7 @@ public sealed class IpcProviders : IDisposable, IApiService IpcSubscribers.GetCollectionForObject.Provider(pi, api.Collection), IpcSubscribers.SetCollection.Provider(pi, api.Collection), IpcSubscribers.SetCollectionForObject.Provider(pi, api.Collection), + IpcSubscribers.CheckCurrentChangedItemFunc.Provider(pi, api.Collection), IpcSubscribers.ConvertTextureFile.Provider(pi, api.Editing), IpcSubscribers.ConvertTextureData.Provider(pi, api.Editing), diff --git a/Penumbra/Mods/Manager/ModChangedItemAdapter.cs b/Penumbra/Api/ModChangedItemAdapter.cs similarity index 95% rename from Penumbra/Mods/Manager/ModChangedItemAdapter.cs rename to Penumbra/Api/ModChangedItemAdapter.cs index 8b99cdf2..8842f20a 100644 --- a/Penumbra/Mods/Manager/ModChangedItemAdapter.cs +++ b/Penumbra/Api/ModChangedItemAdapter.cs @@ -1,6 +1,7 @@ using Penumbra.GameData.Data; +using Penumbra.Mods.Manager; -namespace Penumbra.Mods.Manager; +namespace Penumbra.Api; public sealed class ModChangedItemAdapter(WeakReference storage) : IReadOnlyDictionary>,