mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-25 07:11:51 -05:00

* Port over ShipInit and transform Moon Jump as example * Clean up moon jump * Updated moon jump structure & cvar defines
44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
#ifndef SHIP_INIT_HPP
|
|
#define SHIP_INIT_HPP
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <vector>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
#include <functional>
|
|
|
|
struct ShipInit {
|
|
static std::unordered_map<std::string, std::vector<std::function<void()>>>& GetAll() {
|
|
static std::unordered_map<std::string, std::vector<std::function<void()>>> shipInitFuncs;
|
|
return shipInitFuncs;
|
|
}
|
|
|
|
static void InitAll() {
|
|
ShipInit::Init("*");
|
|
}
|
|
|
|
static void Init(const std::string& path) {
|
|
auto& shipInitFuncs = ShipInit::GetAll();
|
|
for (const auto& initFunc : shipInitFuncs[path]) {
|
|
initFunc();
|
|
}
|
|
}
|
|
};
|
|
|
|
struct RegisterShipInitFunc {
|
|
RegisterShipInitFunc(std::function<void()> initFunc, const std::set<std::string>& updatePaths = {}) {
|
|
auto& shipInitFuncs = ShipInit::GetAll();
|
|
|
|
shipInitFuncs["*"].push_back(initFunc);
|
|
|
|
for (const auto& path : updatePaths) {
|
|
shipInitFuncs[path].push_back(initFunc);
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif // __cplusplus
|
|
|
|
#endif // SHIP_INIT_HPP
|