mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Add IPC event on state change and increment IPC minor version.
This commit is contained in:
parent
fa4f22f6f5
commit
6518f958b7
4 changed files with 35 additions and 7 deletions
21
Glamourer/Api/GlamourerIpc.Events.cs
Normal file
21
Glamourer/Api/GlamourerIpc.Events.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Interop.Structs;
|
||||
using Glamourer.State;
|
||||
using Penumbra.Api.Helpers;
|
||||
|
||||
namespace Glamourer.Api;
|
||||
|
||||
public partial class GlamourerIpc
|
||||
{
|
||||
public const string LabelStateChanged = "Glamourer.StateChanged";
|
||||
|
||||
private readonly StateChanged _stateChangedEvent;
|
||||
private readonly EventProvider<StateChanged.Type, nint, Lazy<string>> _stateChangedProvider;
|
||||
|
||||
private void OnStateChanged(StateChanged.Type type, StateChanged.Source source, ActorState state, ActorData actors, object? data = null)
|
||||
{
|
||||
foreach (var actor in actors.Objects)
|
||||
_stateChangedProvider.Invoke(type, actor.Address, new Lazy<string>(() => _designConverter.ShareBase64(state)));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Interop;
|
||||
using Glamourer.Services;
|
||||
using Glamourer.State;
|
||||
|
|
@ -16,23 +17,21 @@ namespace Glamourer.Api;
|
|||
public partial class GlamourerIpc : IDisposable
|
||||
{
|
||||
public const int CurrentApiVersionMajor = 0;
|
||||
public const int CurrentApiVersionMinor = 1;
|
||||
public const int CurrentApiVersionMinor = 2;
|
||||
|
||||
private readonly StateManager _stateManager;
|
||||
private readonly ObjectManager _objects;
|
||||
private readonly ActorService _actors;
|
||||
private readonly ItemManager _items;
|
||||
private readonly DesignConverter _designConverter;
|
||||
|
||||
|
||||
public GlamourerIpc(DalamudPluginInterface pi, StateManager stateManager, ObjectManager objects, ActorService actors, ItemManager items,
|
||||
DesignConverter designConverter)
|
||||
public GlamourerIpc(DalamudPluginInterface pi, StateManager stateManager, ObjectManager objects, ActorService actors,
|
||||
DesignConverter designConverter, StateChanged stateChangedEvent)
|
||||
{
|
||||
_stateManager = stateManager;
|
||||
_objects = objects;
|
||||
_actors = actors;
|
||||
_items = items;
|
||||
_designConverter = designConverter;
|
||||
_stateChangedEvent = stateChangedEvent;
|
||||
_apiVersionProvider = new FuncProvider<int>(pi, LabelApiVersion, ApiVersion);
|
||||
_apiVersionsProvider = new FuncProvider<(int Major, int Minor)>(pi, LabelApiVersions, ApiVersions);
|
||||
|
||||
|
|
@ -51,6 +50,10 @@ public partial class GlamourerIpc : IDisposable
|
|||
|
||||
_revertProvider = new ActionProvider<string>(pi, LabelRevert, Revert);
|
||||
_revertCharacterProvider = new ActionProvider<Character?>(pi, LabelRevertCharacter, RevertCharacter);
|
||||
|
||||
_stateChangedProvider = new EventProvider<StateChanged.Type, nint, Lazy<string>>(pi, LabelStateChanged);
|
||||
|
||||
_stateChangedEvent.Subscribe(OnStateChanged, StateChanged.Priority.GlamourerIpc);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -69,6 +72,9 @@ public partial class GlamourerIpc : IDisposable
|
|||
_applyOnlyCustomizationToCharacterProvider.Dispose();
|
||||
_revertProvider.Dispose();
|
||||
_revertCharacterProvider.Dispose();
|
||||
|
||||
_stateChangedEvent.Unsubscribe(OnStateChanged);
|
||||
_stateChangedProvider.Dispose();
|
||||
}
|
||||
|
||||
private IEnumerable<ActorIdentifier> FindActors(string actorName)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public sealed class StateChanged : EventWrapper<Action<StateChanged.Type, StateC
|
|||
|
||||
public enum Priority
|
||||
{
|
||||
GlamourerIpc = int.MinValue,
|
||||
}
|
||||
|
||||
public StateChanged()
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ public class StateManager : IReadOnlyDictionary<ActorIdentifier, ActorState>
|
|||
actors = ApplyAll(state, redraw, true);
|
||||
Glamourer.Log.Verbose(
|
||||
$"Reset entire state of {state.Identifier.Incognito(null)} to game base. [Affecting {actors.ToLazyString("nothing")}.]");
|
||||
_event.Invoke(StateChanged.Type.Design, StateChanged.Source.Manual, state, actors, null);
|
||||
_event.Invoke(StateChanged.Type.Reset, StateChanged.Source.Manual, state, actors, null);
|
||||
}
|
||||
|
||||
public void ReapplyState(Actor actor)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue