2#ifndef LIBSBX_SCENES_COMPONENT_IO_HPP_
3#define LIBSBX_SCENES_COMPONENT_IO_HPP_
7#include <unordered_map>
9#include <yaml-cpp/yaml.h>
11#include <libsbx/ecs/registry.hpp>
13#include <libsbx/scenes/node.hpp>
14#include <libsbx/scenes/scene_graph.hpp>
15#include <libsbx/scenes/asset_registry.hpp>
17namespace sbx::scenes {
31 template<
typename Type, std::invocable<YAML::Emitter&, scene_graph&, asset_registry&, const Type&> Save, std::invocable<const YAML::Node&, scene_graph&, asset_registry&> Load>
32 auto register_component(
const std::string& name, Save&& save, Load&& load) ->
void {
40 const auto& component = graph.get_component<Type>(
node);
42 std::invoke(s, emitter, graph, registry, component);
45 graph.add_or_update_component<Type>(
node, std::invoke(l, yaml, graph, registry));
54 auto has(
const std::uint32_t
id)
const ->
bool {
55 return _by_id.contains(
id);
59 return _by_id.at(_by_name.at(name));
62 auto has(
const std::string& name)
const ->
bool {
63 return _by_name.contains(name);
68 std::unordered_map<std::uint32_t, component_io> _by_id;
69 std::unordered_map<std::string, std::uint32_t> _by_name;
Definition: asset_registry.hpp:81
Definition: component_io.hpp:27
Definition: scene_graph.hpp:32
Definition: component_io.hpp:19
static auto value() noexcept -> std::uint32_t
Generates a unique ID for the type.
Definition: type_id.hpp:41