ResourceTree IPC: Remove mergeSameCollection.

This commit is contained in:
Exter-N 2023-09-18 02:01:22 +02:00 committed by Ottermandias
parent d7205344eb
commit 22966e648d
4 changed files with 12 additions and 44 deletions

View file

@ -1408,10 +1408,9 @@ public class IpcTester : IDisposable
private readonly DalamudPluginInterface _pi; private readonly DalamudPluginInterface _pi;
private readonly IObjectTable _objects; private readonly IObjectTable _objects;
private string _gameObjectIndices = "0"; private string _gameObjectIndices = "0";
private bool _mergeSameCollection = false; private ResourceType _type = ResourceType.Mtrl;
private ResourceType _type = ResourceType.Mtrl; private bool _withUIData = false;
private bool _withUIData = false;
private (string, IReadOnlyDictionary<string, string[]>?)[]? _lastGameObjectResourcePaths; private (string, IReadOnlyDictionary<string, string[]>?)[]? _lastGameObjectResourcePaths;
private (string, IReadOnlyDictionary<string, string[]>?)[]? _lastPlayerResourcePaths; private (string, IReadOnlyDictionary<string, string[]>?)[]? _lastPlayerResourcePaths;
@ -1431,7 +1430,6 @@ public class IpcTester : IDisposable
return; return;
ImGui.InputText("GameObject indices", ref _gameObjectIndices, 511); ImGui.InputText("GameObject indices", ref _gameObjectIndices, 511);
ImGui.Checkbox("Merge entries that use the same collection", ref _mergeSameCollection);
ImGuiUtil.GenericEnumCombo("Resource type", ImGui.CalcItemWidth(), _type, out _type, Enum.GetValues<ResourceType>()); ImGuiUtil.GenericEnumCombo("Resource type", ImGui.CalcItemWidth(), _type, out _type, Enum.GetValues<ResourceType>());
ImGui.Checkbox("Also get names and icons", ref _withUIData); ImGui.Checkbox("Also get names and icons", ref _withUIData);
@ -1443,7 +1441,7 @@ public class IpcTester : IDisposable
if (ImGui.Button("Get##GameObjectResourcePaths")) if (ImGui.Button("Get##GameObjectResourcePaths"))
{ {
var gameObjects = GetSelectedGameObjects(); var gameObjects = GetSelectedGameObjects();
var resourcePaths = Ipc.GetGameObjectResourcePaths.Subscriber(_pi).Invoke(gameObjects, _mergeSameCollection); var resourcePaths = Ipc.GetGameObjectResourcePaths.Subscriber(_pi).Invoke(gameObjects);
_lastGameObjectResourcePaths = gameObjects _lastGameObjectResourcePaths = gameObjects
.Select(GameObjectToString) .Select(GameObjectToString)
@ -1456,7 +1454,7 @@ public class IpcTester : IDisposable
DrawIntro(Ipc.GetPlayerResourcePaths.Label, "Get local player resource paths"); DrawIntro(Ipc.GetPlayerResourcePaths.Label, "Get local player resource paths");
if (ImGui.Button("Get##PlayerResourcePaths")) if (ImGui.Button("Get##PlayerResourcePaths"))
{ {
_lastPlayerResourcePaths = Ipc.GetPlayerResourcePaths.Subscriber(_pi).Invoke(_mergeSameCollection) _lastPlayerResourcePaths = Ipc.GetPlayerResourcePaths.Subscriber(_pi).Invoke()
.Select(pair => (GameObjectToString(pair.Key), (IReadOnlyDictionary<string, string[]>?)pair.Value)) .Select(pair => (GameObjectToString(pair.Key), (IReadOnlyDictionary<string, string[]>?)pair.Value))
.ToArray(); .ToArray();

View file

@ -1016,19 +1016,19 @@ public class PenumbraApi : IDisposable, IPenumbraApi
}; };
// @formatter:on // @formatter:on
public IReadOnlyDictionary<string, string[]>?[] GetGameObjectResourcePaths(ushort[] gameObjects, bool mergeSameCollection) public IReadOnlyDictionary<string, string[]>?[] GetGameObjectResourcePaths(ushort[] gameObjects)
{ {
var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType<Character>(); var characters = gameObjects.Select(index => _dalamud.Objects[index]).OfType<Character>();
var resourceTrees = _resourceTreeFactory.FromCharacters(characters, false, false); var resourceTrees = _resourceTreeFactory.FromCharacters(characters, false, false);
var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees, mergeSameCollection); var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees);
return Array.ConvertAll(gameObjects, obj => pathDictionaries.TryGetValue(obj, out var pathDict) ? pathDict : null); return Array.ConvertAll(gameObjects, obj => pathDictionaries.TryGetValue(obj, out var pathDict) ? pathDict : null);
} }
public IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>> GetPlayerResourcePaths(bool mergeSameCollection) public IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>> GetPlayerResourcePaths()
{ {
var resourceTrees = _resourceTreeFactory.FromObjectTable(true, false, false); var resourceTrees = _resourceTreeFactory.FromObjectTable(true, false, false);
var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees, mergeSameCollection); var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees);
return pathDictionaries.AsReadOnly(); return pathDictionaries.AsReadOnly();
} }

