Skip to content

Commit

Permalink
Add getting parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed May 19, 2024
1 parent 1cdf364 commit c139243
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Every node can have `"children"`, there are three ways of accessing them, either
"type": "CCSprite",
"index": 0,
"attributes": {

...
}
}
],
Expand All @@ -58,14 +58,32 @@ Every node can have `"children"`, there are three ways of accessing them, either
}
```

You can also get the parent from a child:

```json
{
"children": {
"node": {
"example-node":{
"parent": {
"attributes":{
...
}
}
}
}
}
}
```

Within MenuLayer, we can see there is a menu, the main menu, which has three buttons. Any or all of these buttons can be modified within that MenuLayer.json file. We would first want to get the main menu by grabbing the children of the MenuLayer, and finding the `"main-menu"` ID:

```json
{
"children": {
"node": {
"main-menu":{

...
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class $modify(MyCCScene, CCScene){
doUICheck(node);
}
}
m_fields->currentCount = this->getChildrenCount();
}
m_fields->currentCount = this->getChildrenCount();
}
};

Expand Down Expand Up @@ -387,7 +387,6 @@ std::string getSound(std::string sound){
return soundRet;
}


void playSound(CCNode* node, matjson::Object attributes){
if(attributes.contains("sound")){
matjson::Value soundVal = attributes["sound"];
Expand Down Expand Up @@ -441,7 +440,6 @@ void openLink(CCNode* node, matjson::Object attributes){
}
}


void setZOrder(CCNode* node, matjson::Object attributes){
if(attributes.contains("z-order")){
matjson::Value zOrderVal = attributes["z-order"];
Expand Down Expand Up @@ -964,6 +962,17 @@ void handleModifications(CCNode* node, matjson::Object nodeObject){
}
}

if(nodeObject.contains("parent")){
matjson::Value parentVal = nodeObject["parent"];
if(parentVal.is_object()){
matjson::Object parentObject = parentVal.as_object();
CCNode* parent = node->getParent();
if(parent){
handleModifications(parent, parentObject);
}
}
}

if(nodeObject.contains("children")){
matjson::Value childrenVal = nodeObject["children"];
if(childrenVal.is_object()){
Expand Down

0 comments on commit c139243

Please sign in to comment.