From 0f03e0484c33ee9c87d239c8f1fa097b43e2bdda Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Tue, 28 Nov 2023 10:46:03 -0800 Subject: [PATCH] Add ipc GetPlayerResourceTrees, change ipc resource node to be nested --- Penumbra.Api | 2 +- Penumbra/Api/PenumbraApi.cs | 8 ++++++++ Penumbra/Api/PenumbraIpcProviders.cs | 4 +++- .../Interop/ResourceTree/ResourceTreeApiHelper.cs | 11 ++++------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Penumbra.Api b/Penumbra.Api index 3f3af19d..1fa1839a 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit 3f3af19d11ec4d7a83ee6c17810eb55ec4237675 +Subproject commit 1fa1839aef7ddd4a90f53e9642403f950579c2eb diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index 7b2e09d0..1e79099c 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -1084,6 +1084,14 @@ public class PenumbraApi : IDisposable, IPenumbraApi return Array.ConvertAll(gameObjects, obj => resDictionary.TryGetValue(obj, out var nodes) ? nodes : null); } + public IReadOnlyDictionary> GetPlayerResourceTrees(bool withUIData) + { + var resourceTrees = _resourceTreeFactory.FromObjectTable(ResourceTreeFactory.Flags.LocalPlayerRelatedOnly + | (withUIData ? ResourceTreeFactory.Flags.WithUiData : 0)); + var resDictionary = ResourceTreeApiHelper.EncapsulateResourceTrees(resourceTrees); + + return resDictionary.AsReadOnly(); + } // TODO: cleanup when incrementing API public string GetMetaManipulations(string characterName) diff --git a/Penumbra/Api/PenumbraIpcProviders.cs b/Penumbra/Api/PenumbraIpcProviders.cs index 289fc38b..9f1e79b9 100644 --- a/Penumbra/Api/PenumbraIpcProviders.cs +++ b/Penumbra/Api/PenumbraIpcProviders.cs @@ -131,6 +131,7 @@ public class PenumbraIpcProviders : IDisposable GetPlayerResourcesOfType; internal readonly FuncProvider?[]> GetGameObjectResourceTrees; + internal readonly FuncProvider>> GetPlayerResourceTrees; public PenumbraIpcProviders(DalamudServices dalamud, IPenumbraApi api, ModManager modManager, CollectionManager collections, TempModManager tempMods, TempCollectionManager tempCollections, SaveService saveService, Configuration config) @@ -256,7 +257,8 @@ public class PenumbraIpcProviders : IDisposable GetPlayerResourcePaths = Ipc.GetPlayerResourcePaths.Provider(pi, Api.GetPlayerResourcePaths); GetGameObjectResourcesOfType = Ipc.GetGameObjectResourcesOfType.Provider(pi, Api.GetGameObjectResourcesOfType); GetPlayerResourcesOfType = Ipc.GetPlayerResourcesOfType.Provider(pi, Api.GetPlayerResourcesOfType); - GetGameObjectResourceTrees = Ipc.GetGameObjectResourceTrees.Provider(pi, Api.GetGameObjectResourceTrees); + GetGameObjectResourceTrees = Ipc.GetGameObjectResourceTrees.Provider(pi, Api.GetGameObjectResourceTrees); + GetPlayerResourceTrees = Ipc.GetPlayerResourceTrees.Provider(pi, Api.GetPlayerResourceTrees); Tester = new IpcTester(config, dalamud, this, modManager, collections, tempMods, tempCollections, saveService); diff --git a/Penumbra/Interop/ResourceTree/ResourceTreeApiHelper.cs b/Penumbra/Interop/ResourceTree/ResourceTreeApiHelper.cs index 3df47086..02e0f380 100644 --- a/Penumbra/Interop/ResourceTree/ResourceTreeApiHelper.cs +++ b/Penumbra/Interop/ResourceTree/ResourceTreeApiHelper.cs @@ -76,10 +76,9 @@ internal static class ResourceTreeApiHelper public static Dictionary> EncapsulateResourceTrees(IEnumerable<(Character, ResourceTree)> resourceTrees) { - static Ipc.ResourceNode GetIpcNode(ResourceNode[] tree, ResourceNode node) => + static Ipc.ResourceNode GetIpcNode(ResourceNode node) => new() { - ChildrenIndices = node.Children.Select(c => Array.IndexOf(tree, c)).ToArray(), Type = node.Type, Icon = ChangedItemDrawer.ToApiIcon(node.Icon), Name = node.Name, @@ -87,13 +86,11 @@ internal static class ResourceTreeApiHelper ActualPath = node.FullPath.ToString(), ObjectAddress = node.ObjectAddress, ResourceHandle = node.ResourceHandle, + Children = node.Children.Select(GetIpcNode).ToArray(), }; - static IEnumerable GetIpcNodes(ResourceTree tree) - { - var nodes = tree.FlatNodes.ToArray(); - return nodes.Select(n => GetIpcNode(nodes, n)).ToArray(); - } + static IEnumerable GetIpcNodes(ResourceTree tree) => + tree.Nodes.Select(GetIpcNode).ToArray(); var resDictionary = new Dictionary>(4); foreach (var (gameObject, resourceTree) in resourceTrees)