@rtsdk/topia 0.19.3 → 0.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -43
- package/dist/index.cjs +419 -51
- package/dist/index.d.ts +410 -258
- package/dist/index.js +419 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -240,44 +240,70 @@ export const getDroppedAssetAndVisitor = async (req: Request, res: Response) =>
|
|
|
240
240
|
};
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
<br/><br/>
|
|
244
|
-
|
|
245
243
|
## Data Objects
|
|
246
244
|
|
|
247
245
|
Data Objects can be used to store information such as game state, configurations, themes, and analytics.
|
|
248
246
|
There are three types of Data Objects:
|
|
249
247
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
248
|
+
### World:
|
|
249
|
+
|
|
250
|
+
The data object attached to the world will store information for every instance of the app in a given world by keyAssetId or sceneDropId and will persist even if a specific instance is removed from world. Data stored in the World data object should be minimal to avoid running into limits.
|
|
251
|
+
|
|
252
|
+
#### Example - Update two specific data points:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
await world.updateDataObject({
|
|
256
|
+
[sceneDropId]: { keyAssetId: droppedAsset.id, themeId: "custom", totalInteractions: 1 },
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### Example - Increment a specific value within the data object by 1:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
await world.incrementDataObjectValue([`${sceneDropId}.totalInteractions`], 1);
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Dropped Asset:
|
|
267
|
+
|
|
268
|
+
The Dropped Asset data object should only store what is unique to the specific instance of the app in the world such as game state. If the Dropped Asset is deleted, the data object would be lost as well so be sure to only store information here the doesn't need to persist!
|
|
269
|
+
|
|
270
|
+
#### Example - Initialize data object with default data and keyAssetId:
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
await droppedAsset.setDataObject(
|
|
274
|
+
{
|
|
275
|
+
...defaultGameData,
|
|
276
|
+
keyAssetId: droppedAsset.id,
|
|
277
|
+
},
|
|
278
|
+
{ lock: { lockId, releaseLock: true } },
|
|
279
|
+
);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### Example - Update lastInteraction date and playerCount:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
await droppedAsset.updateDataObject({ lastInteraction: new Date(), playerCount: playerCount + 1 });
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### User:
|
|
289
|
+
|
|
290
|
+
The data object attached to the visitor should store information related specifically to the visitor i.e. progress. For tracking across multiple world/instances use `${urlSlug}_${sceneDropId}` as a unique key.
|
|
291
|
+
|
|
292
|
+
#### Example - Initialize data object with default data and keyAssetId:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
await visitor.setDataObject(
|
|
296
|
+
{
|
|
297
|
+
[`${urlSlug}_${sceneDropId}`]: {
|
|
298
|
+
currentStreak: 0,
|
|
299
|
+
lastCollectedDate: null,
|
|
300
|
+
longestStreak: 0,
|
|
301
|
+
totalCollected: 0,
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
{ lock: { lockId, releaseLock: true } },
|
|
305
|
+
);
|
|
306
|
+
```
|
|
281
307
|
|
|
282
308
|
### Data Object Locking
|
|
283
309
|
|
|
@@ -324,7 +350,7 @@ await world.setDataObject({ hello: "world" }, { analytics: [{ analyticName: "res
|
|
|
324
350
|
|
|
325
351
|
await world.updateDataObject({}, { analytics: [ {analyticName: "matches", uniqueKey: `${playerOneProfileId}-${playerTwoProfileId}`, urlSlug }], });
|
|
326
352
|
|
|
327
|
-
await world.incrementDataObjectValue(
|
|
353
|
+
await world.incrementDataObjectValue(`${sceneDropId}.completions`, 1, { analytics: [{ analyticName:"completions", incrementBy: 2, profileId, uniqueKey: profileId, urlSlug }] });
|
|
328
354
|
```
|
|
329
355
|
|
|
330
356
|
Examples leveraging Visitor data objects calls:
|
|
@@ -345,7 +371,7 @@ await visitor.incrementDataObjectValue(`completions`, 1, {
|
|
|
345
371
|
});
|
|
346
372
|
```
|
|
347
373
|
|
|
348
|
-
Note: passing an empty object does NOT impact the data objects themselves but rather allows you to track custom analytics
|
|
374
|
+
Note: passing an empty object does NOT impact the data objects themselves but rather allows you to track custom analytics across all instances of your application with a given Public Key.
|
|
349
375
|
|
|
350
376
|
<br>
|
|
351
377
|
|
|
@@ -353,26 +379,18 @@ Note: passing an empty object does NOT impact the data objects themselves but ra
|
|
|
353
379
|
|
|
354
380
|
<hr/>
|
|
355
381
|
|
|
356
|
-
<br>
|
|
357
|
-
|
|
358
382
|
## Get Started
|
|
359
383
|
|
|
360
384
|
Run `gh repo clone metaversecloud-com/mc-sdk-js`
|
|
361
385
|
|
|
362
|
-
<br>
|
|
363
|
-
|
|
364
386
|
## Issues
|
|
365
387
|
|
|
366
388
|
We've added an Issue template to help standardize Issues and ensure they have enough detail for a developer to start work and help prevent contributors from forgetting to add an important piece of information.
|
|
367
389
|
|
|
368
|
-
<br>
|
|
369
|
-
|
|
370
390
|
## Pull Requests
|
|
371
391
|
|
|
372
392
|
We've added a Pull Request template to help make it easier for developers to clarify what the proposed changes will do. This helps facilitate clear communication between all contributors of the SDK and ensures that we are all on the same page!
|
|
373
393
|
|
|
374
|
-
<br>
|
|
375
|
-
|
|
376
394
|
## Documentation
|
|
377
395
|
|
|
378
396
|
### Styles
|