@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 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
- - **World:** The World data object should be used to store information unique to your app in a given world but not necessarily specific details about an instance or an active game. This information would persist even if the app was removed from the world.
251
- - **Example - Update two specific data points:**
252
- ```ts
253
- await world.updateDataObject({
254
- [`keyAssets.${keyAssetId}.itemsCollectedByUser.${profileId}`]: { [dateKey]: { count: 1 }, total: 1 },
255
- [`profileMapper.${profileId}`]: username,
256
- });
257
- ```
258
- - **Example - Increment a specific value within the data object by 1:**
259
- ```ts
260
- await world.incrementDataObjectValue([`keyAssets.${keyAssetId}.totalItemsCollected.count`], 1);
261
- ```
262
- - **Dropped Asset:** 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!
263
- - **Example - Initialize data object with default data and keyAssetId:**
264
- ```ts
265
- await droppedAsset.setDataObject(
266
- {
267
- ...defaultGameData,
268
- keyAssetId: droppedAsset.id,
269
- },
270
- { lock: { lockId, releaseLock: true } },
271
- );
272
- ```
273
- - **Example - Update lastInteraction date and playerCount:**
274
- ```ts
275
- await droppedAsset.updateDataObject({ lastInteraction: new Date(), playerCount: playerCount + 1 });
276
- ```
277
- - **User:** The User data object should be used to store information unique to a user that is NOT unique to a world or instance (dropped asset) of an app.
278
- - **Example - Update totalMessagesSentCount by a user across all worlds:**
279
- `` js await world.incrementDataObjectValue([`totalMessagesSentCount`], 1); ``
280
- <br/>
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(`keyAssets.${assetId}.completions`, 1, { analytics: [{ analyticName:"completions", incrementBy: 2, profileId, uniqueKey: profileId, urlSlug }] });
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 (incremented by 1) across all instances of your application with a given Public Key.
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