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