Skip to content

Commit 76ec69b

Browse files
Add documentations on the optional API
1 parent d67d9e8 commit 76ec69b

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

docs/getting-started/dependency-setup.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ Add the following in your `mod.json`:
1212
```json
1313
{
1414
"dependencies": {
15-
"smjs.object-collab": {
16-
"version": ">={the latest version}",
17-
"required": true
18-
}
15+
"smjs.object-collab": ">={the latest version}"
1916
}
2017
}
2118
```

docs/utilities/optional-api.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Optional API
3+
order: 3
4+
---
5+
6+
# Optional API
7+
8+
Object-Collab comes with a small optional API to get access to the internal object register. This way you can find the details about an object and under what IDs they are registered without explicitly depending on Object-Collab.
9+
10+
All information provided by this method is made as minimal as possible to avoid over-reliance on Object-Collab to resolve the information.
11+
12+
## Example
13+
14+
### Mod.json
15+
16+
```json
17+
{
18+
"dependencies": {
19+
"smjs.object-collab": {
20+
"version": ">={the latest version}",
21+
"required": false
22+
}
23+
}
24+
}
25+
```
26+
27+
### C++
28+
29+
```cpp
30+
#include <smjs.object-collab/include/object_collab_optional.hpp>
31+
32+
using namespace object_collab::prelude;
33+
34+
void MyObjectHandling::handleCustomObjects() {
35+
object_collab::getOptionalRegister().listen([](OptionalRegister objectRegister) {
36+
for (auto& [numericID, info] : objectRegister) {
37+
// Do whatever you want with the object.
38+
}
39+
});
40+
}
41+
```

include/object_collab.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace object_collab {
2020
namespace prelude {
21+
using namespace object_collab;
2122
using namespace editor_popup;
2223
}
2324
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#define MY_MOD_ID "smjs.object-collab"
77

88
namespace object_collab {
9+
namespace prelude {
10+
using namespace object_collab;
11+
}
12+
913
/// The simplified object info for optional inclusions
1014
struct OptionalObjectInfo {
1115
std::string id;
@@ -20,5 +24,6 @@ namespace object_collab {
2024
using OptionalRegister = std::unordered_map<uint32_t, OptionalObjectInfo>;
2125

2226
/// Gets the simplified register
27+
/// @warning Numeric IDs are subject to change between levels. It's not recommended to cache the output of this method.
2328
inline geode::Result<OptionalRegister> getOptionalRegister() GEODE_EVENT_EXPORT(&getOptionalRegister, ());
2429
}

0 commit comments

Comments
 (0)