Skip to content

Commit 09b3eaa

Browse files
committed
Use struct instead of pair
1 parent 6213c19 commit 09b3eaa

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

include/NodeModding.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
#endif
1717

1818
namespace AlphaUtils {
19+
20+
struct ModifyInfo {
21+
int priority;
22+
std::function<void(cocos2d::CCNode*)> method;
23+
};
24+
1925
class ALPHA_UTILS_API_DLL NodeModding {
2026
protected:
21-
std::unordered_map<std::string, std::vector<std::pair<int, std::function<void(cocos2d::CCNode*)>>>> m_nodesToModify;
27+
std::unordered_map<std::string, std::vector<ModifyInfo>> m_nodesToModify;
2228

2329
public:
2430
static NodeModding* get();
25-
std::unordered_map<std::string, std::vector<std::pair<int, std::function<void(cocos2d::CCNode*)>>>> getNodesToModify();
31+
std::unordered_map<std::string, std::vector<ModifyInfo>> getNodesToModify();
2632
void addNodeToModify(std::string className, int prio, std::function<void(cocos2d::CCNode*)> func);
2733
void handleNode(cocos2d::CCNode* node);
2834
};

src/NodeModding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace geode::prelude;
66
using namespace AlphaUtils;
77

8-
std::unordered_map<std::string, std::vector<std::pair<int, std::function<void(CCNode*)>>>> NodeModding::getNodesToModify() {
8+
std::unordered_map<std::string, std::vector<ModifyInfo>> NodeModding::getNodesToModify() {
99
return m_nodesToModify;
1010
}
1111

@@ -16,13 +16,13 @@ void NodeModding::addNodeToModify(std::string className, int prio, std::function
1616
void NodeModding::handleNode(CCNode* node) {
1717
std::string className = AlphaUtils::Cocos::getClassName(node);
1818
if (m_nodesToModify.contains(className)) {
19-
std::vector<std::pair<int, std::function<void(CCNode*)>>> methods = m_nodesToModify[className];
19+
std::vector<ModifyInfo> methods = m_nodesToModify[className];
2020
std::sort(methods.begin(), methods.end(), [](auto& left, auto& right) {
21-
return left.first < right.first;
21+
return left.priority < right.priority;
2222
});
2323

2424
for (auto pair : methods) {
25-
pair.second(node);
25+
pair.method(node);
2626
}
2727
}
2828
}

0 commit comments

Comments
 (0)