In https://github.com/OpenPF2/PF2Core/pull/38, we are implementing a new design pattern called the "Event Emitter" pattern. At the moment, that MR is just updating objects needed for input binding events. This issue tracks the technical debt remaining to update all of our other classes referenced through interfaces with the pattern.
Implementing the Pattern
Each Event Emitter, which is an object behind a UInterface (e.g., UPF2Party is behind IPF2PartyInterface, UPF2CharacterQueueComponent is behind IPF2CharacterQueueInterface, etc.), does the following:
Moves all its BlueprintAssignable, dynamic, multicast delegates out and into an Events Object, which is a new UObject class that is named after the interface but has Events at the end of the name (e.g., IPF2PartyInterface, IPF2CharacterQueueInterfaceEvents, etc). This new class is defined in the same file as the UInterface (e.g., put it in Source/OpenPF2Core/Public/PF2PartyInterface.h, Source/OpenPF2Core/Public/PF2CharacterQueueInterface.h, etc.).
In the primary UInterface of the object: Exposes a new Blueprint-callable GetEvents method that returns an instance of the new events class. The return type for this method must be specific to the Events Object type. For example, UPF2CharacterQueueInterfaceEvents defines its GetEvents() method as follows:
/**
* Gets the events object used for binding Blueprint callbacks to events from this component.
*
* @return
* The events object for this interface.
*/
UFUNCTION(BlueprintCallable, Category="OpenPF2|Components|Player Controllers|Character Queues")
virtual UPF2CharacterQueueInterfaceEvents* GetEvents() const = 0;
In the Event Emitter: Defines a constructor that instantiates the Events Object and stores it in a UPROPERTY of the instance.
In the Event Emitter: Implements the GetEvents() method on the Event Emitter, returning the instance of the Events Object initialized in the constructor.
In the Event Emitter:
Extends the IPF2EventEmitterInterface interface as a public base class.
Implements an override of the GetGenericEventsObject() method, just returning the result of the GetEvents() method. This method is used internally by editor support so that the delegate properties defined in the Events Object can be bound in a blueprint as if they were declared on the Event Emitter.
In https://github.com/OpenPF2/PF2Core/pull/38, we are implementing a new design pattern called the "Event Emitter" pattern. At the moment, that MR is just updating objects needed for input binding events. This issue tracks the technical debt remaining to update all of our other classes referenced through interfaces with the pattern.
Implementing the Pattern
Each Event Emitter, which is an object behind a
UInterface
(e.g.,UPF2Party
is behindIPF2PartyInterface
,UPF2CharacterQueueComponent
is behindIPF2CharacterQueueInterface
, etc.), does the following:BlueprintAssignable
, dynamic, multicast delegates out and into an Events Object, which is a newUObject
class that is named after the interface but hasEvents
at the end of the name (e.g.,IPF2PartyInterface
,IPF2CharacterQueueInterfaceEvents
, etc). This new class is defined in the same file as theUInterface
(e.g., put it inSource/OpenPF2Core/Public/PF2PartyInterface.h
,Source/OpenPF2Core/Public/PF2CharacterQueueInterface.h
, etc.).UInterface
of the object: Exposes a new Blueprint-callableGetEvents
method that returns an instance of the new events class. The return type for this method must be specific to the Events Object type. For example,UPF2CharacterQueueInterfaceEvents
defines itsGetEvents()
method as follows:UPROPERTY
of the instance.GetEvents()
method on the Event Emitter, returning the instance of the Events Object initialized in the constructor.IPF2EventEmitterInterface
interface as a public base class.GetGenericEventsObject()
method, just returning the result of theGetEvents()
method. This method is used internally by editor support so that the delegate properties defined in the Events Object can be bound in a blueprint as if they were declared on the Event Emitter.