LeviLamina
Loading...
Searching...
No Matches
Mod.h
1#pragma once
2
3#include <filesystem>
4#include <functional>
5#include <memory>
6
7#include "ll/api/Expected.h"
8#include "ll/api/base/Macro.h"
9#include "ll/api/io/Logger.h"
10#include "ll/api/mod/Manifest.h"
11
12namespace ll::mod {
13
14LLNDAPI std::filesystem::path const& getModsRoot();
15
16class ModManager;
17class Mod {
18public:
19 enum class State {
20 Enabled,
21 Disabled,
22 };
23 using callback_t = bool(Mod&);
24 using CallbackFn = std::function<callback_t>;
25
26 LLNDAPI explicit Mod(Manifest manifest);
27
28 LLAPI ~Mod();
29
30 LLNDAPI State getState() const;
31
32 LLNDAPI Manifest const& getManifest() const;
33
34 LLNDAPI std::string const& getName() const;
35
36 LLNDAPI std::string const& getType() const;
37
38 LLNDAPI std::filesystem::path const& getModDir() const;
39
40 LLNDAPI std::filesystem::path const& getDataDir() const;
41
42 LLNDAPI std::filesystem::path const& getConfigDir() const;
43
44 LLNDAPI std::filesystem::path const& getLangDir() const;
45
46 LLNDAPI io::Logger& getLogger() const;
47
48 [[nodiscard]] bool isEnabled() const { return getState() == State::Enabled; }
49
50 [[nodiscard]] bool isDisabled() const { return getState() == State::Disabled; }
51
52 // set on load callback and etc...
53 LLAPI void onLoad(CallbackFn func) noexcept;
54
55 LLAPI void onUnload(CallbackFn func) noexcept;
56
57 LLAPI void onEnable(CallbackFn func) noexcept;
58
59 LLAPI void onDisable(CallbackFn func) noexcept;
60
61protected:
62 LLAPI void release() noexcept;
63
64 LLAPI void setState(State state) const;
65
66 // is callback set
67 LLNDAPI bool hasOnLoad() const noexcept;
68
69 LLNDAPI bool hasOnUnload() const noexcept;
70
71 LLNDAPI bool hasOnEnable() const noexcept;
72
73 LLNDAPI bool hasOnDisable() const noexcept;
74
75 // call on load callback and etc...
76 LLAPI Expected<> onLoad() noexcept;
77
78 LLAPI Expected<> onUnload() noexcept;
79
80 LLAPI Expected<> onEnable() noexcept;
81
82 LLAPI Expected<> onDisable() noexcept;
83
84private:
85 friend ModManager;
86
87 struct Impl;
88 std::unique_ptr<Impl> mImpl;
89};
90} // namespace ll::mod
Definition Logger.h:25
Definition ModManager.h:19
Definition Mod.h:17
Definition Manifest.h:31