|
| 1 | +# Alpha's Geode Utils |
| 2 | + |
| 3 | +Miscellaneous Geode utils to make development easier: |
| 4 | + |
| 5 | +## Modifying any CCObject |
| 6 | + |
| 7 | +Familiar modify syntax as Geode, supporting fields. `class $objectModify(SomeObject)` or `class $nodeModify(SomeNode)` |
| 8 | +You can name the modified node/object the same way as well `class $objectModify(MySomeObject, SomeObject)` or `class $nodeModify(MySomeNode, SomeNode)` |
| 9 | + |
| 10 | +$nodeModify and $objectModify do the same thing, except $nodeModify is a base of CCNode while $objectModify is a base of CCObject |
| 11 | + |
| 12 | +To use this, you will create a `void modify()` method within that class and inside of there you can change the node to your hearts content. You can use the fields struct just like in Geode to add fields if needed. |
| 13 | + |
| 14 | +To edit the priority (lets say another mod modifies the same node using this) you can add `static int modifyPrio()` to the class which should return an integer value that is the priority you wish to set. |
| 15 | + |
| 16 | +**Full Example modifying BetterInfo's CustomCreatorLayer:** |
| 17 | + |
| 18 | +```c++ |
| 19 | +class $nodeModify(MyCustomCreatorLayer, CustomCreatorLayer) { |
| 20 | + |
| 21 | + static int modifyPrio() { |
| 22 | + return 10; |
| 23 | + } |
| 24 | + |
| 25 | + struct Fields { |
| 26 | + int m_number = 0; |
| 27 | + }; |
| 28 | + |
| 29 | + void modify() { |
| 30 | + |
| 31 | + CCSprite* spr = CCSprite::createWithSpriteFrameName("GJ_playBtn_001.png"); |
| 32 | + CCMenuItemSpriteExtra* btn = CCMenuItemSpriteExtra::create(spr, this, menu_selector(MyCustomCreatorLayer::onEpicButton)); |
| 33 | + btn->setID("epic-button"_spr); |
| 34 | + |
| 35 | + if (CCMenu* creatorButtonsMenu = typeinfo_cast<CCMenu*>(getChildByID("cvolton.betterinfo/creator-buttons-menu"))) { |
| 36 | + creatorButtonsMenu->addChild(btn); |
| 37 | + creatorButtonsMenu->updateLayout(); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + void onEpicButton(CCObject* obj) { |
| 42 | + log::info("m_number {}", m_fields->m_number); |
| 43 | + m_fields->m_number++; |
| 44 | + } |
| 45 | +}; |
| 46 | +``` |
| 47 | +
|
| 48 | +## Modifying Base Classes of CCNodes |
| 49 | +
|
| 50 | +Using $baseModify, you can modify all nodes that inheret some class. In the following example, we modify all FLAlertLayers, not just FLAlertLayer itself. These are different than the above $nodeModify and $cobjectModify, as it requires a valid type to be passed in, thus it does not natively support modifying other mod's nodes without declaring the class beforehand. |
| 51 | +
|
| 52 | +```c++ |
| 53 | +class $baseModify(MyFLAlertLayer, FLAlertLayer) { |
| 54 | +
|
| 55 | + void modify() { |
| 56 | + setScale(2.f); |
| 57 | + } |
| 58 | +
|
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +If you still wish to modify another mod's nodes by their base class, you can do the following. |
| 63 | +Let's say we had a node called AlphasEpicNode, which in itself inherets CCNode, that a lot of nodes from AlphasEpicMod inherit. Because we are defining it beforehand (make sure the definition matches that of how it is in said mod), the mod can deduce it and it's own base class names and it will work as expected. |
| 64 | + |
| 65 | +```c++ |
| 66 | +class AlphasEpicNode : public CCNode {}; |
| 67 | +class $baseModify(MyAlphasEpicNode, AlphasEpicNode) { |
| 68 | + |
| 69 | + void modify() { |
| 70 | + setScale(2.f); |
| 71 | + } |
| 72 | + |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +## General Utils |
| 77 | + |
| 78 | +### AlphaUtils::Cocos namespace: |
| 79 | + |
| 80 | +Getting sprites while ignoring Texture Loader fallback: |
| 81 | +`std::optional<cocos2d::CCSprite*> getSprite(const char* sprName)` |
| 82 | +`std::optional<cocos2d::CCSprite*> getSpriteByFrameName(const char* sprFrameName)` |
| 83 | + |
| 84 | +Getting a layer from the scene even during transition: |
| 85 | +`std::optional<cocos2d::CCNode*> getLayer()` |
| 86 | +`std::optional<cocos2d::CCNode*> getLayerByClassName(std::string className)` |
| 87 | + |
| 88 | +Setting a node color by hex code: |
| 89 | +`bool setColorByHex(cocos2d::CCRGBAProtocol* node, std::string colorHex)` |
| 90 | + |
| 91 | +Checking if a parent node contains a node anywhere in a tree: |
| 92 | +`bool hasNode(cocos2d::CCNode* child, cocos2d::CCNode* parent)` |
| 93 | + |
| 94 | +Getting a child by class name dynamically: |
| 95 | +`std::optional<cocos2d::CCNode*> getChildByClassName(cocos2d::CCNode* node, std::string name, int index = 0)` |
| 96 | + |
| 97 | +Getting a node's class name: |
| 98 | +`std::string getClassName(cocos2d::CCObject* obj, bool removeNamespace = false)` |
| 99 | + |
| 100 | +### AlphaUtils::Misc namespace: |
| 101 | + |
| 102 | +Getting a random number: |
| 103 | +`int getRandomNumber(int lower, int upper)` |
0 commit comments