Add GetCollectionsByIdentifier.

This commit is contained in:
Ottermandias 2024-04-13 16:05:44 +02:00
parent 6b5321dad8
commit 42ad941ec2
5 changed files with 45 additions and 4 deletions

@ -1 +1 @@
Subproject commit a8e2fe0219b8fd1f787171f11e33571317e531c1
Subproject commit 2f76f42e54141258d89300aa78d42fb3f1878092

View file

@ -48,8 +48,10 @@ public class ApiHelpers(
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal static PenumbraApiEc Return(PenumbraApiEc ec, LazyString args, [CallerMemberName] string name = "Unknown")
{
Penumbra.Log.Debug(
$"[{name}] Called with {args}, returned {ec}.");
if (ec is PenumbraApiEc.Success or PenumbraApiEc.NothingChanged)
Penumbra.Log.Verbose($"[{name}] Called with {args}, returned {ec}.");
else
Penumbra.Log.Debug($"[{name}] Called with {args}, returned {ec}.");
return ec;
}

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Collections;
@ -10,6 +11,24 @@ public class CollectionApi(CollectionManager collections, ApiHelpers helpers) :
public Dictionary<Guid, string> GetCollections()
=> collections.Storage.ToDictionary(c => c.Id, c => c.Name);
public List<(Guid Id, string Name)> GetCollectionsByIdentifier(string identifier)
{
if (identifier.Length == 0)
return [];
var list = new List<(Guid Id, string Name)>(4);
if (Guid.TryParse(identifier, out var guid) && collections.Storage.ById(guid, out var collection) && collection != ModCollection.Empty)
list.Add((collection.Id, collection.Name));
else if (identifier.Length >= 8)
list.AddRange(collections.Storage.Where(c => c.Identifier.StartsWith(identifier, StringComparison.OrdinalIgnoreCase))
.Select(c => (c.Id, c.Name)));
list.AddRange(collections.Storage
.Where(c => string.Equals(c.Name, identifier, StringComparison.OrdinalIgnoreCase) && !list.Contains((c.Id, c.Name)))
.Select(c => (c.Id, c.Name)));
return list;
}
public Dictionary<string, object?> GetChangedItemsForCollection(Guid collectionId)
{
try

View file

@ -19,6 +19,7 @@ public sealed class IpcProviders : IDisposable, IApiService
_providers =
[
IpcSubscribers.GetCollections.Provider(pi, api.Collection),
IpcSubscribers.GetCollectionsByIdentifier.Provider(pi, api.Collection),
IpcSubscribers.GetChangedItemsForCollection.Provider(pi, api.Collection),
IpcSubscribers.GetCollection.Provider(pi, api.Collection),
IpcSubscribers.GetCollectionForObject.Provider(pi, api.Collection),

View file

@ -35,7 +35,7 @@ public class CollectionsIpcTester(DalamudPluginInterface pi) : IUiService
ImGuiUtil.GenericEnumCombo("Collection Type", 200, _type, out _type, t => ((CollectionType)t).ToName());
ImGui.InputInt("Object Index##Collections", ref _objectIdx, 0, 0);
ImGuiUtil.GuidInput("Collection Id##Collections", "Collection GUID...", string.Empty, ref _collectionId, ref _collectionIdString);
ImGuiUtil.GuidInput("Collection Id##Collections", "Collection Identifier...", string.Empty, ref _collectionId, ref _collectionIdString);
ImGui.Checkbox("Allow Assignment Creation", ref _allowCreation);
ImGui.SameLine();
ImGui.Checkbox("Allow Assignment Deletion", ref _allowDeletion);
@ -48,6 +48,25 @@ public class CollectionsIpcTester(DalamudPluginInterface pi) : IUiService
if (_oldCollection != null)
ImGui.TextUnformatted(!_oldCollection.HasValue ? "Created" : _oldCollection.ToString());
IpcTester.DrawIntro(GetCollectionsByIdentifier.Label, "Collection Identifier");
var collectionList = new GetCollectionsByIdentifier(pi).Invoke(_collectionIdString);
if (collectionList.Count == 0)
{
DrawCollection(null);
}
else
{
DrawCollection(collectionList[0]);
foreach (var pair in collectionList.Skip(1))
{
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.TableNextColumn();
DrawCollection(pair);
}
}
IpcTester.DrawIntro(GetCollection.Label, "Current Collection");
DrawCollection(new GetCollection(pi).Invoke(ApiCollectionType.Current));