View file

@ -119,8 +119,8 @@ public class PenumbraIpcProviders : IDisposable
internal readonly FuncProvider<string, string, int, PenumbraApiEc> RemoveTemporaryMod; internal readonly FuncProvider<string, string, int, PenumbraApiEc> RemoveTemporaryMod;
// Resource Tree // Resource Tree
internal readonly FuncProvider<ushort[], bool, IReadOnlyDictionary<string, string[]>?[]> GetGameObjectResourcePaths; internal readonly FuncProvider<ushort[], IReadOnlyDictionary<string, string[]>?[]> GetGameObjectResourcePaths;
internal readonly FuncProvider<bool, IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>> GetPlayerResourcePaths; internal readonly FuncProvider<IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>> GetPlayerResourcePaths;
internal readonly FuncProvider<ushort[], ResourceType, bool, IReadOnlyDictionary<nint, (string, string, ChangedItemIcon)>?[]> GetGameObjectResourcesOfType; internal readonly FuncProvider<ushort[], ResourceType, bool, IReadOnlyDictionary<nint, (string, string, ChangedItemIcon)>?[]> GetGameObjectResourcesOfType;
internal readonly FuncProvider<ResourceType, bool, IReadOnlyDictionary<ushort, IReadOnlyDictionary<nint, (string, string, ChangedItemIcon)>>> GetPlayerResourcesOfType; internal readonly FuncProvider<ResourceType, bool, IReadOnlyDictionary<ushort, IReadOnlyDictionary<nint, (string, string, ChangedItemIcon)>>> GetPlayerResourcesOfType;

View file

@ -6,37 +6,7 @@ namespace Penumbra.Interop.ResourceTree;
internal static class ResourceTreeApiHelper internal static class ResourceTreeApiHelper
{ {
public static Dictionary<ushort, IReadOnlyDictionary<string, string[]>> GetResourcePathDictionaries(IEnumerable<(Character, ResourceTree)> resourceTrees, public static Dictionary<ushort, IReadOnlyDictionary<string, string[]>> GetResourcePathDictionaries(IEnumerable<(Character, ResourceTree)> resourceTrees)
bool mergeSameCollection)
=> mergeSameCollection ? GetResourcePathDictionariesMerged(resourceTrees) : GetResourcePathDictionariesUnmerged(resourceTrees);
private static Dictionary<ushort, IReadOnlyDictionary<string, string[]>> GetResourcePathDictionariesMerged(IEnumerable<(Character, ResourceTree)> resourceTrees)
{
var collections = new Dictionary<ushort, string>(4);
var pathDictionaries = new Dictionary<string, Dictionary<string, HashSet<string>>>(4);
foreach (var (gameObject, resourceTree) in resourceTrees)
{
if (collections.ContainsKey(gameObject.ObjectIndex))
continue;
collections.Add(gameObject.ObjectIndex, resourceTree.CollectionName);
if (!pathDictionaries.TryGetValue(resourceTree.CollectionName, out var pathDictionary))
{
pathDictionary = new();
pathDictionaries.Add(resourceTree.CollectionName, pathDictionary);
}
CollectResourcePaths(pathDictionary, resourceTree);
}
var pathRODictionaries = pathDictionaries.ToDictionary(pair => pair.Key,
pair => (IReadOnlyDictionary<string, string[]>)pair.Value.ToDictionary(pair => pair.Key, pair => pair.Value.ToArray()).AsReadOnly());
return collections.ToDictionary(pair => pair.Key, pair => pathRODictionaries[pair.Value]);
}
private static Dictionary<ushort, IReadOnlyDictionary<string, string[]>> GetResourcePathDictionariesUnmerged(IEnumerable<(Character, ResourceTree)> resourceTrees)
{ {
var pathDictionaries = new Dictionary<ushort, Dictionary<string, HashSet<string>>>(4); var pathDictionaries = new Dictionary<ushort, Dictionary<string, HashSet<string>>>(4);