Skip to content

Commit

Permalink
Add metadata conversion function
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 17, 2024
1 parent bcac93f commit 73fb997
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions source/core/inc/tactile/core/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -35,4 +42,29 @@ struct CMeta final
HashMap<UUID, AttributeBundle> 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
34 changes: 34 additions & 0 deletions source/core/src/tactile/core/meta/meta.cpp
Original file line number Diff line number Diff line change
@@ -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<CMeta>(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<CMeta>(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
2 changes: 1 addition & 1 deletion source/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 73fb997

Please sign in to comment.