@rtsdk/topia 0.0.23 → 0.0.25
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 +358 -231
- package/dist/src/__mocks__/scenes.js +1 -1
- package/dist/src/controllers/DroppedAsset.js +13 -5
- 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
|
@@ -56,14 +56,24 @@ export class DroppedAsset extends Asset {
|
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
try {
|
|
58
58
|
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions);
|
|
59
|
-
|
|
59
|
+
const droppedAssetDetails = response.data;
|
|
60
|
+
droppedAssetDetails.urlSlug = this.urlSlug;
|
|
61
|
+
Object.assign(this, droppedAssetDetails);
|
|
60
62
|
}
|
|
61
63
|
catch (error) {
|
|
62
64
|
throw this.errorHandler({ error });
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @summary
|
|
70
|
+
* Delete dropped asset.
|
|
71
|
+
*
|
|
72
|
+
* @usage
|
|
73
|
+
* ```ts
|
|
74
|
+
* await droppedAsset.deleteDroppedAsset();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
67
77
|
deleteDroppedAsset() {
|
|
68
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
79
|
try {
|
|
@@ -84,7 +94,6 @@ export class DroppedAsset extends Asset {
|
|
|
84
94
|
* const { dataObject } = droppedAsset;
|
|
85
95
|
* ```
|
|
86
96
|
*/
|
|
87
|
-
// get dropped asset
|
|
88
97
|
fetchDroppedAssetDataObject() {
|
|
89
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
99
|
try {
|
|
@@ -98,7 +107,7 @@ export class DroppedAsset extends Asset {
|
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
100
109
|
* @summary
|
|
101
|
-
*
|
|
110
|
+
* Sets the data object for a dropped asset.
|
|
102
111
|
*
|
|
103
112
|
* Optionally, a lock can be provided with this request to ensure only one update happens at a time between all updates that share the same lock id
|
|
104
113
|
*
|
|
@@ -110,7 +119,6 @@ export class DroppedAsset extends Asset {
|
|
|
110
119
|
* const { dataObject } = droppedAsset;
|
|
111
120
|
* ```
|
|
112
121
|
*/
|
|
113
|
-
// get dropped asset
|
|
114
122
|
setDroppedAssetDataObject(dataObject, options = {}) {
|
|
115
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
124
|
try {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
// controllers
|
|
11
|
+
import { SDKController } from "controllers/SDKController";
|
|
12
|
+
/**
|
|
13
|
+
* @summary
|
|
14
|
+
* Create an instance of Scene class with a given scene id and optional attributes and session credentials.
|
|
15
|
+
*
|
|
16
|
+
* @usage
|
|
17
|
+
* ```ts
|
|
18
|
+
* await new Scene(topia, "sceneId", { attributes: { name: "My Scene" } });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class Scene extends SDKController {
|
|
22
|
+
constructor(topia, id, options = { attributes: {}, credentials: {} }) {
|
|
23
|
+
super(topia, options.credentials);
|
|
24
|
+
this.id = id;
|
|
25
|
+
Object.assign(this, options.attributes);
|
|
26
|
+
}
|
|
27
|
+
fetchSceneById() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
const response = yield this.topiaPublicApi().get(`/scenes/${this.id}`, this.requestOptions);
|
|
31
|
+
Object.assign(this, response.data);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw this.errorHandler({ error });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export default Scene;
|
|
@@ -28,9 +28,9 @@ export class Topia {
|
|
|
28
28
|
if (apiKey)
|
|
29
29
|
headers.Authorization = apiKey;
|
|
30
30
|
if (interactiveKey)
|
|
31
|
-
headers.
|
|
31
|
+
headers.PublicKey = interactiveKey;
|
|
32
32
|
this.axios = axios.create({
|
|
33
|
-
baseURL: `https://${this.apiDomain}/api`,
|
|
33
|
+
baseURL: `https://${this.apiDomain}/api/v1`,
|
|
34
34
|
headers,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
@@ -18,25 +18,36 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
20
|
};
|
|
21
|
-
var _User_worldsMap;
|
|
21
|
+
var _User_assetsMap, _User_scenesMap, _User_worldsMap;
|
|
22
22
|
// controllers
|
|
23
|
+
import { Asset } from "controllers/Asset";
|
|
24
|
+
import { Scene } from "controllers/Scene";
|
|
23
25
|
import { SDKController } from "controllers/SDKController";
|
|
24
26
|
import { World } from "controllers/World";
|
|
25
27
|
/**
|
|
26
28
|
* @summary
|
|
27
|
-
* Create an instance of User class with
|
|
29
|
+
* Create an instance of User class with optional session credentials.
|
|
28
30
|
*
|
|
29
31
|
* @usage
|
|
30
32
|
* ```ts
|
|
31
|
-
* await new User(topia,
|
|
33
|
+
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", playerId: 1 });
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
34
36
|
export class User extends SDKController {
|
|
35
|
-
constructor(topia,
|
|
37
|
+
constructor(topia, options = { credentials: {} }) {
|
|
36
38
|
super(topia, options.credentials);
|
|
39
|
+
_User_assetsMap.set(this, void 0);
|
|
40
|
+
_User_scenesMap.set(this, void 0);
|
|
37
41
|
_User_worldsMap.set(this, void 0);
|
|
42
|
+
__classPrivateFieldSet(this, _User_assetsMap, {}, "f");
|
|
43
|
+
__classPrivateFieldSet(this, _User_scenesMap, {}, "f");
|
|
38
44
|
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
39
|
-
|
|
45
|
+
}
|
|
46
|
+
get assets() {
|
|
47
|
+
return __classPrivateFieldGet(this, _User_assetsMap, "f");
|
|
48
|
+
}
|
|
49
|
+
get scenes() {
|
|
50
|
+
return __classPrivateFieldGet(this, _User_scenesMap, "f");
|
|
40
51
|
}
|
|
41
52
|
get worlds() {
|
|
42
53
|
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
@@ -45,11 +56,18 @@ export class User extends SDKController {
|
|
|
45
56
|
* @summary
|
|
46
57
|
* Returns all assets owned by User when an email address is provided.
|
|
47
58
|
*/
|
|
48
|
-
|
|
59
|
+
fetchAssets() {
|
|
49
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
61
|
try {
|
|
51
|
-
const response = yield this.topiaPublicApi().get(`/assets/my-assets
|
|
52
|
-
|
|
62
|
+
const response = yield this.topiaPublicApi().get(`/assets/my-assets`, this.requestOptions);
|
|
63
|
+
const tempAssetsMap = {};
|
|
64
|
+
for (const i in response.data) {
|
|
65
|
+
const assetDetails = response.data[i];
|
|
66
|
+
tempAssetsMap[assetDetails.id] = new Asset(this.topia, assetDetails.id, {
|
|
67
|
+
attributes: assetDetails,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
__classPrivateFieldSet(this, _User_assetsMap, tempAssetsMap, "f");
|
|
53
71
|
}
|
|
54
72
|
catch (error) {
|
|
55
73
|
throw this.errorHandler({ error });
|
|
@@ -58,15 +76,20 @@ export class User extends SDKController {
|
|
|
58
76
|
}
|
|
59
77
|
/**
|
|
60
78
|
* @summary
|
|
61
|
-
* Returns all scenes owned by User
|
|
79
|
+
* Returns all scenes owned by User
|
|
62
80
|
*/
|
|
63
|
-
|
|
81
|
+
fetchScenes() {
|
|
64
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
83
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
84
|
+
const response = yield this.topiaPublicApi().get("/scenes/my-scenes", this.requestOptions);
|
|
85
|
+
const tempScenesMap = {};
|
|
86
|
+
for (const i in response.data) {
|
|
87
|
+
const sceneDetails = response.data[i];
|
|
88
|
+
tempScenesMap[sceneDetails.id] = new Scene(this.topia, sceneDetails.urlSlug, {
|
|
89
|
+
attributes: sceneDetails,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
__classPrivateFieldSet(this, _User_scenesMap, tempScenesMap, "f");
|
|
70
93
|
}
|
|
71
94
|
catch (error) {
|
|
72
95
|
throw this.errorHandler({ error });
|
|
@@ -109,5 +132,5 @@ export class User extends SDKController {
|
|
|
109
132
|
});
|
|
110
133
|
}
|
|
111
134
|
}
|
|
112
|
-
_User_worldsMap = new WeakMap();
|
|
135
|
+
_User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
|
|
113
136
|
export default User;
|
|
@@ -7,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
import { SDKController } from "controllers/SDKController";
|
|
10
|
+
import { User } from "controllers/User";
|
|
12
11
|
/**
|
|
13
12
|
* @summary
|
|
14
13
|
* Create an instance of Visitor class with a given id and optional attributes and session credentials.
|
|
@@ -18,9 +17,9 @@ import { SDKController } from "controllers/SDKController";
|
|
|
18
17
|
* await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
|
|
19
18
|
* ```
|
|
20
19
|
*/
|
|
21
|
-
export class Visitor extends
|
|
20
|
+
export class Visitor extends User {
|
|
22
21
|
constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
23
|
-
super(topia, options.credentials);
|
|
22
|
+
super(topia, { credentials: options.credentials });
|
|
24
23
|
Object.assign(this, options.attributes);
|
|
25
24
|
this.id = id;
|
|
26
25
|
this.urlSlug = urlSlug;
|
|
@@ -35,14 +34,15 @@ export class Visitor extends SDKController {
|
|
|
35
34
|
* ```
|
|
36
35
|
*
|
|
37
36
|
* @result
|
|
38
|
-
*
|
|
37
|
+
* Returns details for a visitor in a world by id and urlSlug
|
|
39
38
|
*/
|
|
40
39
|
fetchVisitor() {
|
|
40
|
+
var _a;
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
try {
|
|
43
43
|
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
|
|
44
|
-
if (response.data.
|
|
45
|
-
Object.assign(this, response.data)
|
|
44
|
+
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.playerId) === this.id) {
|
|
45
|
+
Object.assign(this, response.data);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
throw "This visitor is not active";
|
|
@@ -18,13 +18,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
20
|
};
|
|
21
|
-
var _World_droppedAssetsMap
|
|
21
|
+
var _World_droppedAssetsMap;
|
|
22
22
|
// controllers
|
|
23
23
|
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
24
24
|
import { SDKController } from "controllers/SDKController";
|
|
25
|
-
import { Visitor } from "controllers/Visitor";
|
|
26
25
|
// utils
|
|
27
|
-
import { removeUndefined
|
|
26
|
+
import { removeUndefined } from "utils";
|
|
28
27
|
/**
|
|
29
28
|
* @summary
|
|
30
29
|
* Create an instance of World class with a given url slug and optional attributes and session credentials.
|
|
@@ -38,18 +37,14 @@ export class World extends SDKController {
|
|
|
38
37
|
constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
39
38
|
super(topia, options.credentials);
|
|
40
39
|
_World_droppedAssetsMap.set(this, void 0);
|
|
41
|
-
_World_visitorsMap.set(this, void 0);
|
|
42
40
|
Object.assign(this, options.attributes);
|
|
43
41
|
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
44
|
-
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
45
42
|
this.urlSlug = urlSlug;
|
|
46
43
|
}
|
|
47
44
|
get droppedAssets() {
|
|
48
45
|
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
52
|
-
}
|
|
47
|
+
//////// world details
|
|
53
48
|
/**
|
|
54
49
|
* @summary
|
|
55
50
|
* Retrieves details of a world.
|
|
@@ -60,7 +55,6 @@ export class World extends SDKController {
|
|
|
60
55
|
* const { name } = world;
|
|
61
56
|
* ```
|
|
62
57
|
*/
|
|
63
|
-
// world details
|
|
64
58
|
fetchDetails() {
|
|
65
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
60
|
try {
|
|
@@ -115,120 +109,39 @@ export class World extends SDKController {
|
|
|
115
109
|
}
|
|
116
110
|
});
|
|
117
111
|
}
|
|
118
|
-
|
|
119
|
-
fetchVisitors() {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
try {
|
|
122
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
|
|
123
|
-
// create temp map and then update private property only once
|
|
124
|
-
const tempVisitorsMap = {};
|
|
125
|
-
for (const id in response.data) {
|
|
126
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
|
|
127
|
-
attributes: response.data[id],
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
throw this.errorHandler({ error });
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
112
|
+
////////// dropped assets
|
|
137
113
|
/**
|
|
138
114
|
* @summary
|
|
139
|
-
* Retrieve all
|
|
115
|
+
* Retrieve all assets dropped in a world.
|
|
140
116
|
*
|
|
141
117
|
* @usage
|
|
142
118
|
* ```ts
|
|
143
|
-
*
|
|
119
|
+
* await world.fetchDroppedAssets();
|
|
120
|
+
* const assets = world.droppedAssets;
|
|
144
121
|
* ```
|
|
145
122
|
*/
|
|
146
|
-
|
|
123
|
+
fetchDroppedAssets() {
|
|
147
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
125
|
try {
|
|
149
|
-
yield this.
|
|
150
|
-
|
|
126
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
127
|
+
// create temp map and then update private property only once
|
|
128
|
+
const tempDroppedAssetsMap = {};
|
|
129
|
+
for (const index in response.data) {
|
|
130
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
131
|
+
tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
|
|
132
|
+
attributes: response.data[index],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
151
136
|
}
|
|
152
137
|
catch (error) {
|
|
153
|
-
|
|
138
|
+
throw this.errorHandler({ error });
|
|
154
139
|
}
|
|
155
140
|
});
|
|
156
141
|
}
|
|
157
142
|
/**
|
|
158
143
|
* @summary
|
|
159
|
-
*
|
|
160
|
-
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
161
|
-
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
162
|
-
*
|
|
163
|
-
* @usage
|
|
164
|
-
* ```ts
|
|
165
|
-
* await world.moveAllVisitors({
|
|
166
|
-
* shouldFetchVisitors: true,
|
|
167
|
-
* shouldTeleportVisitors: true,
|
|
168
|
-
* scatterVisitorsBy: 40,
|
|
169
|
-
* x: 100,
|
|
170
|
-
* y: 100,
|
|
171
|
-
* });
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
* @result
|
|
175
|
-
* Updates each Visitor instance and world.visitors map.
|
|
176
|
-
*/
|
|
177
|
-
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
178
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
if (shouldFetchVisitors)
|
|
180
|
-
yield this.fetchVisitors();
|
|
181
|
-
const allPromises = [];
|
|
182
|
-
if (!this.visitors)
|
|
183
|
-
return;
|
|
184
|
-
const objectKeys = Object.keys(this.visitors);
|
|
185
|
-
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
|
|
186
|
-
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
187
|
-
x: scatterVisitors(x, scatterVisitorsBy),
|
|
188
|
-
y: scatterVisitors(y, scatterVisitorsBy),
|
|
189
|
-
})));
|
|
190
|
-
const outcomes = yield Promise.all(allPromises);
|
|
191
|
-
return outcomes;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* @summary
|
|
196
|
-
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
197
|
-
*
|
|
198
|
-
* @usage
|
|
199
|
-
* ```ts
|
|
200
|
-
* const visitorsToMove = [
|
|
201
|
-
* {
|
|
202
|
-
* visitorObj: world.visitors["1"],
|
|
203
|
-
* shouldTeleportVisitor: true,
|
|
204
|
-
* x: 100,
|
|
205
|
-
* y: 100
|
|
206
|
-
* }, {
|
|
207
|
-
* visitorObj: world.visitors["2"],
|
|
208
|
-
* shouldTeleportVisitor: false,
|
|
209
|
-
* x: 100,
|
|
210
|
-
* y: 100
|
|
211
|
-
* }
|
|
212
|
-
* ];
|
|
213
|
-
* await world.moveVisitors(visitorsToMove);
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @result
|
|
217
|
-
* Updates each Visitor instance and world.visitors map.
|
|
218
|
-
*/
|
|
219
|
-
moveVisitors(visitorsToMove) {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
const allPromises = [];
|
|
222
|
-
visitorsToMove.forEach((v) => {
|
|
223
|
-
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
224
|
-
});
|
|
225
|
-
const outcomes = yield Promise.all(allPromises);
|
|
226
|
-
return outcomes;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* @summary
|
|
231
|
-
* Retrieve all assets dropped in a world.
|
|
144
|
+
* Retrieve all assets dropped in a world matching uniqueName.
|
|
232
145
|
*
|
|
233
146
|
* @usage
|
|
234
147
|
* ```ts
|
|
@@ -236,20 +149,18 @@ export class World extends SDKController {
|
|
|
236
149
|
* const assets = world.droppedAssets;
|
|
237
150
|
* ```
|
|
238
151
|
*/
|
|
239
|
-
|
|
240
|
-
fetchDroppedAssets() {
|
|
152
|
+
fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
|
|
241
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
154
|
try {
|
|
243
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
155
|
+
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
|
|
244
156
|
// create temp map and then update private property only once
|
|
245
|
-
const
|
|
246
|
-
for (const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
157
|
+
const droppedAssets = [];
|
|
158
|
+
for (const asset of response.data.assets) {
|
|
159
|
+
droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
|
|
160
|
+
attributes: asset,
|
|
161
|
+
}));
|
|
251
162
|
}
|
|
252
|
-
|
|
163
|
+
return droppedAssets;
|
|
253
164
|
}
|
|
254
165
|
catch (error) {
|
|
255
166
|
throw this.errorHandler({ error });
|
|
@@ -288,26 +199,24 @@ export class World extends SDKController {
|
|
|
288
199
|
}
|
|
289
200
|
/**
|
|
290
201
|
* @summary
|
|
291
|
-
*
|
|
202
|
+
* Drop a scene in a world.
|
|
292
203
|
*
|
|
293
204
|
* @usage
|
|
294
205
|
* ```ts
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* "
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* "
|
|
302
|
-
* }
|
|
303
|
-
* await world.replaceScene(SCENE_ID);
|
|
206
|
+
* await world.dropScene({
|
|
207
|
+
* "sceneId": "string",
|
|
208
|
+
* "position": {
|
|
209
|
+
* "x": 0,
|
|
210
|
+
* "y": 0
|
|
211
|
+
* },
|
|
212
|
+
* "assetSuffix": "string"
|
|
213
|
+
* });
|
|
304
214
|
* ```
|
|
305
215
|
*/
|
|
306
|
-
|
|
307
|
-
replaceScene(sceneId) {
|
|
216
|
+
dropScene({ assetSuffix, position, sceneId, }) {
|
|
308
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
218
|
try {
|
|
310
|
-
yield this.topiaPublicApi().
|
|
219
|
+
yield this.topiaPublicApi().post(`/world/${this.urlSlug}/drop-scene`, { assetSuffix, position, sceneId }, this.requestOptions);
|
|
311
220
|
}
|
|
312
221
|
catch (error) {
|
|
313
222
|
throw this.errorHandler({ error });
|
|
@@ -316,27 +225,25 @@ export class World extends SDKController {
|
|
|
316
225
|
}
|
|
317
226
|
/**
|
|
318
227
|
* @summary
|
|
319
|
-
*
|
|
228
|
+
* Replace the current scene of a world.
|
|
320
229
|
*
|
|
321
230
|
* @usage
|
|
322
231
|
* ```ts
|
|
323
|
-
*
|
|
324
|
-
* const
|
|
232
|
+
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
|
|
233
|
+
* const style = {
|
|
234
|
+
* "textColor": "#abc123",
|
|
235
|
+
* "textFontFamily": "Arial",
|
|
236
|
+
* "textSize": 40,
|
|
237
|
+
* "textWeight": "normal",
|
|
238
|
+
* "textWidth": 200
|
|
239
|
+
* }
|
|
240
|
+
* await world.replaceScene(SCENE_ID);
|
|
325
241
|
* ```
|
|
326
242
|
*/
|
|
327
|
-
|
|
328
|
-
fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
|
|
243
|
+
replaceScene(sceneId) {
|
|
329
244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
245
|
try {
|
|
331
|
-
|
|
332
|
-
// create temp map and then update private property only once
|
|
333
|
-
const droppedAssets = [];
|
|
334
|
-
for (const asset of response.data.assets) {
|
|
335
|
-
droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
|
|
336
|
-
attributes: asset,
|
|
337
|
-
}));
|
|
338
|
-
}
|
|
339
|
-
return droppedAssets;
|
|
246
|
+
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
|
|
340
247
|
}
|
|
341
248
|
catch (error) {
|
|
342
249
|
throw this.errorHandler({ error });
|
|
@@ -344,5 +251,5 @@ export class World extends SDKController {
|
|
|
344
251
|
});
|
|
345
252
|
}
|
|
346
253
|
}
|
|
347
|
-
_World_droppedAssetsMap = new WeakMap()
|
|
254
|
+
_World_droppedAssetsMap = new WeakMap();
|
|
348
255
|
export default World;
|