You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
31 lines
1.1 KiB
#pragma once
|
|
#include <functional>
|
|
#include <nlohmann/json.hpp>
|
|
#include <nlohmann/json_fwd.hpp>
|
|
#include "dinkyecs.hpp"
|
|
|
|
|
|
#define ENROLL_COMPONENT(COMPONENT, ...) \
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(COMPONENT, __VA_ARGS__); \
|
|
template <> struct NameOf<COMPONENT> { \
|
|
static constexpr const char *name = #COMPONENT; \
|
|
};
|
|
|
|
namespace components {
|
|
using namespace nlohmann;
|
|
|
|
template <typename T> struct NameOf;
|
|
|
|
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>;
|
|
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
|
|
|
template <typename COMPONENT> void enroll(ComponentMap &m) {
|
|
m[NameOf<COMPONENT>::name] = [](DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j) {
|
|
COMPONENT c;
|
|
from_json(j, c);
|
|
world.set<COMPONENT>(ent, c);
|
|
};
|
|
}
|
|
|
|
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data);
|
|
}
|
|
|