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 std::filesystem::path const& getResourceDir() const;
47
48 LLNDAPI std::filesystem::path const& getBehaviorDir() const;
49
50 LLNDAPI io::Logger& getLogger() const;
51
52 [[nodiscard]] bool isEnabled() const { return getState() == State::Enabled; }
53
54 [[nodiscard]] bool isDisabled() const { return getState() == State::Disabled; }
55
56 // set on load callback and etc...
57 LLAPI void onLoad(CallbackFn func) noexcept;
58
59 LLAPI void onUnload(CallbackFn func) noexcept;
60
61 LLAPI void onEnable(CallbackFn func) noexcept;
62
63 LLAPI void onDisable(CallbackFn func) noexcept;
64
65protected:
66 LLAPI void release() noexcept;
67
68 LLAPI void setState(State state) const;
69
70 // is callback set
71 LLNDAPI bool hasOnLoad() const noexcept;
72
73 LLNDAPI bool hasOnUnload() const noexcept;
74
75 LLNDAPI bool hasOnEnable() const noexcept;
76
77 LLNDAPI bool hasOnDisable() const noexcept;
78
79 // call on load callback and etc...
80 LLAPI Expected<> onLoad() noexcept;
81
82 LLAPI Expected<> onUnload() noexcept;
83
84 LLAPI Expected<> onEnable() noexcept;
85
86 LLAPI Expected<> onDisable() noexcept;
87
88private:
89 friend ModManager;
90
91 struct Impl;
92 std::unique_ptr<Impl> mImpl;
93};
94} // namespace ll::mod
Definition Logger.h:29
Definition ModManager.h:19
Definition Mod.h:17
Definition Manifest.h:29