From 73fb99753304e4c1668050e3e483c5038e5407d5 Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Wed, 17 Jul 2024 20:44:35 +0200 Subject: [PATCH] Add metadata conversion function --- source/core/CMakeLists.txt | 1 + source/core/inc/tactile/core/meta/meta.hpp | 32 ++++++++++++++++++++ source/core/src/tactile/core/meta/meta.cpp | 34 ++++++++++++++++++++++ source/core/test/CMakeLists.txt | 2 +- 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 source/core/src/tactile/core/meta/meta.cpp diff --git a/source/core/CMakeLists.txt b/source/core/CMakeLists.txt index 89d66c657d..dd44e4f682 100644 --- a/source/core/CMakeLists.txt +++ b/source/core/CMakeLists.txt @@ -66,6 +66,7 @@ target_sources(tactile-core "src/tactile/core/map/map_spec.cpp" "src/tactile/core/meta/attribute_type.cpp" "src/tactile/core/meta/color.cpp" + "src/tactile/core/meta/meta.cpp" "src/tactile/core/model/model.cpp" "src/tactile/core/model/settings.cpp" "src/tactile/core/numeric/random.cpp" diff --git a/source/core/inc/tactile/core/meta/meta.hpp b/source/core/inc/tactile/core/meta/meta.hpp index 61775e90d7..a3e6e51cad 100644 --- a/source/core/inc/tactile/core/meta/meta.hpp +++ b/source/core/inc/tactile/core/meta/meta.hpp @@ -7,10 +7,17 @@ #include "tactile/base/container/string_map.hpp" #include "tactile/base/meta/attribute.hpp" #include "tactile/base/prelude.hpp" +#include "tactile/core/entity/entity.hpp" #include "tactile/core/util/uuid.hpp" namespace tactile { +class Registry; + +namespace ir { +struct Metadata; +} // namespace ir + /** * Represents an attribute bundle. * @@ -35,4 +42,29 @@ struct CMeta final HashMap components; }; +/** + * Indicates whether an entity is a meta context. + * + * \param registry The associated registry. + * \param id The target entity identifier. + * + * \return + * True if the entity is a meta context; false otherwise. + */ +[[nodiscard]] +auto is_meta(const Registry& registry, EntityID id) -> bool; + +/** + * Converts IR metadata to the internal representation and adds it to a context. + * + * \pre The entity identifier must reference a meta context. + * + * \param registry The associated registry. + * \param meta_id The meta context entity identifier. + * \param ir_metadata The source metadata representation. + */ +void convert_ir_metadata(Registry& registry, + EntityID meta_id, + const ir::Metadata& ir_metadata); + } // namespace tactile diff --git a/source/core/src/tactile/core/meta/meta.cpp b/source/core/src/tactile/core/meta/meta.cpp new file mode 100644 index 0000000000..326db013b3 --- /dev/null +++ b/source/core/src/tactile/core/meta/meta.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) + +#include "tactile/core/meta/meta.hpp" + +#include "tactile/base/io/save/ir.hpp" +#include "tactile/core/debug/assert.hpp" +#include "tactile/core/entity/registry.hpp" + +namespace tactile { + +auto is_meta(const Registry& registry, const EntityID id) -> bool +{ + return registry.has(id); +} + +void convert_ir_metadata(Registry& registry, + const EntityID meta_id, + const ir::Metadata& ir_metadata) +{ + TACTILE_ASSERT(is_meta(registry, meta_id)); + + auto& meta = registry.get(meta_id); + meta.name = ir_metadata.name; + + for (const auto& [prop_name, prop_value] : ir_metadata.properties) { + meta.properties.insert_or_assign(prop_name, prop_value); + } + + for (const auto& [comp_name, comp_attributes] : ir_metadata.components) { + // TODO + } +} + +} // namespace tactile diff --git a/source/core/test/CMakeLists.txt b/source/core/test/CMakeLists.txt index ceab67eac3..e749687661 100644 --- a/source/core/test/CMakeLists.txt +++ b/source/core/test/CMakeLists.txt @@ -53,7 +53,7 @@ target_sources(tactile-core-test tactile_prepare_target(tactile-core-test) target_link_libraries(tactile-core-test - PUBLIC + PRIVATE tactile::core GTest::gtest )