Add ipc GetPlayerResourceTrees, change ipc resource node to be nested

This commit is contained in:
Asriel Camora 2023-11-28 10:46:03 -08:00
parent 73af509885
commit 0f03e0484c
No known key found for this signature in database
GPG key ID: 92B8372B278DDE41
4 changed files with 16 additions and 9 deletions

@ -1 +1 @@
Subproject commit 3f3af19d11ec4d7a83ee6c17810eb55ec4237675
Subproject commit 1fa1839aef7ddd4a90f53e9642403f950579c2eb

View file

@ -1084,6 +1084,14 @@ public class PenumbraApi : IDisposable, IPenumbraApi
return Array.ConvertAll(gameObjects, obj => resDictionary.TryGetValue(obj, out var nodes) ? nodes : null);
}
public IReadOnlyDictionary<ushort, IEnumerable<Ipc.ResourceNode>> 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)

View file

@ -131,6 +131,7 @@ public class PenumbraIpcProviders : IDisposable
GetPlayerResourcesOfType;
internal readonly FuncProvider<bool, ushort[], IEnumerable<Ipc.ResourceNode>?[]> GetGameObjectResourceTrees;
internal readonly FuncProvider<bool, IReadOnlyDictionary<ushort, IEnumerable<Ipc.ResourceNode>>> 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);

View file

@ -76,10 +76,9 @@ internal static class ResourceTreeApiHelper
public static Dictionary<ushort, IEnumerable<Ipc.ResourceNode>> 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<Ipc.ResourceNode> GetIpcNodes(ResourceTree tree)
{
var nodes = tree.FlatNodes.ToArray();
return nodes.Select(n => GetIpcNode(nodes, n)).ToArray();
}
static IEnumerable<Ipc.ResourceNode> GetIpcNodes(ResourceTree tree) =>
tree.Nodes.Select(GetIpcNode).ToArray();
var resDictionary = new Dictionary<ushort, IEnumerable<Ipc.ResourceNode>>(4);
foreach (var (gameObject, resourceTree) in resourceTrees)