@rtsdk/topia 0.0.23 → 0.0.24
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/LICENSE.md +1 -2
- package/README.md +56 -56
- package/dist/example.js +3 -3
- package/dist/index.js +345 -226
- package/dist/src/__mocks__/scenes.js +1 -1
- package/dist/src/controllers/SDKController.js +1 -1
- package/dist/src/controllers/Scene.js +39 -0
- package/dist/src/controllers/Topia.js +2 -2
- package/dist/src/controllers/User.js +38 -15
- package/dist/src/controllers/Visitor.js +7 -7
- package/dist/src/controllers/World.js +52 -145
- package/dist/src/controllers/WorldActivity.js +160 -0
- package/dist/src/controllers/__tests__/asset.test.js +2 -2
- package/dist/src/controllers/__tests__/droppedAsset.test.js +1 -1
- package/dist/src/controllers/__tests__/scene.test.js +37 -0
- package/dist/src/controllers/__tests__/user.test.js +14 -15
- package/dist/src/controllers/__tests__/visitor.test.js +10 -4
- package/dist/src/controllers/__tests__/world.test.js +2 -34
- package/dist/src/controllers/__tests__/worldActivity.test.js +62 -0
- package/dist/src/controllers/index.js +2 -0
- package/dist/src/factories/SceneFactory.js +27 -0
- package/dist/src/factories/UserFactory.js +2 -2
- package/dist/src/factories/VisitorFactory.js +3 -3
- package/dist/src/factories/WorldActivityFactory.js +10 -0
- package/dist/src/factories/index.js +2 -0
- package/dist/src/index.js +1 -1
- package/dist/src/interfaces/SceneInterfaces.js +1 -0
- package/dist/src/interfaces/WorldActivityInterfaces.js +1 -0
- package/dist/src/interfaces/index.js +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
14
14
|
*
|
|
15
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
16
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
18
|
import require$$0$1 from 'buffer';
|
|
@@ -39763,7 +39762,7 @@ class SDKController {
|
|
|
39763
39762
|
assetId,
|
|
39764
39763
|
};
|
|
39765
39764
|
this.jwt = jwt.sign(payload, topia.interactiveSecret);
|
|
39766
|
-
headers.
|
|
39765
|
+
headers.InteractiveJWT = this.jwt;
|
|
39767
39766
|
}
|
|
39768
39767
|
if (apiKey) {
|
|
39769
39768
|
headers.Authorization = apiKey;
|
|
@@ -40248,74 +40247,24 @@ _DroppedAsset_updateDroppedAsset = new WeakMap();
|
|
|
40248
40247
|
|
|
40249
40248
|
/**
|
|
40250
40249
|
* @summary
|
|
40251
|
-
* Create an instance of
|
|
40250
|
+
* Create an instance of Scene class with a given scene id and optional attributes and session credentials.
|
|
40252
40251
|
*
|
|
40253
40252
|
* @usage
|
|
40254
40253
|
* ```ts
|
|
40255
|
-
* await new
|
|
40254
|
+
* await new Scene(topia, "sceneId", { attributes: { name: "My Scene" } });
|
|
40256
40255
|
* ```
|
|
40257
40256
|
*/
|
|
40258
|
-
class
|
|
40259
|
-
constructor(topia, id,
|
|
40257
|
+
class Scene extends SDKController {
|
|
40258
|
+
constructor(topia, id, options = { attributes: {}, credentials: {} }) {
|
|
40260
40259
|
super(topia, options.credentials);
|
|
40261
|
-
Object.assign(this, options.attributes);
|
|
40262
40260
|
this.id = id;
|
|
40263
|
-
this.
|
|
40264
|
-
}
|
|
40265
|
-
/**
|
|
40266
|
-
* @summary
|
|
40267
|
-
* Get a single visitor from a world
|
|
40268
|
-
*
|
|
40269
|
-
* @usage
|
|
40270
|
-
* ```ts
|
|
40271
|
-
* await visitor.fetchVisitor();
|
|
40272
|
-
* ```
|
|
40273
|
-
*
|
|
40274
|
-
* @result
|
|
40275
|
-
* Updates each Visitor instance and world.visitors map.
|
|
40276
|
-
*/
|
|
40277
|
-
fetchVisitor() {
|
|
40278
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40279
|
-
try {
|
|
40280
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
|
|
40281
|
-
if (response.data.success) {
|
|
40282
|
-
Object.assign(this, response.data).players[0];
|
|
40283
|
-
}
|
|
40284
|
-
else {
|
|
40285
|
-
throw "This visitor is not active";
|
|
40286
|
-
}
|
|
40287
|
-
}
|
|
40288
|
-
catch (error) {
|
|
40289
|
-
throw this.errorHandler({ error });
|
|
40290
|
-
}
|
|
40291
|
-
});
|
|
40261
|
+
Object.assign(this, options.attributes);
|
|
40292
40262
|
}
|
|
40293
|
-
|
|
40294
|
-
* @summary
|
|
40295
|
-
* Teleport or walk a visitor currently in a world to a single set of coordinates.
|
|
40296
|
-
*
|
|
40297
|
-
* @usage
|
|
40298
|
-
* ```ts
|
|
40299
|
-
* await visitor.moveVisitor({
|
|
40300
|
-
* shouldTeleportVisitor: true,
|
|
40301
|
-
* x: 100,
|
|
40302
|
-
* y: 100,
|
|
40303
|
-
* });
|
|
40304
|
-
* ```
|
|
40305
|
-
*
|
|
40306
|
-
* @result
|
|
40307
|
-
* Updates each Visitor instance and world.visitors map.
|
|
40308
|
-
*/
|
|
40309
|
-
moveVisitor({ shouldTeleportVisitor, x, y }) {
|
|
40263
|
+
fetchSceneById() {
|
|
40310
40264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40311
40265
|
try {
|
|
40312
|
-
yield this.topiaPublicApi().
|
|
40313
|
-
|
|
40314
|
-
x,
|
|
40315
|
-
y,
|
|
40316
|
-
},
|
|
40317
|
-
teleport: shouldTeleportVisitor,
|
|
40318
|
-
}, this.requestOptions);
|
|
40266
|
+
const response = yield this.topiaPublicApi().get(`/scenes/${this.id}`, this.requestOptions);
|
|
40267
|
+
Object.assign(this, response.data);
|
|
40319
40268
|
}
|
|
40320
40269
|
catch (error) {
|
|
40321
40270
|
throw this.errorHandler({ error });
|
|
@@ -40351,7 +40300,7 @@ const scatterVisitors = (original, scatterBy) => {
|
|
|
40351
40300
|
return Math.floor(Math.random() * (max - min) + min);
|
|
40352
40301
|
};
|
|
40353
40302
|
|
|
40354
|
-
var _World_droppedAssetsMap
|
|
40303
|
+
var _World_droppedAssetsMap;
|
|
40355
40304
|
/**
|
|
40356
40305
|
* @summary
|
|
40357
40306
|
* Create an instance of World class with a given url slug and optional attributes and session credentials.
|
|
@@ -40365,18 +40314,14 @@ class World extends SDKController {
|
|
|
40365
40314
|
constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
40366
40315
|
super(topia, options.credentials);
|
|
40367
40316
|
_World_droppedAssetsMap.set(this, void 0);
|
|
40368
|
-
_World_visitorsMap.set(this, void 0);
|
|
40369
40317
|
Object.assign(this, options.attributes);
|
|
40370
40318
|
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
40371
|
-
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
40372
40319
|
this.urlSlug = urlSlug;
|
|
40373
40320
|
}
|
|
40374
40321
|
get droppedAssets() {
|
|
40375
40322
|
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
40376
40323
|
}
|
|
40377
|
-
|
|
40378
|
-
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
40379
|
-
}
|
|
40324
|
+
//////// world details
|
|
40380
40325
|
/**
|
|
40381
40326
|
* @summary
|
|
40382
40327
|
* Retrieves details of a world.
|
|
@@ -40387,7 +40332,6 @@ class World extends SDKController {
|
|
|
40387
40332
|
* const { name } = world;
|
|
40388
40333
|
* ```
|
|
40389
40334
|
*/
|
|
40390
|
-
// world details
|
|
40391
40335
|
fetchDetails() {
|
|
40392
40336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40393
40337
|
try {
|
|
@@ -40442,120 +40386,39 @@ class World extends SDKController {
|
|
|
40442
40386
|
}
|
|
40443
40387
|
});
|
|
40444
40388
|
}
|
|
40445
|
-
|
|
40446
|
-
fetchVisitors() {
|
|
40447
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40448
|
-
try {
|
|
40449
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
|
|
40450
|
-
// create temp map and then update private property only once
|
|
40451
|
-
const tempVisitorsMap = {};
|
|
40452
|
-
for (const id in response.data) {
|
|
40453
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
|
|
40454
|
-
attributes: response.data[id],
|
|
40455
|
-
});
|
|
40456
|
-
}
|
|
40457
|
-
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
40458
|
-
}
|
|
40459
|
-
catch (error) {
|
|
40460
|
-
throw this.errorHandler({ error });
|
|
40461
|
-
}
|
|
40462
|
-
});
|
|
40463
|
-
}
|
|
40389
|
+
////////// dropped assets
|
|
40464
40390
|
/**
|
|
40465
40391
|
* @summary
|
|
40466
|
-
* Retrieve all
|
|
40392
|
+
* Retrieve all assets dropped in a world.
|
|
40467
40393
|
*
|
|
40468
40394
|
* @usage
|
|
40469
40395
|
* ```ts
|
|
40470
|
-
*
|
|
40396
|
+
* await world.fetchDroppedAssets();
|
|
40397
|
+
* const assets = world.droppedAssets;
|
|
40471
40398
|
* ```
|
|
40472
40399
|
*/
|
|
40473
|
-
|
|
40400
|
+
fetchDroppedAssets() {
|
|
40474
40401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40475
40402
|
try {
|
|
40476
|
-
yield this.
|
|
40477
|
-
|
|
40403
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
40404
|
+
// create temp map and then update private property only once
|
|
40405
|
+
const tempDroppedAssetsMap = {};
|
|
40406
|
+
for (const index in response.data) {
|
|
40407
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
40408
|
+
tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
|
|
40409
|
+
attributes: response.data[index],
|
|
40410
|
+
});
|
|
40411
|
+
}
|
|
40412
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
40478
40413
|
}
|
|
40479
40414
|
catch (error) {
|
|
40480
|
-
|
|
40415
|
+
throw this.errorHandler({ error });
|
|
40481
40416
|
}
|
|
40482
40417
|
});
|
|
40483
40418
|
}
|
|
40484
40419
|
/**
|
|
40485
40420
|
* @summary
|
|
40486
|
-
*
|
|
40487
|
-
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
40488
|
-
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
40489
|
-
*
|
|
40490
|
-
* @usage
|
|
40491
|
-
* ```ts
|
|
40492
|
-
* await world.moveAllVisitors({
|
|
40493
|
-
* shouldFetchVisitors: true,
|
|
40494
|
-
* shouldTeleportVisitors: true,
|
|
40495
|
-
* scatterVisitorsBy: 40,
|
|
40496
|
-
* x: 100,
|
|
40497
|
-
* y: 100,
|
|
40498
|
-
* });
|
|
40499
|
-
* ```
|
|
40500
|
-
*
|
|
40501
|
-
* @result
|
|
40502
|
-
* Updates each Visitor instance and world.visitors map.
|
|
40503
|
-
*/
|
|
40504
|
-
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
40505
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40506
|
-
if (shouldFetchVisitors)
|
|
40507
|
-
yield this.fetchVisitors();
|
|
40508
|
-
const allPromises = [];
|
|
40509
|
-
if (!this.visitors)
|
|
40510
|
-
return;
|
|
40511
|
-
const objectKeys = Object.keys(this.visitors);
|
|
40512
|
-
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
|
|
40513
|
-
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
40514
|
-
x: scatterVisitors(x, scatterVisitorsBy),
|
|
40515
|
-
y: scatterVisitors(y, scatterVisitorsBy),
|
|
40516
|
-
})));
|
|
40517
|
-
const outcomes = yield Promise.all(allPromises);
|
|
40518
|
-
return outcomes;
|
|
40519
|
-
});
|
|
40520
|
-
}
|
|
40521
|
-
/**
|
|
40522
|
-
* @summary
|
|
40523
|
-
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
40524
|
-
*
|
|
40525
|
-
* @usage
|
|
40526
|
-
* ```ts
|
|
40527
|
-
* const visitorsToMove = [
|
|
40528
|
-
* {
|
|
40529
|
-
* visitorObj: world.visitors["1"],
|
|
40530
|
-
* shouldTeleportVisitor: true,
|
|
40531
|
-
* x: 100,
|
|
40532
|
-
* y: 100
|
|
40533
|
-
* }, {
|
|
40534
|
-
* visitorObj: world.visitors["2"],
|
|
40535
|
-
* shouldTeleportVisitor: false,
|
|
40536
|
-
* x: 100,
|
|
40537
|
-
* y: 100
|
|
40538
|
-
* }
|
|
40539
|
-
* ];
|
|
40540
|
-
* await world.moveVisitors(visitorsToMove);
|
|
40541
|
-
* ```
|
|
40542
|
-
*
|
|
40543
|
-
* @result
|
|
40544
|
-
* Updates each Visitor instance and world.visitors map.
|
|
40545
|
-
*/
|
|
40546
|
-
moveVisitors(visitorsToMove) {
|
|
40547
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40548
|
-
const allPromises = [];
|
|
40549
|
-
visitorsToMove.forEach((v) => {
|
|
40550
|
-
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
40551
|
-
});
|
|
40552
|
-
const outcomes = yield Promise.all(allPromises);
|
|
40553
|
-
return outcomes;
|
|
40554
|
-
});
|
|
40555
|
-
}
|
|
40556
|
-
/**
|
|
40557
|
-
* @summary
|
|
40558
|
-
* Retrieve all assets dropped in a world.
|
|
40421
|
+
* Retrieve all assets dropped in a world matching uniqueName.
|
|
40559
40422
|
*
|
|
40560
40423
|
* @usage
|
|
40561
40424
|
* ```ts
|
|
@@ -40563,20 +40426,18 @@ class World extends SDKController {
|
|
|
40563
40426
|
* const assets = world.droppedAssets;
|
|
40564
40427
|
* ```
|
|
40565
40428
|
*/
|
|
40566
|
-
|
|
40567
|
-
fetchDroppedAssets() {
|
|
40429
|
+
fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
|
|
40568
40430
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40569
40431
|
try {
|
|
40570
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
40432
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
|
|
40571
40433
|
// create temp map and then update private property only once
|
|
40572
|
-
const
|
|
40573
|
-
for (const
|
|
40574
|
-
|
|
40575
|
-
|
|
40576
|
-
|
|
40577
|
-
});
|
|
40434
|
+
const droppedAssets = [];
|
|
40435
|
+
for (const asset of response.data.assets) {
|
|
40436
|
+
droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
|
|
40437
|
+
attributes: asset,
|
|
40438
|
+
}));
|
|
40578
40439
|
}
|
|
40579
|
-
|
|
40440
|
+
return droppedAssets;
|
|
40580
40441
|
}
|
|
40581
40442
|
catch (error) {
|
|
40582
40443
|
throw this.errorHandler({ error });
|
|
@@ -40615,26 +40476,24 @@ class World extends SDKController {
|
|
|
40615
40476
|
}
|
|
40616
40477
|
/**
|
|
40617
40478
|
* @summary
|
|
40618
|
-
*
|
|
40479
|
+
* Drop a scene in a world.
|
|
40619
40480
|
*
|
|
40620
40481
|
* @usage
|
|
40621
40482
|
* ```ts
|
|
40622
|
-
*
|
|
40623
|
-
*
|
|
40624
|
-
* "
|
|
40625
|
-
*
|
|
40626
|
-
*
|
|
40627
|
-
*
|
|
40628
|
-
* "
|
|
40629
|
-
* }
|
|
40630
|
-
* await world.replaceScene(SCENE_ID);
|
|
40483
|
+
* await world.dropScene({
|
|
40484
|
+
* "sceneId": "string",
|
|
40485
|
+
* "position": {
|
|
40486
|
+
* "x": 0,
|
|
40487
|
+
* "y": 0
|
|
40488
|
+
* },
|
|
40489
|
+
* "assetSuffix": "string"
|
|
40490
|
+
* });
|
|
40631
40491
|
* ```
|
|
40632
40492
|
*/
|
|
40633
|
-
|
|
40634
|
-
replaceScene(sceneId) {
|
|
40493
|
+
dropScene({ assetSuffix, position, sceneId, }) {
|
|
40635
40494
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40636
40495
|
try {
|
|
40637
|
-
yield this.topiaPublicApi().
|
|
40496
|
+
yield this.topiaPublicApi().post(`/world/${this.urlSlug}/drop-scene`, { assetSuffix, position, sceneId }, this.requestOptions);
|
|
40638
40497
|
}
|
|
40639
40498
|
catch (error) {
|
|
40640
40499
|
throw this.errorHandler({ error });
|
|
@@ -40643,27 +40502,25 @@ class World extends SDKController {
|
|
|
40643
40502
|
}
|
|
40644
40503
|
/**
|
|
40645
40504
|
* @summary
|
|
40646
|
-
*
|
|
40505
|
+
* Replace the current scene of a world.
|
|
40647
40506
|
*
|
|
40648
40507
|
* @usage
|
|
40649
40508
|
* ```ts
|
|
40650
|
-
*
|
|
40651
|
-
* const
|
|
40509
|
+
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
|
|
40510
|
+
* const style = {
|
|
40511
|
+
* "textColor": "#abc123",
|
|
40512
|
+
* "textFontFamily": "Arial",
|
|
40513
|
+
* "textSize": 40,
|
|
40514
|
+
* "textWeight": "normal",
|
|
40515
|
+
* "textWidth": 200
|
|
40516
|
+
* }
|
|
40517
|
+
* await world.replaceScene(SCENE_ID);
|
|
40652
40518
|
* ```
|
|
40653
40519
|
*/
|
|
40654
|
-
|
|
40655
|
-
fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
|
|
40520
|
+
replaceScene(sceneId) {
|
|
40656
40521
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40657
40522
|
try {
|
|
40658
|
-
|
|
40659
|
-
// create temp map and then update private property only once
|
|
40660
|
-
const droppedAssets = [];
|
|
40661
|
-
for (const asset of response.data.assets) {
|
|
40662
|
-
droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
|
|
40663
|
-
attributes: asset,
|
|
40664
|
-
}));
|
|
40665
|
-
}
|
|
40666
|
-
return droppedAssets;
|
|
40523
|
+
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
|
|
40667
40524
|
}
|
|
40668
40525
|
catch (error) {
|
|
40669
40526
|
throw this.errorHandler({ error });
|
|
@@ -40671,24 +40528,33 @@ class World extends SDKController {
|
|
|
40671
40528
|
});
|
|
40672
40529
|
}
|
|
40673
40530
|
}
|
|
40674
|
-
_World_droppedAssetsMap = new WeakMap()
|
|
40531
|
+
_World_droppedAssetsMap = new WeakMap();
|
|
40675
40532
|
|
|
40676
|
-
var _User_worldsMap;
|
|
40533
|
+
var _User_assetsMap, _User_scenesMap, _User_worldsMap;
|
|
40677
40534
|
/**
|
|
40678
40535
|
* @summary
|
|
40679
|
-
* Create an instance of User class with
|
|
40536
|
+
* Create an instance of User class with optional session credentials.
|
|
40680
40537
|
*
|
|
40681
40538
|
* @usage
|
|
40682
40539
|
* ```ts
|
|
40683
|
-
* await new User(topia,
|
|
40540
|
+
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", playerId: 1 });
|
|
40684
40541
|
* ```
|
|
40685
40542
|
*/
|
|
40686
40543
|
class User extends SDKController {
|
|
40687
|
-
constructor(topia,
|
|
40544
|
+
constructor(topia, options = { credentials: {} }) {
|
|
40688
40545
|
super(topia, options.credentials);
|
|
40546
|
+
_User_assetsMap.set(this, void 0);
|
|
40547
|
+
_User_scenesMap.set(this, void 0);
|
|
40689
40548
|
_User_worldsMap.set(this, void 0);
|
|
40549
|
+
__classPrivateFieldSet(this, _User_assetsMap, {}, "f");
|
|
40550
|
+
__classPrivateFieldSet(this, _User_scenesMap, {}, "f");
|
|
40690
40551
|
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
40691
|
-
|
|
40552
|
+
}
|
|
40553
|
+
get assets() {
|
|
40554
|
+
return __classPrivateFieldGet(this, _User_assetsMap, "f");
|
|
40555
|
+
}
|
|
40556
|
+
get scenes() {
|
|
40557
|
+
return __classPrivateFieldGet(this, _User_scenesMap, "f");
|
|
40692
40558
|
}
|
|
40693
40559
|
get worlds() {
|
|
40694
40560
|
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
@@ -40697,11 +40563,18 @@ class User extends SDKController {
|
|
|
40697
40563
|
* @summary
|
|
40698
40564
|
* Returns all assets owned by User when an email address is provided.
|
|
40699
40565
|
*/
|
|
40700
|
-
|
|
40566
|
+
fetchAssets() {
|
|
40701
40567
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40702
40568
|
try {
|
|
40703
|
-
const response = yield this.topiaPublicApi().get(`/assets/my-assets
|
|
40704
|
-
|
|
40569
|
+
const response = yield this.topiaPublicApi().get(`/assets/my-assets`, this.requestOptions);
|
|
40570
|
+
const tempAssetsMap = {};
|
|
40571
|
+
for (const i in response.data) {
|
|
40572
|
+
const assetDetails = response.data[i];
|
|
40573
|
+
tempAssetsMap[assetDetails.id] = new Asset(this.topia, assetDetails.id, {
|
|
40574
|
+
attributes: assetDetails,
|
|
40575
|
+
});
|
|
40576
|
+
}
|
|
40577
|
+
__classPrivateFieldSet(this, _User_assetsMap, tempAssetsMap, "f");
|
|
40705
40578
|
}
|
|
40706
40579
|
catch (error) {
|
|
40707
40580
|
throw this.errorHandler({ error });
|
|
@@ -40710,15 +40583,20 @@ class User extends SDKController {
|
|
|
40710
40583
|
}
|
|
40711
40584
|
/**
|
|
40712
40585
|
* @summary
|
|
40713
|
-
* Returns all scenes owned by User
|
|
40586
|
+
* Returns all scenes owned by User
|
|
40714
40587
|
*/
|
|
40715
|
-
|
|
40588
|
+
fetchScenes() {
|
|
40716
40589
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40717
40590
|
try {
|
|
40718
|
-
|
|
40719
|
-
|
|
40720
|
-
const
|
|
40721
|
-
|
|
40591
|
+
const response = yield this.topiaPublicApi().get("/scenes/my-scenes", this.requestOptions);
|
|
40592
|
+
const tempScenesMap = {};
|
|
40593
|
+
for (const i in response.data) {
|
|
40594
|
+
const sceneDetails = response.data[i];
|
|
40595
|
+
tempScenesMap[sceneDetails.id] = new Scene(this.topia, sceneDetails.urlSlug, {
|
|
40596
|
+
attributes: sceneDetails,
|
|
40597
|
+
});
|
|
40598
|
+
}
|
|
40599
|
+
__classPrivateFieldSet(this, _User_scenesMap, tempScenesMap, "f");
|
|
40722
40600
|
}
|
|
40723
40601
|
catch (error) {
|
|
40724
40602
|
throw this.errorHandler({ error });
|
|
@@ -40761,7 +40639,222 @@ class User extends SDKController {
|
|
|
40761
40639
|
});
|
|
40762
40640
|
}
|
|
40763
40641
|
}
|
|
40764
|
-
_User_worldsMap = new WeakMap();
|
|
40642
|
+
_User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
|
|
40643
|
+
|
|
40644
|
+
/**
|
|
40645
|
+
* @summary
|
|
40646
|
+
* Create an instance of Visitor class with a given id and optional attributes and session credentials.
|
|
40647
|
+
*
|
|
40648
|
+
* @usage
|
|
40649
|
+
* ```ts
|
|
40650
|
+
* await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
|
|
40651
|
+
* ```
|
|
40652
|
+
*/
|
|
40653
|
+
class Visitor extends User {
|
|
40654
|
+
constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
40655
|
+
super(topia, { credentials: options.credentials });
|
|
40656
|
+
Object.assign(this, options.attributes);
|
|
40657
|
+
this.id = id;
|
|
40658
|
+
this.urlSlug = urlSlug;
|
|
40659
|
+
}
|
|
40660
|
+
/**
|
|
40661
|
+
* @summary
|
|
40662
|
+
* Get a single visitor from a world
|
|
40663
|
+
*
|
|
40664
|
+
* @usage
|
|
40665
|
+
* ```ts
|
|
40666
|
+
* await visitor.fetchVisitor();
|
|
40667
|
+
* ```
|
|
40668
|
+
*
|
|
40669
|
+
* @result
|
|
40670
|
+
* Returns details for a visitor in a world by id and urlSlug
|
|
40671
|
+
*/
|
|
40672
|
+
fetchVisitor() {
|
|
40673
|
+
var _a;
|
|
40674
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40675
|
+
try {
|
|
40676
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
|
|
40677
|
+
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.playerId) === this.id) {
|
|
40678
|
+
Object.assign(this, response.data);
|
|
40679
|
+
}
|
|
40680
|
+
else {
|
|
40681
|
+
throw "This visitor is not active";
|
|
40682
|
+
}
|
|
40683
|
+
}
|
|
40684
|
+
catch (error) {
|
|
40685
|
+
throw this.errorHandler({ error });
|
|
40686
|
+
}
|
|
40687
|
+
});
|
|
40688
|
+
}
|
|
40689
|
+
/**
|
|
40690
|
+
* @summary
|
|
40691
|
+
* Teleport or walk a visitor currently in a world to a single set of coordinates.
|
|
40692
|
+
*
|
|
40693
|
+
* @usage
|
|
40694
|
+
* ```ts
|
|
40695
|
+
* await visitor.moveVisitor({
|
|
40696
|
+
* shouldTeleportVisitor: true,
|
|
40697
|
+
* x: 100,
|
|
40698
|
+
* y: 100,
|
|
40699
|
+
* });
|
|
40700
|
+
* ```
|
|
40701
|
+
*
|
|
40702
|
+
* @result
|
|
40703
|
+
* Updates each Visitor instance and world.visitors map.
|
|
40704
|
+
*/
|
|
40705
|
+
moveVisitor({ shouldTeleportVisitor, x, y }) {
|
|
40706
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40707
|
+
try {
|
|
40708
|
+
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
|
|
40709
|
+
moveTo: {
|
|
40710
|
+
x,
|
|
40711
|
+
y,
|
|
40712
|
+
},
|
|
40713
|
+
teleport: shouldTeleportVisitor,
|
|
40714
|
+
}, this.requestOptions);
|
|
40715
|
+
}
|
|
40716
|
+
catch (error) {
|
|
40717
|
+
throw this.errorHandler({ error });
|
|
40718
|
+
}
|
|
40719
|
+
});
|
|
40720
|
+
}
|
|
40721
|
+
}
|
|
40722
|
+
|
|
40723
|
+
var _WorldActivity_visitorsMap;
|
|
40724
|
+
/**
|
|
40725
|
+
* @summary
|
|
40726
|
+
* Create an instance of WorldActivity class with a given url slug and optional attributes and session credentials.
|
|
40727
|
+
*
|
|
40728
|
+
* This class is responsible for all activity of a specified world including editing dropped assets, moving current visitors, etc.
|
|
40729
|
+
*
|
|
40730
|
+
* @usage
|
|
40731
|
+
* ```ts
|
|
40732
|
+
* await new WorldActivity(topia, "exampleWorld", { attributes: { name: "Example World" } });
|
|
40733
|
+
* ```
|
|
40734
|
+
*/
|
|
40735
|
+
class WorldActivity extends SDKController {
|
|
40736
|
+
constructor(topia, urlSlug, options = { credentials: {} }) {
|
|
40737
|
+
super(topia, options.credentials);
|
|
40738
|
+
_WorldActivity_visitorsMap.set(this, void 0);
|
|
40739
|
+
__classPrivateFieldSet(this, _WorldActivity_visitorsMap, {}, "f");
|
|
40740
|
+
this.urlSlug = urlSlug;
|
|
40741
|
+
}
|
|
40742
|
+
get visitors() {
|
|
40743
|
+
return __classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f");
|
|
40744
|
+
}
|
|
40745
|
+
//////// visitors
|
|
40746
|
+
fetchVisitors() {
|
|
40747
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40748
|
+
try {
|
|
40749
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
|
|
40750
|
+
// create temp map and then update private property only once
|
|
40751
|
+
const tempVisitorsMap = {};
|
|
40752
|
+
for (const id in response.data) {
|
|
40753
|
+
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
|
|
40754
|
+
attributes: response.data[id],
|
|
40755
|
+
});
|
|
40756
|
+
}
|
|
40757
|
+
__classPrivateFieldSet(this, _WorldActivity_visitorsMap, tempVisitorsMap, "f");
|
|
40758
|
+
}
|
|
40759
|
+
catch (error) {
|
|
40760
|
+
throw this.errorHandler({ error });
|
|
40761
|
+
}
|
|
40762
|
+
});
|
|
40763
|
+
}
|
|
40764
|
+
/**
|
|
40765
|
+
* @summary
|
|
40766
|
+
* Retrieve all visitors currently in a world.
|
|
40767
|
+
*
|
|
40768
|
+
* @usage
|
|
40769
|
+
* ```ts
|
|
40770
|
+
* const visitors = await world.currentVisitors();
|
|
40771
|
+
* ```
|
|
40772
|
+
*/
|
|
40773
|
+
currentVisitors() {
|
|
40774
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40775
|
+
try {
|
|
40776
|
+
yield this.fetchVisitors();
|
|
40777
|
+
return this.visitors;
|
|
40778
|
+
}
|
|
40779
|
+
catch (error) {
|
|
40780
|
+
return error;
|
|
40781
|
+
}
|
|
40782
|
+
});
|
|
40783
|
+
}
|
|
40784
|
+
/**
|
|
40785
|
+
* @summary
|
|
40786
|
+
* Move all visitors currently in a world to a single set of coordinates.
|
|
40787
|
+
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
40788
|
+
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
40789
|
+
*
|
|
40790
|
+
* @usage
|
|
40791
|
+
* ```ts
|
|
40792
|
+
* await world.moveAllVisitors({
|
|
40793
|
+
* shouldFetchVisitors: true,
|
|
40794
|
+
* shouldTeleportVisitors: true,
|
|
40795
|
+
* scatterVisitorsBy: 40,
|
|
40796
|
+
* x: 100,
|
|
40797
|
+
* y: 100,
|
|
40798
|
+
* });
|
|
40799
|
+
* ```
|
|
40800
|
+
*
|
|
40801
|
+
* @result
|
|
40802
|
+
* Updates each Visitor instance and world.visitors map.
|
|
40803
|
+
*/
|
|
40804
|
+
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
40805
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40806
|
+
if (shouldFetchVisitors)
|
|
40807
|
+
yield this.fetchVisitors();
|
|
40808
|
+
const allPromises = [];
|
|
40809
|
+
if (!this.visitors)
|
|
40810
|
+
return;
|
|
40811
|
+
const objectKeys = Object.keys(this.visitors);
|
|
40812
|
+
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f")[key].moveVisitor({
|
|
40813
|
+
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
40814
|
+
x: scatterVisitors(x, scatterVisitorsBy),
|
|
40815
|
+
y: scatterVisitors(y, scatterVisitorsBy),
|
|
40816
|
+
})));
|
|
40817
|
+
const outcomes = yield Promise.all(allPromises);
|
|
40818
|
+
return outcomes;
|
|
40819
|
+
});
|
|
40820
|
+
}
|
|
40821
|
+
/**
|
|
40822
|
+
* @summary
|
|
40823
|
+
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
40824
|
+
*
|
|
40825
|
+
* @usage
|
|
40826
|
+
* ```ts
|
|
40827
|
+
* const visitorsToMove = [
|
|
40828
|
+
* {
|
|
40829
|
+
* visitorObj: world.visitors["1"],
|
|
40830
|
+
* shouldTeleportVisitor: true,
|
|
40831
|
+
* x: 100,
|
|
40832
|
+
* y: 100
|
|
40833
|
+
* }, {
|
|
40834
|
+
* visitorObj: world.visitors["2"],
|
|
40835
|
+
* shouldTeleportVisitor: false,
|
|
40836
|
+
* x: 100,
|
|
40837
|
+
* y: 100
|
|
40838
|
+
* }
|
|
40839
|
+
* ];
|
|
40840
|
+
* await world.moveVisitors(visitorsToMove);
|
|
40841
|
+
* ```
|
|
40842
|
+
*
|
|
40843
|
+
* @result
|
|
40844
|
+
* Updates each Visitor instance and world.visitors map.
|
|
40845
|
+
*/
|
|
40846
|
+
moveVisitors(visitorsToMove) {
|
|
40847
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40848
|
+
const allPromises = [];
|
|
40849
|
+
visitorsToMove.forEach((v) => {
|
|
40850
|
+
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
40851
|
+
});
|
|
40852
|
+
const outcomes = yield Promise.all(allPromises);
|
|
40853
|
+
return outcomes;
|
|
40854
|
+
});
|
|
40855
|
+
}
|
|
40856
|
+
}
|
|
40857
|
+
_WorldActivity_visitorsMap = new WeakMap();
|
|
40765
40858
|
|
|
40766
40859
|
/**
|
|
40767
40860
|
* @summary
|
|
@@ -40790,9 +40883,9 @@ class Topia {
|
|
|
40790
40883
|
if (apiKey)
|
|
40791
40884
|
headers.Authorization = apiKey;
|
|
40792
40885
|
if (interactiveKey)
|
|
40793
|
-
headers.
|
|
40886
|
+
headers.PublicKey = interactiveKey;
|
|
40794
40887
|
this.axios = axios.create({
|
|
40795
|
-
baseURL: `https://${this.apiDomain}/api`,
|
|
40888
|
+
baseURL: `https://${this.apiDomain}/api/v1`,
|
|
40796
40889
|
headers,
|
|
40797
40890
|
});
|
|
40798
40891
|
}
|
|
@@ -40840,12 +40933,29 @@ class DroppedAssetFactory extends SDKController {
|
|
|
40840
40933
|
}
|
|
40841
40934
|
}
|
|
40842
40935
|
|
|
40936
|
+
class SceneFactory {
|
|
40937
|
+
constructor(topia) {
|
|
40938
|
+
this.topia = topia;
|
|
40939
|
+
this.create;
|
|
40940
|
+
}
|
|
40941
|
+
create(id, options) {
|
|
40942
|
+
return new Scene(this.topia, id, options);
|
|
40943
|
+
}
|
|
40944
|
+
get(id, options) {
|
|
40945
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40946
|
+
const scene = yield new Scene(this.topia, id, options);
|
|
40947
|
+
yield scene.fetchSceneById();
|
|
40948
|
+
return scene;
|
|
40949
|
+
});
|
|
40950
|
+
}
|
|
40951
|
+
}
|
|
40952
|
+
|
|
40843
40953
|
class UserFactory {
|
|
40844
40954
|
constructor(topia) {
|
|
40845
40955
|
this.topia = topia;
|
|
40846
40956
|
}
|
|
40847
|
-
create(
|
|
40848
|
-
return new User(this.topia,
|
|
40957
|
+
create(options) {
|
|
40958
|
+
return new User(this.topia, options);
|
|
40849
40959
|
}
|
|
40850
40960
|
}
|
|
40851
40961
|
|
|
@@ -40853,6 +40963,9 @@ class VisitorFactory {
|
|
|
40853
40963
|
constructor(topia) {
|
|
40854
40964
|
this.topia = topia;
|
|
40855
40965
|
}
|
|
40966
|
+
create(id, urlSlug, options) {
|
|
40967
|
+
return new Visitor(this.topia, id, urlSlug, options);
|
|
40968
|
+
}
|
|
40856
40969
|
get(id, urlSlug, options) {
|
|
40857
40970
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40858
40971
|
const visitor = new Visitor(this.topia, id, urlSlug, options);
|
|
@@ -40860,8 +40973,14 @@ class VisitorFactory {
|
|
|
40860
40973
|
return visitor;
|
|
40861
40974
|
});
|
|
40862
40975
|
}
|
|
40863
|
-
|
|
40864
|
-
|
|
40976
|
+
}
|
|
40977
|
+
|
|
40978
|
+
class WorldActivityFactory {
|
|
40979
|
+
constructor(topia) {
|
|
40980
|
+
this.topia = topia;
|
|
40981
|
+
}
|
|
40982
|
+
create(urlSlug, options) {
|
|
40983
|
+
return new WorldActivity(this.topia, urlSlug, options);
|
|
40865
40984
|
}
|
|
40866
40985
|
}
|
|
40867
40986
|
|
|
@@ -40896,4 +41015,4 @@ process.on("uncaughtException", function (err) {
|
|
|
40896
41015
|
process.exit(1);
|
|
40897
41016
|
});
|
|
40898
41017
|
|
|
40899
|
-
export { AssetFactory, DroppedAssetFactory, Topia, UserFactory, VisitorFactory, WorldFactory };
|
|
41018
|
+
export { AssetFactory, DroppedAssetFactory, SceneFactory, Topia, UserFactory, VisitorFactory, WorldActivityFactory, WorldFactory };
|