8#ifndef GALAXY_META_ENTITYFACTORY_HPP_
9#define GALAXY_META_ENTITYFACTORY_HPP_
11#include <ankerl/unordered_dense.h>
12#include <entt/entt.hpp>
13#include <nlohmann/json.hpp>
44 using Validations = ankerl::unordered_dense::map<entt::id_type, std::move_only_function<bool(
const entt::entity, entt::registry&)>>;
45 using ComponentJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<void(
const entt::entity, entt::registry&,
const nlohmann::json&)>>;
46 using AnyJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<entt::any(
const nlohmann::json&)>>;
66 template<val
id_component Component>
77 void json_factory(
const std::string& type,
const entt::entity entity, entt::registry& registry,
const nlohmann::json& json);
88 entt::any
any_from_json(
const std::string& type,
const nlohmann::json& json);
99 nlohmann::json
serialize_entity(
const entt::entity entity, entt::registry& registry);
112 entt::entity
deserialize_entity(
const nlohmann::json& json, entt::registry& registry);
122 const std::string&
get_type(
const entt::id_type
id);
132 entt::id_type
get_typeid(
const std::string& name);
190 const auto hash = entt::type_id<ToValidate>().hash();
193 m_validations[hash] = [
this](
const entt::entity entity, entt::registry& registry) ->
bool {
194 const auto* component = registry.try_get<ToValidate>(entity);
197 return registry.all_of<Dependencies...>(entity);
214 template<val
id_component Component>
219 const auto hash = entt::type_id<Component>().hash();
223 if constexpr (std::constructible_from<Component, const nlohmann::json&>)
225 m_json_factory.emplace(name, [](
const entt::entity entity, entt::registry& registry,
const nlohmann::json& json) {
226 registry.emplace<Component>(entity, json);
230 return entt::make_any<Component>(json);
234 if constexpr (std::derived_from<Component, fs::Serializable>)
237 return SerializationData {.name = name, .json =
static_cast<Component*
>(component)->serialize()};
#define GALAXY_LOG(level, msg,...)