mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-21 07:17:53 +01:00
Update to API4, use IPC instead of API-project. Replace Actor in most visible names with Object, Character or Player..
This commit is contained in:
parent
3680d2b63f
commit
4dfc2cf665
60 changed files with 812 additions and 740 deletions
47
Penumbra/Api/IPenumbraApi.cs
Normal file
47
Penumbra/Api/IPenumbraApi.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Lumina.Data;
|
||||
using Penumbra.GameData.Enums;
|
||||
|
||||
namespace Penumbra.Api
|
||||
{
|
||||
public interface IPenumbraApiBase
|
||||
{
|
||||
public int ApiVersion { get; }
|
||||
public bool Valid { get; }
|
||||
}
|
||||
|
||||
public delegate void ChangedItemHover( object? item );
|
||||
public delegate void ChangedItemClick( MouseButton button, object? item );
|
||||
|
||||
public interface IPenumbraApi : IPenumbraApiBase
|
||||
{
|
||||
// Triggered when the user hovers over a listed changed object in a mod tab.
|
||||
// Can be used to append tooltips.
|
||||
public event ChangedItemHover? ChangedItemTooltip;
|
||||
// Triggered when the user clicks a listed changed object in a mod tab.
|
||||
public event ChangedItemClick? ChangedItemClicked;
|
||||
|
||||
// Queue redrawing of all actors of the given name with the given RedrawType.
|
||||
public void RedrawObject( string name, RedrawType setting );
|
||||
|
||||
// Queue redrawing of the specific actor with the given RedrawType. Should only be used when the actor is sure to be valid.
|
||||
public void RedrawObject( GameObject gameObject, RedrawType setting );
|
||||
|
||||
// Queue redrawing of all currently available actors with the given RedrawType.
|
||||
public void RedrawAll( RedrawType setting );
|
||||
|
||||
// Resolve a given gamePath via Penumbra using the Default and Forced collections.
|
||||
// Returns the given gamePath if penumbra would not manipulate it.
|
||||
public string ResolvePath(string gamePath);
|
||||
|
||||
// Resolve a given gamePath via Penumbra using the character collection for the given name (if it exists) and the Forced collections.
|
||||
// Returns the given gamePath if penumbra would not manipulate it.
|
||||
public string ResolvePath( string gamePath, string characterName );
|
||||
|
||||
// Try to load a given gamePath with the resolved path from Penumbra.
|
||||
public T? GetFile< T >( string gamePath ) where T : FileResource;
|
||||
|
||||
// Try to load a given gamePath with the resolved path from Penumbra.
|
||||
public T? GetFile<T>( string gamePath, string characterName ) where T : FileResource;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Logging;
|
||||
using Lumina.Data;
|
||||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.GameData.Util;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
|
@ -12,18 +13,18 @@ namespace Penumbra.Api
|
|||
{
|
||||
public class PenumbraApi : IDisposable, IPenumbraApi
|
||||
{
|
||||
public int ApiVersion { get; } = 2;
|
||||
private readonly Plugin _plugin;
|
||||
public int ApiVersion { get; } = 3;
|
||||
private readonly Penumbra _penumbra;
|
||||
private readonly Lumina.GameData? _lumina;
|
||||
public bool Valid { get; private set; } = false;
|
||||
|
||||
public PenumbraApi( Plugin penumbra )
|
||||
public PenumbraApi( Penumbra penumbra )
|
||||
{
|
||||
_plugin = penumbra;
|
||||
_penumbra = penumbra;
|
||||
Valid = true;
|
||||
_lumina = ( Lumina.GameData? )_plugin.PluginInterface.Data.GetType()
|
||||
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
||||
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
||||
?.GetValue( _plugin.PluginInterface.Data );
|
||||
?.GetValue( Dalamud.GameData );
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -52,30 +53,30 @@ namespace Penumbra.Api
|
|||
}
|
||||
}
|
||||
|
||||
public void RedrawActor( string name, RedrawType setting )
|
||||
public void RedrawObject( string name, RedrawType setting )
|
||||
{
|
||||
CheckInitialized();
|
||||
|
||||
_plugin.ActorRefresher.RedrawActor( name, setting );
|
||||
_penumbra.ObjectReloader.RedrawObject( name, setting );
|
||||
}
|
||||
|
||||
public void RedrawActor( Actor? actor, RedrawType setting )
|
||||
public void RedrawObject( GameObject? gameObject, RedrawType setting )
|
||||
{
|
||||
CheckInitialized();
|
||||
|
||||
_plugin.ActorRefresher.RedrawActor( actor, setting );
|
||||
_penumbra.ObjectReloader.RedrawObject( gameObject, setting );
|
||||
}
|
||||
|
||||
public void RedrawAll( RedrawType setting )
|
||||
{
|
||||
CheckInitialized();
|
||||
|
||||
_plugin.ActorRefresher.RedrawAll( setting );
|
||||
_penumbra.ObjectReloader.RedrawAll( setting );
|
||||
}
|
||||
|
||||
private string ResolvePath( string path, ModManager manager, ModCollection collection )
|
||||
private static string ResolvePath( string path, ModManager manager, ModCollection collection )
|
||||
{
|
||||
if( !_plugin.Configuration.IsEnabled )
|
||||
if( !Penumbra.Config.IsEnabled )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
|
@ -110,7 +111,7 @@ namespace Penumbra.Api
|
|||
return _lumina?.GetFileFromDisk< T >( resolvedPath );
|
||||
}
|
||||
|
||||
return _plugin.PluginInterface.Data.GetFile< T >( resolvedPath );
|
||||
return Dalamud.GameData.GetFile< T >( resolvedPath );
|
||||
}
|
||||
catch( Exception e)
|
||||
{
|
||||
|
|
|
|||
136
Penumbra/Api/PenumbraIpc.cs
Normal file
136
Penumbra/Api/PenumbraIpc.cs
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
using System;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
using Penumbra.GameData.Enums;
|
||||
|
||||
namespace Penumbra.Api
|
||||
{
|
||||
public class PenumbraIpc
|
||||
{
|
||||
public const string LabelProviderApiVersion = "Penumbra.ApiVersion";
|
||||
public const string LabelProviderRedrawName = "Penumbra.RedrawObjectByName";
|
||||
public const string LabelProviderRedrawObject = "Penumbra.RedrawObject";
|
||||
public const string LabelProviderRedrawAll = "Penumbra.RedrawAll";
|
||||
public const string LabelProviderResolveDefault = "Penumbra.ResolveDefaultPath";
|
||||
public const string LabelProviderResolveCharacter = "Penumbra.ResolveCharacterPath";
|
||||
|
||||
public const string LabelProviderChangedItemTooltip = "Penumbra.ChangedItemTooltip";
|
||||
public const string LabelProviderChangedItemClick = "Penumbra.ChangedItemClick";
|
||||
|
||||
internal ICallGateProvider< int >? ProviderApiVersion;
|
||||
internal ICallGateProvider< string, int, object >? ProviderRedrawName;
|
||||
internal ICallGateProvider< GameObject, int, object >? ProviderRedrawObject;
|
||||
internal ICallGateProvider< int, object >? ProviderRedrawAll;
|
||||
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
||||
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
||||
internal ICallGateProvider< object?, object >? ProviderChangedItemTooltip;
|
||||
internal ICallGateProvider< int, object?, object >? ProviderChangedItemClick;
|
||||
|
||||
internal readonly IPenumbraApi _api;
|
||||
|
||||
private static RedrawType CheckRedrawType( int value )
|
||||
{
|
||||
var type = ( RedrawType )value;
|
||||
if( Enum.IsDefined( type ) )
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new Exception( "The integer provided for a Redraw Function was not a valid RedrawType." );
|
||||
}
|
||||
|
||||
private void OnClick( MouseButton click, object? item )
|
||||
=> ProviderChangedItemClick?.SendMessage( ( int )click, item );
|
||||
|
||||
|
||||
public PenumbraIpc( DalamudPluginInterface pi, IPenumbraApi api )
|
||||
{
|
||||
_api = api;
|
||||
|
||||
try
|
||||
{
|
||||
ProviderApiVersion = pi.GetIpcProvider< int >( LabelProviderApiVersion );
|
||||
ProviderApiVersion.RegisterFunc( () => api.ApiVersion );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderApiVersion}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderRedrawName = pi.GetIpcProvider< string, int, object >( LabelProviderRedrawName );
|
||||
ProviderRedrawName.RegisterAction( ( s, i ) => api.RedrawObject( s, CheckRedrawType( i ) ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderRedrawName}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderRedrawObject = pi.GetIpcProvider< GameObject, int, object >( LabelProviderRedrawObject );
|
||||
ProviderRedrawObject.RegisterAction( ( o, i ) => api.RedrawObject( o, CheckRedrawType( i ) ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderRedrawObject}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderRedrawAll = pi.GetIpcProvider< int, object >( LabelProviderRedrawAll );
|
||||
ProviderRedrawAll.RegisterFunc( i =>
|
||||
{
|
||||
api.RedrawAll( CheckRedrawType( i ) );
|
||||
return null!;
|
||||
} );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderRedrawAll}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderResolveDefault = pi.GetIpcProvider< string, string >( LabelProviderResolveDefault );
|
||||
ProviderResolveDefault.RegisterFunc( api.ResolvePath );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderResolveDefault}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderResolveCharacter = pi.GetIpcProvider< string, string, string >( LabelProviderResolveCharacter );
|
||||
ProviderResolveCharacter.RegisterFunc( api.ResolvePath );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderResolveCharacter}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderChangedItemTooltip = pi.GetIpcProvider< object?, object >( LabelProviderChangedItemTooltip );
|
||||
api.ChangedItemTooltip += ProviderChangedItemTooltip.SendMessage;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemTooltip}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderChangedItemClick = pi.GetIpcProvider< int, object?, object >( LabelProviderChangedItemClick );
|
||||
api.ChangedItemClicked += OnClick;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue