LeviLamina
Loading...
Searching...
No Matches
ModManagerRegistry.h
1#pragma once
2
3#include "ll/api/Expected.h"
4#include "ll/api/base/Macro.h"
5#include "ll/api/base/StdInt.h"
6#include "ll/api/coro/Generator.h"
7#include "ll/api/data/DependencyGraph.h"
8#include "ll/api/mod/ModManager.h"
9#include "ll/api/mod/NativeMod.h"
10
11namespace ll::mod {
12class ModRegistrar;
13class ModManagerRegistry {
14 friend ModRegistrar;
15 friend Mod;
16 struct Impl;
17 std::unique_ptr<Impl> impl;
18
19 ModManagerRegistry();
20 ~ModManagerRegistry();
21
22 Expected<> loadMod(Manifest manifest) noexcept;
23
24 Expected<> unloadMod(std::string_view name) noexcept;
25
26 Expected<> enableMod(std::string_view name) const noexcept;
27
28 Expected<> disableMod(std::string_view name) const noexcept;
29
30 Expected<> onModLoad(std::string_view name) const noexcept;
31
32 Expected<> onModUnload(std::string_view name) const noexcept;
33
34 Expected<> onModEnable(std::string_view name) const noexcept;
35
36 Expected<> onModDisable(std::string_view name) const noexcept;
37
38public:
39 using CallbackId = uint64;
40
41 enum class ModCallbackType {
42 Load,
43 Unload,
44 Enable,
45 Disable,
46 All = -1,
47 };
48
49 LLNDAPI static ModManagerRegistry& getInstance();
50
51 LLNDAPI bool addManager(std::shared_ptr<ModManager> const& manager);
52
53 LLNDAPI bool eraseManager(std::string_view type);
54
55 LLNDAPI bool hasManager(std::string_view type) const;
56
57 LLNDAPI std::shared_ptr<ModManager> getManager(std::string_view type) const;
58
59 LLNDAPI std::shared_ptr<ModManager> getManagerForMod(std::string_view name) const;
60
61 LLNDAPI coro::Generator<ModManager&> managers() const;
62
63 LLNDAPI coro::Generator<Mod&> mods() const;
64
65 LLNDAPI bool hasMod(std::string_view name) const;
66
67 LLNDAPI std::string getModType(std::string_view name) const;
68
69 LLNDAPI std::shared_ptr<Mod> getMod(std::string_view name) const;
70
71 LLAPI CallbackId executeOnMod(
72 ModCallbackType type,
73 std::function<void(std::string_view name)>&& fn,
74 std::weak_ptr<Mod> mod = NativeMod::current()
75 ) noexcept;
76
77 CallbackId executeOnModLoad(
78 std::function<void(std::string_view name)>&& fn,
79 std::weak_ptr<Mod> mod = NativeMod::current()
80 ) noexcept {
81 return executeOnMod(ModCallbackType::Load, std::move(fn), std::move(mod));
82 }
83
84 CallbackId executeOnModUnload(
85 std::function<void(std::string_view name)>&& fn,
86 std::weak_ptr<Mod> mod = NativeMod::current()
87 ) noexcept {
88 return executeOnMod(ModCallbackType::Unload, std::move(fn), std::move(mod));
89 }
90
91 CallbackId executeOnModEnable(
92 std::function<void(std::string_view name)>&& fn,
93 std::weak_ptr<Mod> mod = NativeMod::current()
94 ) noexcept {
95 return executeOnMod(ModCallbackType::Enable, std::move(fn), std::move(mod));
96 }
97
98 CallbackId executeOnModDisable(
99 std::function<void(std::string_view name)>&& fn,
100 std::weak_ptr<Mod> mod = NativeMod::current()
101 ) noexcept {
102 return executeOnMod(ModCallbackType::Disable, std::move(fn), std::move(mod));
103 }
104
105 LLAPI bool eraseOnModCallback(CallbackId id) noexcept;
106 LLAPI size_t eraseOnModCallback(std::weak_ptr<Mod> mod, ModCallbackType type = ModCallbackType::All) noexcept;
107};
108} // namespace ll::mod
Definition Generator.h:69
Definition Manifest.h:29