Abstract base class for all Malena plugins.
More...
#include <Plugin.h>
|
| virtual | ~Plugin ()=default |
| template<typename T> |
| T * | getIf () |
| | Return a T* if this plugin is an instance of T, or nullptr otherwise.
|
| template<typename T> |
| const T * | getIf () const |
| | Const overload of getIf.
|
| virtual const char * | getName () const |
| | Return the plugin's display name.
|
| virtual const sf::Texture * | getThumbnail () const |
| | Return a pointer to this plugin's thumbnail texture, or nullptr.
|
| virtual const char * | getVersion () const |
| | Return the plugin's version string.
|
| template<typename T> |
| bool | is () const |
| | Return true if this plugin is an instance of T.
|
| void | offAllMessages () |
| | Unsubscribe from all messages registered by this object.
|
| template<typename DataType, typename Enum> |
| void | offMessage (Enum event) |
| | Unsubscribe from a specific typed message.
|
| virtual void | onLoad () |
| | Called immediately after the plugin is loaded and constructed.
|
| template<typename DataType, typename Enum> |
| void | onMessage (Enum event, std::function< void(const DataType &)> callback) |
| | Register a callback to receive a typed message.
|
| virtual void | onUnload () |
| | Called just before the plugin is destroyed and unloaded.
|
| template<typename DataType, typename Enum> |
| void | sendMessage (Enum event, const DataType &data) |
| | Publish a typed message to all current subscribers.
|
Abstract base class for all Malena plugins.
Plugin defines the lifecycle interface that every plugin must implement. Subclass via PluginWith<Manifest> rather than Plugin directly — PluginWith wires in the manifest, flag/state machinery, and resource accessors automatically.
Lifecycle
onLoad() — called immediately after the plugin is constructed and registered. Use this to set up components, subscribe to events, etc.
onUnload() — called just before the plugin is destroyed. Use this to clean up any state the plugin owns.
Type queries
if (plugin->is<IScorePlugin>()) { ... }
if (auto* score = plugin->getIf<IScorePlugin>()) {
score->addPoints(10);
}
- See also
- PluginWith, PluginManager, ML_EXPORT
Definition at line 76 of file Plugin.h.
◆ ~Plugin()
| virtual ml::Plugin::~Plugin |
( |
| ) |
|
|
virtualdefault |
◆ getIf() [1/2]
template<typename T>
| T * ml::Plugin::getIf |
( |
| ) |
|
|
inline |
Return a T* if this plugin is an instance of T, or nullptr otherwise.
- Template Parameters
-
Definition at line 136 of file Plugin.h.
◆ getIf() [2/2]
template<typename T>
| const T * ml::Plugin::getIf |
( |
| ) |
const |
|
inline |
Const overload of getIf.
- Template Parameters
-
Definition at line 144 of file Plugin.h.
◆ getName()
| virtual const char * ml::Plugin::getName |
( |
| ) |
const |
|
inlinevirtual |
Return the plugin's display name.
- Returns
- Null-terminated name string. Defaults to
"Unnamed Plugin".
Definition at line 85 of file Plugin.h.
◆ getThumbnail()
| virtual const sf::Texture * ml::Plugin::getThumbnail |
( |
| ) |
const |
|
inlinevirtual |
Return a pointer to this plugin's thumbnail texture, or nullptr.
Used by PluginManager::scanPlugins() to populate PluginInfo records for display in a carousel or menu. Return nullptr if the plugin has no thumbnail.
- Returns
- Pointer to the thumbnail
sf::Texture, or nullptr.
Definition at line 102 of file Plugin.h.
◆ getVersion()
| virtual const char * ml::Plugin::getVersion |
( |
| ) |
const |
|
inlinevirtual |
Return the plugin's version string.
- Returns
- Null-terminated version string. Defaults to
"1.0.0".
Definition at line 91 of file Plugin.h.
◆ is()
template<typename T>
| bool ml::Plugin::is |
( |
| ) |
const |
|
inline |
Return true if this plugin is an instance of T.
- Template Parameters
-
| T | The type to check against. |
Definition at line 127 of file Plugin.h.
◆ offAllMessages()
| void ml::Messenger::offAllMessages |
( |
| ) |
|
|
inherited |
Unsubscribe from all messages registered by this object.
Called automatically by the destructor. Only call manually if you need to reset all subscriptions while the object is still alive.
◆ offMessage()
template<typename DataType, typename Enum>
| void ml::Messenger::offMessage |
( |
Enum | event | ) |
|
|
inherited |
Unsubscribe from a specific typed message.
After this call, the callback previously registered for event and DataType will no longer be invoked. Safe to call from within the callback itself.
- Template Parameters
-
| DataType | The payload type of the subscription to remove. |
| Enum | The enum type identifying the event. |
- Parameters
-
| event | The specific event to unsubscribe from. |
◆ onLoad()
| virtual void ml::Plugin::onLoad |
( |
| ) |
|
|
inlinevirtual |
Called immediately after the plugin is loaded and constructed.
Override to initialise components, subscribe to events, load resources, and perform any other startup work.
Definition at line 110 of file Plugin.h.
◆ onMessage()
template<typename DataType, typename Enum>
| void ml::Messenger::onMessage |
( |
Enum | event, |
|
|
std::function< void(const DataType &)> | callback ) |
|
inherited |
Register a callback to receive a typed message.
The callback is invoked each time sendMessage is called with the same event and DataType. Multiple calls with the same event replace the previous callback for that event.
- Template Parameters
-
| DataType | The expected payload type. |
| Enum | The enum type identifying the event. |
- Parameters
-
| event | The specific event to listen for. |
| callback | Function called with a const reference to the payload when the event fires. |
◆ onUnload()
| virtual void ml::Plugin::onUnload |
( |
| ) |
|
|
inlinevirtual |
Called just before the plugin is destroyed and unloaded.
Override to clean up any state the plugin owns. All event and message subscriptions are removed automatically after this call, so explicit unsubscription is not required.
Definition at line 119 of file Plugin.h.
◆ sendMessage()
template<typename DataType, typename Enum>
| void ml::Messenger::sendMessage |
( |
Enum | event, |
|
|
const DataType & | data ) |
|
inherited |
Publish a typed message to all current subscribers.
All objects that have called onMessage for the same event and DataType will have their callbacks invoked with data. Delivery is immediate unless MessageManager is currently iterating, in which case it is deferred.
- Template Parameters
-
| DataType | The payload type. Must match the type used in the corresponding onMessage call. |
| Enum | The enum type identifying the event. |
- Parameters
-
| event | The specific event to send. |
| data | The payload to deliver to subscribers. |
The documentation for this class was generated from the following file: