JustEnoughMod
Loading...
Searching...
No Matches
Plugin.hpp
1#ifndef PLUGIN_PLUGIN_HPP
2#define PLUGIN_PLUGIN_HPP
3
4#include <core/Logger.hpp>
5#include <string>
6#include <util/Version.hpp>
7
8#include <memory>
9
10#define JEM_PLUGIN_DEF(plugin) \
11 extern "C" auto _createPlugin()->JEM::Plugin::Plugin * { \
12 return new plugin(); \
13 }
14
15namespace JEM::Plugin {
16 class Plugin {
17 public:
18 virtual ~Plugin() = default;
19
20 [[nodiscard]] virtual constexpr auto getPluginName() -> const char * = 0;
21 [[nodiscard]] virtual constexpr auto getPluginVersion() -> Version {
22 return Version("0.0.0");
23 }
24
25 virtual void init() = 0;
26 virtual void update() = 0;
27
28 void load() {
29 m_logger = std::make_shared<Logger>(getPluginName());
30 getLogger()->info("Loading Plugin {} with Version {}", getPluginName(),
31 static_cast<std::string>(getPluginVersion()));
32 }
33
34 [[nodiscard]] auto getLogger() const -> std::shared_ptr<Logger> {
35 return m_logger;
36 }
37
38 private:
39 std::shared_ptr<Logger> m_logger;
40 };
41} // namespace JEM::Plugin
42
43#endif
Definition Plugin.hpp:16
Definition Version.hpp:9