mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-13 22:49:52 -04:00
allow passing pointers to getChildByType, CCArrayExt, CCDictionaryExt
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
This commit is contained in:
parent
19f18ca927
commit
b956596194
2 changed files with 20 additions and 16 deletions
|
@ -1133,7 +1133,7 @@ public:
|
|||
* @returns Child at index cast to the given type,
|
||||
* or nullptr if index exceeds bounds
|
||||
*/
|
||||
template <class T = CCNode>
|
||||
template <class InpT = CCNode*, class T = std::remove_pointer_t<InpT>>
|
||||
T* getChildByType(int index) {
|
||||
size_t indexCounter = 0;
|
||||
if (this->getChildrenCount() == 0) return nullptr;
|
||||
|
|
|
@ -962,6 +962,9 @@ namespace geode::cocos {
|
|||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
concept CocosObject = std::derived_from<T, cocos2d::CCObject>;
|
||||
|
||||
template <class T>
|
||||
concept CocosObjectPtr = std::is_pointer_v<T> && std::is_convertible_v<T, cocos2d::CCObject const*>;
|
||||
|
||||
|
@ -984,11 +987,10 @@ namespace geode::cocos {
|
|||
* log::info("{}", obj->m_objectID);
|
||||
* }
|
||||
*/
|
||||
template <CocosObjectPtr Type>
|
||||
template <class InpT, CocosObject T = std::remove_pointer_t<InpT>>
|
||||
class CCArrayExt {
|
||||
protected:
|
||||
Ref<cocos2d::CCArray> m_arr;
|
||||
using T = std::remove_pointer_t<Type>;
|
||||
|
||||
public:
|
||||
using value_type = T*;
|
||||
|
@ -1053,19 +1055,19 @@ namespace geode::cocos {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename K, typename T>
|
||||
template <class K, class InpT, CocosObject T = std::remove_pointer_t<InpT>>
|
||||
struct CCDictIterator {
|
||||
public:
|
||||
CCDictIterator(cocos2d::CCDictElement* p) : m_ptr(p) {}
|
||||
|
||||
cocos2d::CCDictElement* m_ptr;
|
||||
|
||||
std::pair<K, T> operator*() {
|
||||
std::pair<K, T*> operator*() {
|
||||
if constexpr (std::is_same_v<K, std::string> || std::is_same_v<K, gd::string>) {
|
||||
return {m_ptr->getStrKey(), static_cast<T>(m_ptr->getObject())};
|
||||
return {m_ptr->getStrKey(), static_cast<T*>(m_ptr->getObject())};
|
||||
}
|
||||
else {
|
||||
return {m_ptr->getIntKey(), static_cast<T>(m_ptr->getObject())};
|
||||
return {m_ptr->getIntKey(), static_cast<T*>(m_ptr->getObject())};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1074,11 +1076,11 @@ namespace geode::cocos {
|
|||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator==(CCDictIterator<K, T> const& a, CCDictIterator<K, T> const& b) {
|
||||
friend bool operator==(CCDictIterator<K, InpT> const& a, CCDictIterator<K, InpT> const& b) {
|
||||
return a.m_ptr == b.m_ptr;
|
||||
};
|
||||
|
||||
friend bool operator!=(CCDictIterator<K, T> const& a, CCDictIterator<K, T> const& b) {
|
||||
friend bool operator!=(CCDictIterator<K, InpT> const& a, CCDictIterator<K, InpT> const& b) {
|
||||
return a.m_ptr != b.m_ptr;
|
||||
};
|
||||
|
||||
|
@ -1087,22 +1089,22 @@ namespace geode::cocos {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename K, typename T>
|
||||
template <class K, class InpT, CocosObject T = std::remove_pointer_t<InpT>>
|
||||
struct CCDictEntry {
|
||||
K m_key;
|
||||
cocos2d::CCDictionary* m_dict;
|
||||
|
||||
CCDictEntry(K key, cocos2d::CCDictionary* dict) : m_key(key), m_dict(dict) {}
|
||||
|
||||
T operator->() {
|
||||
return static_cast<T>(m_dict->objectForKey(m_key));
|
||||
T* operator->() {
|
||||
return static_cast<T*>(m_dict->objectForKey(m_key));
|
||||
}
|
||||
|
||||
operator T() {
|
||||
return static_cast<T>(m_dict->objectForKey(m_key));
|
||||
operator T*() {
|
||||
return static_cast<T*>(m_dict->objectForKey(m_key));
|
||||
}
|
||||
|
||||
CCDictEntry& operator=(T f) {
|
||||
CCDictEntry& operator=(T* f) {
|
||||
m_dict->setObject(f, m_key);
|
||||
return *this;
|
||||
}
|
||||
|
@ -1125,9 +1127,11 @@ namespace geode::cocos {
|
|||
* log::info("{}: {}", name, level->m_levelID);
|
||||
* }
|
||||
*/
|
||||
template <CocosDictionaryKey Key, CocosObjectPtr ValuePtr>
|
||||
template <CocosDictionaryKey Key, class ValueInpT, CocosObject Value = std::remove_pointer_t<ValueInpT>>
|
||||
struct CCDictionaryExt {
|
||||
protected:
|
||||
using ValuePtr = Value*;
|
||||
|
||||
Ref<cocos2d::CCDictionary> m_dict;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue