From 947dcf7f2691286210a1169120a9c8020dc18d36 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Tue, 9 Jan 2024 10:47:23 -0300 Subject: [PATCH] add concepts to validate the types for the ext classes --- loader/include/Geode/utils/cocos.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index 33883629..88ea5b8f 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -903,6 +903,12 @@ namespace geode::cocos { } }; + template + concept CocosObjectPtr = std::is_pointer_v && std::is_convertible_v; + + template + concept CocosDictionaryKey = std::same_as || std::same_as || std::same_as || std::same_as; + /** * A templated wrapper over CCArray, providing easy iteration and indexing. * This will keep ownership of the given CCArray*. @@ -914,12 +920,12 @@ namespace geode::cocos { * // Easy indexing, giving you the type you assigned * GameObject* myObj = objects[2]; * - * // Easy iteration using c++ range-based for loops + * // Easy iteration using C++ range-based for loops * for (auto* obj : objects) { * log::info("{}", obj->m_objectID); * } */ - template + template class CCArrayExt { protected: Ref m_arr; @@ -1055,12 +1061,12 @@ namespace geode::cocos { * // Easy indexing, giving you the type you assigned * GJGameLevel* myLvl = levels["Cube Adventures"]; * - * // Easy iteration using c++ range-based for loops + * // Easy iteration using C++ range-based for loops * for (auto [name, level] : levels) { * log::info("{}: {}", name, level->m_levelID); * } */ - template + template struct CCDictionaryExt { protected: Ref m_dict; @@ -1103,5 +1109,9 @@ namespace geode::cocos { size_t count(const Key& key) { return this->contains(key) ? 1 : 0; } + + cocos2d::CCDictionary* inner() { + return m_dict; + } }; }