diff options
author | hop311 <hop3114@gmail.com> | 2024-04-15 01:13:46 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-04-15 01:24:07 +0200 |
commit | 083365191bd5f586edd850e0bd6a0190de782ab1 (patch) | |
tree | c03b31ed54afbd0cba57b37e47a16fb560131b8f /src/openvic-simulation/types/IdentifierRegistry.hpp | |
parent | a7f125a5f276e2951d1236fe88e32c5c08271504 (diff) |
Rework GFX::Actor Attachments and Animations
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index c1fef9d..533273a 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -269,6 +269,23 @@ namespace OpenVic { } \ return nullptr; \ } \ + template<std::derived_from<external_value_type> T> \ + requires requires(external_value_type const& value) { \ + { value.get_type() } -> std::same_as<std::string_view>; \ + { T::get_type_static() } -> std::same_as<std::string_view>; \ + } \ + constexpr T CONST* get_cast_item_by_identifier(std::string_view identifier) CONST { \ + external_value_type CONST* item = get_item_by_identifier(identifier); \ + if (item != nullptr) { \ + if (item->get_type() == T::get_type_static()) { \ + return reinterpret_cast<T CONST*>(item); \ + } \ + Logger::error( \ + "Invalid type for item \"", identifier, "\": ", item->get_type(), " (expected ", T::get_type_static(), ")" \ + ); \ + } \ + return nullptr; \ + } \ constexpr external_value_type CONST* get_item_by_index(std::size_t index) CONST { \ if (index < items.size()) { \ return std::addressof(ValueInfo::get_external_value(ItemInfo::get_value(items[index]))); \ @@ -565,6 +582,10 @@ private: constexpr decltype(registry)::external_value_type const_kw* get_##singular##_by_identifier(std::string_view identifier) const_kw { \ return registry.get_item_by_identifier(identifier); \ } \ + template<std::derived_from<decltype(registry)::external_value_type> T> \ + constexpr T const_kw* get_cast_##singular##_by_identifier(std::string_view identifier) const_kw { \ + return registry.get_cast_item_by_identifier<T>(identifier); \ + } \ constexpr decltype(registry)::external_value_type const_kw* get_##singular##_by_index(std::size_t index) const_kw { \ return index >= index_offset ? registry.get_item_by_index(index - index_offset) : nullptr; \ } \ |