Add API/IPC for collection handling.

This commit is contained in:
Ottermandias 2023-01-16 17:42:26 +01:00
parent 123ed256b1
commit 80f02e5377
6 changed files with 284 additions and 87 deletions

View file

@ -9,8 +9,10 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using Dalamud.Utility;
using Penumbra.Api.Enums;
using Penumbra.Api.Helpers;
using Penumbra.Collections;
using Penumbra.String;
using Penumbra.String.Classes;
using Penumbra.Meta.Manipulations;
@ -683,10 +685,18 @@ public class IpcTester : IDisposable
{
private readonly DalamudPluginInterface _pi;
private int _objectIdx = 0;
private string _collectionName = string.Empty;
private bool _allowCreation = true;
private bool _allowDeletion = true;
private ApiCollectionType _type = ApiCollectionType.Current;
private string _characterCollectionName = string.Empty;
private IList< string > _collections = new List< string >();
private string _changedItemCollection = string.Empty;
private IReadOnlyDictionary< string, object? > _changedItems = new Dictionary< string, object? >();
private PenumbraApiEc _returnCode = PenumbraApiEc.Success;
private string? _oldCollection = null;
public Collections( DalamudPluginInterface pi )
=> _pi = pi;
@ -699,12 +709,25 @@ public class IpcTester : IDisposable
return;
}
ImGuiUtil.GenericEnumCombo( "Collection Type", 200, _type, out _type, t => ((CollectionType)t).ToName() );
ImGui.InputInt( "Object Index##Collections", ref _objectIdx, 0, 0 );
ImGui.InputText( "Collection Name##Collections", ref _collectionName, 64 );
ImGui.Checkbox( "Allow Assignment Creation", ref _allowCreation );
ImGui.SameLine();
ImGui.Checkbox( "Allow Assignment Deletion", ref _allowDeletion );
using var table = ImRaii.Table( string.Empty, 3, ImGuiTableFlags.SizingFixedFit );
if( !table )
{
return;
}
DrawIntro( "Last Return Code", _returnCode.ToString() );
if( _oldCollection != null )
{
ImGui.TextUnformatted( _oldCollection.Length == 0 ? "Created" : _oldCollection );
}
DrawIntro( Ipc.GetCurrentCollectionName.Label, "Current Collection" );
ImGui.TextUnformatted( Ipc.GetCurrentCollectionName.Subscriber( _pi ).Invoke() );
DrawIntro( Ipc.GetDefaultCollectionName.Label, "Default Collection" );
@ -725,6 +748,27 @@ public class IpcTester : IDisposable
ImGui.OpenPopup( "Collections" );
}
DrawIntro( Ipc.GetCollectionForType.Label, "Get Special Collection" );
var name = Ipc.GetCollectionForType.Subscriber( _pi ).Invoke( _type );
ImGui.TextUnformatted( name.Length == 0 ? "Unassigned" : name );
DrawIntro( Ipc.SetCollectionForType.Label, "Set Special Collection" );
if( ImGui.Button( "Set##TypeCollection" ) )
{
( _returnCode, _oldCollection ) = Ipc.SetCollectionForType.Subscriber( _pi ).Invoke( _type, _collectionName, _allowCreation, _allowDeletion );
}
DrawIntro( Ipc.GetCollectionForObject.Label, "Get Object Collection" );
( var valid, var individual, name ) = Ipc.GetCollectionForObject.Subscriber( _pi ).Invoke( _objectIdx );
ImGui.TextUnformatted(
$"{( valid ? "Valid" : "Invalid" )} Object, {( name.Length == 0 ? "Unassigned" : name )}{( individual ? " (Individual Assignment)" : string.Empty )}" );
DrawIntro( Ipc.SetCollectionForObject.Label, "Set Object Collection" );
if( ImGui.Button( "Set##ObjectCollection" ) )
{
( _returnCode, _oldCollection ) = Ipc.SetCollectionForObject.Subscriber( _pi ).Invoke( _objectIdx, _collectionName, _allowCreation, _allowDeletion );
}
if( _returnCode == PenumbraApiEc.NothingChanged && _oldCollection.IsNullOrEmpty() )
_oldCollection = null;
DrawIntro( Ipc.GetChangedItems.Label, "Changed Item List" );
ImGui.SetNextItemWidth( 200 * ImGuiHelpers.GlobalScale );
ImGui.InputTextWithHint( "##changedCollection", "Collection Name...", ref _changedItemCollection, 64 );
@ -1089,6 +1133,7 @@ public class IpcTester : IDisposable
{
_lastSettingsError = Ipc.CopyModSettings.Subscriber( _pi ).Invoke( _settingsCollection, _settingsModDirectory, _settingsModName );
}
ImGuiUtil.HoverTooltip( "Copy settings from Mod Directory Name to Mod Name (as directory) in collection." );
DrawIntro( Ipc.TrySetModSetting.Label, "Set Setting(s)" );