mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-03 06:13:45 +01:00
Some cleanup, slight changes.
This commit is contained in:
parent
bcd62cbe69
commit
3c5cff1418
6 changed files with 74 additions and 62 deletions
|
|
@ -20,6 +20,7 @@ public interface IPenumbraApiBase
|
|||
|
||||
public delegate void ChangedItemHover( object? item );
|
||||
public delegate void ChangedItemClick( MouseButton button, object? item );
|
||||
public delegate void GameObjectRedrawn( IntPtr objectPtr, int objectTableIndex );
|
||||
|
||||
public enum PenumbraApiEc
|
||||
{
|
||||
|
|
@ -51,7 +52,7 @@ public interface IPenumbraApi : IPenumbraApiBase
|
|||
|
||||
// Triggered when the user clicks a listed changed object in a mod tab.
|
||||
public event ChangedItemClick? ChangedItemClicked;
|
||||
event EventHandler? ObjectIsRedrawn;
|
||||
public event GameObjectRedrawn? GameObjectRedrawn;
|
||||
|
||||
// Queue redrawing of all actors of the given name with the given RedrawType.
|
||||
public void RedrawObject( string name, RedrawType setting );
|
||||
|
|
@ -74,7 +75,7 @@ public interface IPenumbraApi : IPenumbraApiBase
|
|||
public string ResolvePath( string gamePath, string characterName );
|
||||
|
||||
// Reverse resolves a given modded local path into its replacement in form of all applicable game path for given character
|
||||
public string[] ReverseResolvePath( string moddedPath, string characterName );
|
||||
public IList<string> ReverseResolvePath( string moddedPath, string characterName );
|
||||
|
||||
// Try to load a given gamePath with the resolved path from Penumbra.
|
||||
public T? GetFile< T >( string gamePath ) where T : FileResource;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
public int ApiVersion { get; } = 4;
|
||||
private Penumbra? _penumbra;
|
||||
private Lumina.GameData? _lumina;
|
||||
public event EventHandler? ObjectIsRedrawn;
|
||||
public event GameObjectRedrawn? GameObjectRedrawn;
|
||||
|
||||
public bool Valid
|
||||
=> _penumbra != null;
|
||||
|
|
@ -29,21 +29,16 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
{
|
||||
_penumbra = penumbra;
|
||||
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
||||
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
||||
?.GetValue( Dalamud.GameData );
|
||||
_penumbra.ObjectReloader.ObjectIsRedrawn += ObjectReloader_ObjectIsRedrawn;
|
||||
}
|
||||
|
||||
private void ObjectReloader_ObjectIsRedrawn( object? sender, EventArgs e )
|
||||
{
|
||||
ObjectIsRedrawn?.Invoke( sender, e );
|
||||
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
||||
?.GetValue( Dalamud.GameData );
|
||||
_penumbra.ObjectReloader.GameObjectRedrawn += OnGameObjectRedrawn;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_penumbra!.ObjectReloader.ObjectIsRedrawn -= ObjectReloader_ObjectIsRedrawn;
|
||||
_penumbra = null;
|
||||
_lumina = null;
|
||||
_penumbra!.ObjectReloader.GameObjectRedrawn -= OnGameObjectRedrawn;
|
||||
_penumbra = null;
|
||||
_lumina = null;
|
||||
}
|
||||
|
||||
public event ChangedItemClick? ChangedItemClicked;
|
||||
|
|
@ -98,13 +93,18 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
_penumbra!.ObjectReloader.RedrawObject( gameObject, setting );
|
||||
}
|
||||
|
||||
private void OnGameObjectRedrawn( IntPtr objectAddress, int objectTableIndex )
|
||||
{
|
||||
GameObjectRedrawn?.Invoke( objectAddress, objectTableIndex );
|
||||
}
|
||||
|
||||
public void RedrawAll( RedrawType setting )
|
||||
{
|
||||
CheckInitialized();
|
||||
_penumbra!.ObjectReloader.RedrawAll( setting );
|
||||
}
|
||||
|
||||
private static string ResolvePath( string path, Mods.Mod.Manager _, ModCollection collection )
|
||||
private static string ResolvePath( string path, Mod.Manager _, ModCollection collection )
|
||||
{
|
||||
if( !Penumbra.Config.EnableMods )
|
||||
{
|
||||
|
|
@ -129,7 +129,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
Penumbra.CollectionManager.Character( characterName ) );
|
||||
}
|
||||
|
||||
public string[] ReverseResolvePath( string path, string characterName )
|
||||
public IList< string > ReverseResolvePath( string path, string characterName )
|
||||
{
|
||||
CheckInitialized();
|
||||
if( !Penumbra.Config.EnableMods )
|
||||
|
|
@ -137,11 +137,8 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
return new[] { path };
|
||||
}
|
||||
|
||||
var gamePath = Utf8GamePath.FromString( path, out var p, true ) ? p : Utf8GamePath.Empty;
|
||||
var ret = Penumbra.CollectionManager.Character( characterName ).ResolveReversePath( new FullPath( path ) ) ??
|
||||
new List< Utf8GamePath >();
|
||||
if( ret.Count == 0 ) ret.Add( gamePath );
|
||||
return ret.Select( r => r.ToString() ).ToArray();
|
||||
var ret = Penumbra.CollectionManager.Character( characterName ).ReverseResolvePath( new FullPath( path ) );
|
||||
return ret.Select( r => r.ToString() ).ToList();
|
||||
}
|
||||
|
||||
private T? GetFileIntern< T >( string resolvedPath ) where T : FileResource
|
||||
|
|
@ -233,10 +230,11 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
return Penumbra.ModManager.Select( m => ( m.ModPath.Name, m.Name.Text ) ).ToArray();
|
||||
}
|
||||
|
||||
public IDictionary< string, (IList<string>, SelectType) >? GetAvailableModSettings( string modDirectory, string modName )
|
||||
public IDictionary< string, (IList< string >, SelectType) >? GetAvailableModSettings( string modDirectory, string modName )
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public (PenumbraApiEc, (bool, int, IDictionary< string, IList<string> >, bool)?) GetCurrentModSettings( string collectionName, string modDirectory, string modName,
|
||||
public (PenumbraApiEc, (bool, int, IDictionary< string, IList< string > >, bool)?) GetCurrentModSettings( string collectionName,
|
||||
string modDirectory, string modName,
|
||||
bool allowInheritance )
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
|
|
@ -252,7 +250,8 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
public PenumbraApiEc TrySetModSetting( string collectionName, string modDirectory, string modName, string optionGroupName, string option )
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public PenumbraApiEc TrySetModSetting( string collectionName, string modDirectory, string modName, string optionGroupName, IReadOnlyList<string> options )
|
||||
public PenumbraApiEc TrySetModSetting( string collectionName, string modDirectory, string modName, string optionGroupName,
|
||||
IReadOnlyList< string > options )
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public PenumbraApiEc CreateTemporaryCollection( string collectionName, string? character, bool forceOverwriteCharacter )
|
||||
|
|
|
|||
|
|
@ -111,17 +111,17 @@ public partial class PenumbraIpc
|
|||
|
||||
public partial class PenumbraIpc
|
||||
{
|
||||
public const string LabelProviderRedrawName = "Penumbra.RedrawObjectByName";
|
||||
public const string LabelProviderRedrawIndex = "Penumbra.RedrawObjectByIndex";
|
||||
public const string LabelProviderRedrawObject = "Penumbra.RedrawObject";
|
||||
public const string LabelProviderRedrawAll = "Penumbra.RedrawAll";
|
||||
public const string LabelProviderObjectIsRedrawn = "Penumbra.ObjectIsRedrawn";
|
||||
public const string LabelProviderRedrawName = "Penumbra.RedrawObjectByName";
|
||||
public const string LabelProviderRedrawIndex = "Penumbra.RedrawObjectByIndex";
|
||||
public const string LabelProviderRedrawObject = "Penumbra.RedrawObject";
|
||||
public const string LabelProviderRedrawAll = "Penumbra.RedrawAll";
|
||||
public const string LabelProviderGameObjectRedrawn = "Penumbra.GameObjectRedrawn";
|
||||
|
||||
internal ICallGateProvider< string, int, object >? ProviderRedrawName;
|
||||
internal ICallGateProvider< int, int, object >? ProviderRedrawIndex;
|
||||
internal ICallGateProvider< GameObject, int, object >? ProviderRedrawObject;
|
||||
internal ICallGateProvider< int, object >? ProviderRedrawAll;
|
||||
internal ICallGateProvider< string, string >? ProviderObjectIsRedrawn;
|
||||
internal ICallGateProvider< IntPtr, int, object? >? ProviderGameObjectRedrawn;
|
||||
|
||||
private static RedrawType CheckRedrawType( int value )
|
||||
{
|
||||
|
|
@ -178,19 +178,17 @@ public partial class PenumbraIpc
|
|||
|
||||
try
|
||||
{
|
||||
ProviderObjectIsRedrawn = pi.GetIpcProvider< string, string >( LabelProviderObjectIsRedrawn );
|
||||
Api.ObjectIsRedrawn += Api_ObjectIsRedrawn;
|
||||
ProviderGameObjectRedrawn = pi.GetIpcProvider< IntPtr, int, object? >( LabelProviderGameObjectRedrawn );
|
||||
Api.GameObjectRedrawn += OnGameObjectRedrawn;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderObjectIsRedrawn}:\n{e}" );
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGameObjectRedrawn}:\n{e}" );
|
||||
}
|
||||
}
|
||||
|
||||
private void Api_ObjectIsRedrawn( object? sender, EventArgs e )
|
||||
{
|
||||
ProviderObjectIsRedrawn?.SendMessage( ( ( GameObject? )sender )?.Name.ToString() ?? "" );
|
||||
}
|
||||
private void OnGameObjectRedrawn( IntPtr objectAddress, int objectTableIndex )
|
||||
=> ProviderGameObjectRedrawn?.SendMessage( objectAddress, objectTableIndex );
|
||||
|
||||
private void DisposeRedrawProviders()
|
||||
{
|
||||
|
|
@ -198,7 +196,7 @@ public partial class PenumbraIpc
|
|||
ProviderRedrawIndex?.UnregisterAction();
|
||||
ProviderRedrawObject?.UnregisterAction();
|
||||
ProviderRedrawAll?.UnregisterAction();
|
||||
Api.ObjectIsRedrawn -= Api_ObjectIsRedrawn;
|
||||
Api.GameObjectRedrawn -= OnGameObjectRedrawn;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,10 +207,10 @@ public partial class PenumbraIpc
|
|||
public const string LabelProviderGetDrawObjectInfo = "Penumbra.GetDrawObjectInfo";
|
||||
public const string LabelProviderReverseResolvePath = "Penumbra.ReverseResolvePath";
|
||||
|
||||
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
||||
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
||||
internal ICallGateProvider< IntPtr, (IntPtr, string) >? ProviderGetDrawObjectInfo;
|
||||
internal ICallGateProvider< string, string, string[] >? ProviderReverseResolvePath;
|
||||
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
||||
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
||||
internal ICallGateProvider< IntPtr, (IntPtr, string) >? ProviderGetDrawObjectInfo;
|
||||
internal ICallGateProvider< string, string, IList< string > >? ProviderReverseResolvePath;
|
||||
|
||||
private void InitializeResolveProviders( DalamudPluginInterface pi )
|
||||
{
|
||||
|
|
@ -248,7 +246,7 @@ public partial class PenumbraIpc
|
|||
|
||||
try
|
||||
{
|
||||
ProviderReverseResolvePath = pi.GetIpcProvider< string, string, string[] >( LabelProviderReverseResolvePath );
|
||||
ProviderReverseResolvePath = pi.GetIpcProvider< string, string, IList< string > >( LabelProviderReverseResolvePath );
|
||||
ProviderReverseResolvePath.RegisterFunc( Api.ReverseResolvePath );
|
||||
}
|
||||
catch( Exception e )
|
||||
|
|
@ -262,6 +260,7 @@ public partial class PenumbraIpc
|
|||
ProviderGetDrawObjectInfo?.UnregisterFunc();
|
||||
ProviderResolveDefault?.UnregisterFunc();
|
||||
ProviderResolveCharacter?.UnregisterFunc();
|
||||
ProviderReverseResolvePath?.UnregisterFunc();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue