Skip to content

Commit f54aeae

Browse files
authored
we don't actually have attributes anymore
1 parent 2256e55 commit f54aeae

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mods/dependencies.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,30 @@ $execute {
104104

105105
An example of using dispatch events in practice [can be found in MouseAPI](https://github.com/geode-sdk/MouseAPI/blob/main/src/test.cpp#L54-L94).
106106

107-
### Attributes
107+
### User Objects
108108

109-
One way for mods to communicate with optional dependencies is through **node attributes**, which may contain any data. These are like the `setUserData` and `setUserObject` functions native to `CCNode`s, except that attributes have a string key associated with them. For example, a mod that adds scrollbars to layers might use the following check to see if a scrollbar should be added to a layer:
109+
One way for mods to communicate with optional dependencies is through **user objects**, which may contain any data. These are like the `setUserData` and `setUserObject` functions native to `CCNode`s, except that these objects have a string key associated with them. For example, a mod that adds scrollbars to layers might use the following check to see if a scrollbar should be added to a layer:
110110

111111
```cpp
112-
if (layer->getAttribute<bool>("hjfod.cool-scrollbars/enable")) {
112+
if (layer->getUserObject("hjfod.cool-scrollbars/enable")) {
113113
// add scrollbar
114114
}
115115
```
116116
117-
Other mods can set this attribute on their layers with the `CCNode::setAttribute` function.
117+
Other mods can add this user object to their layers with the `CCNode::setUserObject` function:
118+
119+
```cpp
120+
layer->setUserObject("hjfod.cool-scrollbars/enable", CCBool::create(true));
121+
```
122+
123+
As these are typical `CCObject`s, a mod can store any piece of information within a user object. This can range from objects as simple as a `CCBool` to more complicated, mod-specific ones that store multiple pieces of data.
118124

119125
Mods can also add an event listener to listen for when attributes are added/changed:
120126

121127
```cpp
122128
$execute {
123129
new EventListener<AttributeSetFilter>(
124-
+[](AttributeSetEvent* event) {
130+
+[](UserObjectSetEvent* event) {
125131
addScrollbar(event->node);
126132
},
127133
AttributeSetFilter("hjfod.cool-scrollbars/enable")

0 commit comments

Comments
 (0)