@series-inc/venus-sdk 3.4.2 → 3.4.3-beta.0
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/dist/{AdsApi-ihIIoDSK.d.ts → AdsApi-Dt9Yx0qb.d.ts} +30 -2
- package/dist/SandboxHost-JNX5UBGL.js +1889 -0
- package/dist/SandboxHost-JNX5UBGL.js.map +1 -0
- package/dist/chunk-DJ3WT3FA.js +1890 -0
- package/dist/chunk-DJ3WT3FA.js.map +1 -0
- package/dist/{chunk-W74ZI2H3.js → chunk-Q7SNANYR.js} +67 -1872
- package/dist/chunk-Q7SNANYR.js.map +1 -0
- package/dist/index.d.ts +31 -4
- package/dist/index.js +2 -1
- package/dist/venus-api/index.d.ts +2 -2
- package/dist/venus-api/index.js +44 -29
- package/dist/venus-api/index.js.map +1 -1
- package/dist/vite/index.css +19 -0
- package/dist/vite/index.css.map +1 -0
- package/dist/vite/index.d.ts +100 -1
- package/dist/vite/index.js +1165 -3
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-W74ZI2H3.js.map +0 -1
|
@@ -0,0 +1,1890 @@
|
|
|
1
|
+
import { RpcAdsApi, RpcAnalyticsApi, RpcStorageApi, RpcAvatarApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, HostProfileApi, HostDeviceApi, HostEnvironmentApi, HostSystemApi, HostCdnApi, HostTimeApi, RpcAiApi, RpcHapticsApi, RpcFeaturesApi, RpcLifecycleApi, RpcRoomsApi, RpcLoggingApi, RpcIapApi, RpcPreloaderApi, RpcSharedAssetsApi, initializeRoomsApi, isSandboxEnabled, MockAdsApi, MockLifecycleApi, MockAnalyticsApi, createMockStorageApi, MockAvatarApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockProfileApi, MockDeviceApi, MockEnvironmentApi, MockSystemApi, MockCdnApi, MockTimeApi, MockAiApi, MockHapticsApi, MockFeaturesApi, MockLoggingApi, MockIapApi, MockSocialApi, MockPreloaderApi, MockSharedAssetsApi } from './chunk-Q7SNANYR.js';
|
|
2
|
+
|
|
3
|
+
// src/utils/idGenerator.ts
|
|
4
|
+
function generateId() {
|
|
5
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/rpc/RpcClient.ts
|
|
9
|
+
var RpcClient = class {
|
|
10
|
+
pendingCalls = /* @__PURE__ */ new Map();
|
|
11
|
+
notificationCallbacks = /* @__PURE__ */ new Map();
|
|
12
|
+
onResponseSub = null;
|
|
13
|
+
onNotificationSub = null;
|
|
14
|
+
transport = null;
|
|
15
|
+
start(transport) {
|
|
16
|
+
this.transport = transport;
|
|
17
|
+
this.onResponseSub = transport.onResponse(async (response) => {
|
|
18
|
+
return this.handleRpcResponse(response);
|
|
19
|
+
});
|
|
20
|
+
this.onNotificationSub = transport.onNotification(async (notification) => {
|
|
21
|
+
return this.handleRpcNotification(notification);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
stop() {
|
|
25
|
+
if (this.onResponseSub) {
|
|
26
|
+
this.onResponseSub.unsubscribe();
|
|
27
|
+
this.onResponseSub = null;
|
|
28
|
+
}
|
|
29
|
+
if (this.onNotificationSub) {
|
|
30
|
+
this.onNotificationSub.unsubscribe();
|
|
31
|
+
this.onNotificationSub = null;
|
|
32
|
+
}
|
|
33
|
+
this.transport = null;
|
|
34
|
+
}
|
|
35
|
+
onNotification(id, callback) {
|
|
36
|
+
this.notificationCallbacks.set(id, callback);
|
|
37
|
+
return {
|
|
38
|
+
unsubscribe: () => {
|
|
39
|
+
this.notificationCallbacks.delete(id);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
callT(method, args, timeout = 5e3) {
|
|
44
|
+
return this.call(method, args, timeout);
|
|
45
|
+
}
|
|
46
|
+
async call(method, args, timeout = 5e3) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const id = generateId();
|
|
49
|
+
this.addPendingCall(id, resolve, reject);
|
|
50
|
+
const request = {
|
|
51
|
+
type: "rpc-request",
|
|
52
|
+
id,
|
|
53
|
+
method,
|
|
54
|
+
args
|
|
55
|
+
};
|
|
56
|
+
if (this.transport) {
|
|
57
|
+
this.transport.sendRequest(request);
|
|
58
|
+
}
|
|
59
|
+
if (timeout > 0) {
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
if (this.hasPendingCall(id)) {
|
|
62
|
+
this.removePendingCall(id);
|
|
63
|
+
reject(new Error(`RPC call ${method} timed out`));
|
|
64
|
+
}
|
|
65
|
+
}, timeout);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
hasPendingCall(id) {
|
|
70
|
+
return this.pendingCalls.has(id);
|
|
71
|
+
}
|
|
72
|
+
addPendingCall(id, resolve, reject) {
|
|
73
|
+
this.pendingCalls.set(id, {
|
|
74
|
+
id,
|
|
75
|
+
resolve,
|
|
76
|
+
reject
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
removePendingCall(id) {
|
|
80
|
+
this.pendingCalls.delete(id);
|
|
81
|
+
}
|
|
82
|
+
getPendingCall(id) {
|
|
83
|
+
return this.pendingCalls.get(id);
|
|
84
|
+
}
|
|
85
|
+
handleRpcResponse(response) {
|
|
86
|
+
const pending = this.getPendingCall(response.id);
|
|
87
|
+
if (!pending) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
this.removePendingCall(response.id);
|
|
91
|
+
if (response.error) {
|
|
92
|
+
pending.reject(new Error(response.error.message));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
pending.resolve(response.result);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
handleRpcNotification(notification) {
|
|
99
|
+
const callback = this.notificationCallbacks.get(notification.id);
|
|
100
|
+
if (callback) {
|
|
101
|
+
callback(notification.payload);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/simulation/RpcSimulationApi.ts
|
|
107
|
+
var RpcSimulationApi = class {
|
|
108
|
+
rpcClient;
|
|
109
|
+
_simulationConfig = null;
|
|
110
|
+
subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
111
|
+
constructor(rpcClient) {
|
|
112
|
+
this.rpcClient = rpcClient;
|
|
113
|
+
this.rpcClient.onNotification(
|
|
114
|
+
"H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */,
|
|
115
|
+
this.handleSimulationUpdate.bind(this)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
isEnabled() {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
122
|
+
return this.rpcClient.call(
|
|
123
|
+
"H5_SIMULATION_VALIDATE_ASSIGNMENT" /* H5_SIMULATION_VALIDATE_ASSIGNMENT */,
|
|
124
|
+
{
|
|
125
|
+
containerId,
|
|
126
|
+
slotId,
|
|
127
|
+
itemId
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
async subscribeAsync(options) {
|
|
132
|
+
this.ensureValidSubscribeOptions(options);
|
|
133
|
+
const subscriptionId = generateId();
|
|
134
|
+
this.subscriptionCallbacks.set(subscriptionId, options.onUpdate);
|
|
135
|
+
try {
|
|
136
|
+
await this.rpcClient.call("H5_SIMULATION_SUBSCRIBE" /* H5_SIMULATION_SUBSCRIBE */, {
|
|
137
|
+
subscriptionId,
|
|
138
|
+
entities: options.entities,
|
|
139
|
+
tags: options.tags,
|
|
140
|
+
activeRuns: options.activeRuns,
|
|
141
|
+
roomId: options.roomId
|
|
142
|
+
});
|
|
143
|
+
} catch (error) {
|
|
144
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
let unsubscribed = false;
|
|
148
|
+
return () => {
|
|
149
|
+
if (unsubscribed) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
unsubscribed = true;
|
|
153
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
154
|
+
void this.rpcClient.call("H5_SIMULATION_UNSUBSCRIBE" /* H5_SIMULATION_UNSUBSCRIBE */, {
|
|
155
|
+
subscriptionId
|
|
156
|
+
}).catch((error) => {
|
|
157
|
+
console.error(
|
|
158
|
+
"[Venus SDK] Failed to unsubscribe simulation listener",
|
|
159
|
+
error
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
executeBatchOperationsAsync(operations, validateOnly) {
|
|
165
|
+
return this.rpcClient.call(
|
|
166
|
+
"H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */,
|
|
167
|
+
{
|
|
168
|
+
operations,
|
|
169
|
+
validateOnly
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
async getAvailableItemsAsync(containerId, slotId) {
|
|
174
|
+
const response = await this.rpcClient.call(
|
|
175
|
+
"H5_SIMULATION_GET_AVAILABLE_ITEMS" /* H5_SIMULATION_GET_AVAILABLE_ITEMS */,
|
|
176
|
+
{
|
|
177
|
+
containerId,
|
|
178
|
+
slotId
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
return response.availableItems || [];
|
|
182
|
+
}
|
|
183
|
+
calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
184
|
+
return this.rpcClient.call(
|
|
185
|
+
"H5_SIMULATION_CALCULATE_POWER_PREVIEW" /* H5_SIMULATION_CALCULATE_POWER_PREVIEW */,
|
|
186
|
+
{
|
|
187
|
+
containerId,
|
|
188
|
+
slotId,
|
|
189
|
+
candidateItemId
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
194
|
+
return this.rpcClient.call(
|
|
195
|
+
"H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */,
|
|
196
|
+
{
|
|
197
|
+
containerId,
|
|
198
|
+
slotId,
|
|
199
|
+
itemId
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
removeItemFromSlotAsync(containerId, slotId) {
|
|
204
|
+
return this.rpcClient.call(
|
|
205
|
+
"H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */,
|
|
206
|
+
{
|
|
207
|
+
containerId,
|
|
208
|
+
slotId
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
async getSlotContainersAsync() {
|
|
213
|
+
const response = await this.rpcClient.call(
|
|
214
|
+
"H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
|
|
215
|
+
{}
|
|
216
|
+
);
|
|
217
|
+
return response.containers || [];
|
|
218
|
+
}
|
|
219
|
+
async getSlotAssignmentsAsync(containerId) {
|
|
220
|
+
const response = await this.rpcClient.call(
|
|
221
|
+
"H5_SIMULATION_GET_ASSIGNMENTS" /* H5_SIMULATION_GET_ASSIGNMENTS */,
|
|
222
|
+
{
|
|
223
|
+
containerId
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
return Array.isArray(response) ? response : response.assignments || [];
|
|
227
|
+
}
|
|
228
|
+
async getStateAsync(roomId) {
|
|
229
|
+
const response = await this.rpcClient.call(
|
|
230
|
+
"H5_SIMULATION_GET_STATE" /* H5_SIMULATION_GET_STATE */,
|
|
231
|
+
{
|
|
232
|
+
roomId
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
if (response.configuration) {
|
|
236
|
+
this._simulationConfig = response.configuration;
|
|
237
|
+
}
|
|
238
|
+
return response;
|
|
239
|
+
}
|
|
240
|
+
async getConfigAsync(roomId) {
|
|
241
|
+
if (this._simulationConfig) {
|
|
242
|
+
return this._simulationConfig;
|
|
243
|
+
}
|
|
244
|
+
const config = await this.rpcClient.call(
|
|
245
|
+
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
246
|
+
{
|
|
247
|
+
roomId
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
if (config) {
|
|
251
|
+
this._simulationConfig = config;
|
|
252
|
+
return config;
|
|
253
|
+
}
|
|
254
|
+
throw new Error("No simulation configuration available");
|
|
255
|
+
}
|
|
256
|
+
executeRecipeAsync(recipeId, inputs, options) {
|
|
257
|
+
return this.rpcClient.call(
|
|
258
|
+
"H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */,
|
|
259
|
+
{
|
|
260
|
+
recipeId,
|
|
261
|
+
inputs,
|
|
262
|
+
roomId: options?.roomId,
|
|
263
|
+
batchAmount: options?.batchAmount,
|
|
264
|
+
allowPartialBatch: options?.allowPartialBatch,
|
|
265
|
+
entity: options?.entity
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
collectRecipeAsync(runId) {
|
|
270
|
+
return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
|
|
271
|
+
runId
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
getActiveRunsAsync(options) {
|
|
275
|
+
return this.rpcClient.call(
|
|
276
|
+
"H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
|
|
277
|
+
{
|
|
278
|
+
roomId: options?.roomId
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
283
|
+
return this.rpcClient.call(
|
|
284
|
+
"H5_SIMULATION_EXECUTE_SCOPED_RECIPE" /* H5_SIMULATION_EXECUTE_SCOPED_RECIPE */,
|
|
285
|
+
{
|
|
286
|
+
recipeId,
|
|
287
|
+
entity,
|
|
288
|
+
inputs,
|
|
289
|
+
roomId: options?.roomId ?? null,
|
|
290
|
+
options
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
getAvailableRecipesAsync(options) {
|
|
295
|
+
return this.rpcClient.call(
|
|
296
|
+
"H5_SIMULATION_GET_AVAILABLE_RECIPES" /* H5_SIMULATION_GET_AVAILABLE_RECIPES */,
|
|
297
|
+
{
|
|
298
|
+
roomId: options?.roomId || null,
|
|
299
|
+
includeActorRecipes: options?.includeActorRecipes || false
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
getRecipeRequirementsAsync(recipe) {
|
|
304
|
+
return this.rpcClient.call(
|
|
305
|
+
"H5_SIMULATION_GET_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_RECIPE_REQUIREMENTS */,
|
|
306
|
+
{
|
|
307
|
+
recipeId: recipe.recipeId,
|
|
308
|
+
entity: recipe.entity,
|
|
309
|
+
batchAmount: recipe.batchAmount
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
getBatchRecipeRequirementsAsync(recipes) {
|
|
314
|
+
return this.rpcClient.call(
|
|
315
|
+
"H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS */,
|
|
316
|
+
{
|
|
317
|
+
recipes
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
triggerRecipeChainAsync(recipeId, options) {
|
|
322
|
+
return this.rpcClient.call(
|
|
323
|
+
"H5_SIMULATION_TRIGGER_RECIPE_CHAIN" /* H5_SIMULATION_TRIGGER_RECIPE_CHAIN */,
|
|
324
|
+
{
|
|
325
|
+
triggerRecipeId: recipeId,
|
|
326
|
+
context: options?.context,
|
|
327
|
+
roomId: options?.roomId
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
getEntityMetadataAsync(entityId) {
|
|
332
|
+
return this.rpcClient.call(
|
|
333
|
+
"H5_SIMULATION_GET_ENTITY_METADATA" /* H5_SIMULATION_GET_ENTITY_METADATA */,
|
|
334
|
+
{
|
|
335
|
+
entityId
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
340
|
+
const response = await this.rpcClient.call(
|
|
341
|
+
"H5_SIMULATION_RESOLVE_VALUE" /* H5_SIMULATION_RESOLVE_VALUE */,
|
|
342
|
+
{
|
|
343
|
+
entityId,
|
|
344
|
+
fieldPath,
|
|
345
|
+
entity
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
return response.value;
|
|
349
|
+
}
|
|
350
|
+
handleSimulationUpdate(notification) {
|
|
351
|
+
if (!notification || !notification.subscriptionId) {
|
|
352
|
+
console.warn("[Venus SDK] Received malformed simulation update");
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const callback = this.subscriptionCallbacks.get(notification.subscriptionId);
|
|
356
|
+
if (!callback) {
|
|
357
|
+
console.warn(
|
|
358
|
+
"[Venus SDK] Received update for unknown subscription:",
|
|
359
|
+
notification.subscriptionId
|
|
360
|
+
);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
callback(notification.updates);
|
|
365
|
+
} catch (error) {
|
|
366
|
+
console.error("[Venus SDK] Error in simulation subscription callback", error);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
ensureValidSubscribeOptions(options) {
|
|
370
|
+
if (typeof options !== "object" || options === null) {
|
|
371
|
+
throw new Error("Simulation subscribe requires an options object");
|
|
372
|
+
}
|
|
373
|
+
const opts = options;
|
|
374
|
+
if (typeof opts.onUpdate !== "function") {
|
|
375
|
+
throw new Error("Simulation subscribe requires an onUpdate callback");
|
|
376
|
+
}
|
|
377
|
+
const hasFilter = Array.isArray(opts.entities) && opts.entities.length > 0 || Array.isArray(opts.tags) && opts.tags.length > 0 || Boolean(opts.activeRuns);
|
|
378
|
+
if (!hasFilter) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
"Simulation subscribe requires at least one filter (entities, tags, activeRuns)"
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/simulation/index.ts
|
|
387
|
+
function initializeSimulation(venusApi, host) {
|
|
388
|
+
venusApi.simulation = {
|
|
389
|
+
isEnabled: () => true
|
|
390
|
+
};
|
|
391
|
+
venusApi.simulation.getConfigAsync = () => {
|
|
392
|
+
return host.simulation.getConfigAsync();
|
|
393
|
+
};
|
|
394
|
+
venusApi.simulation.getStateAsync = (roomId) => {
|
|
395
|
+
return host.simulation.getStateAsync(roomId);
|
|
396
|
+
};
|
|
397
|
+
venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
|
|
398
|
+
return host.simulation.executeRecipeAsync(recipeId, inputs, options);
|
|
399
|
+
};
|
|
400
|
+
venusApi.simulation.getActiveRunsAsync = () => {
|
|
401
|
+
return host.simulation.getActiveRunsAsync();
|
|
402
|
+
};
|
|
403
|
+
venusApi.simulation.collectRecipeAsync = (runId) => {
|
|
404
|
+
return host.simulation.collectRecipeAsync(runId);
|
|
405
|
+
};
|
|
406
|
+
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, options) => {
|
|
407
|
+
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, options);
|
|
408
|
+
};
|
|
409
|
+
venusApi.simulation.triggerRecipeChainAsync = (recipeId, options) => {
|
|
410
|
+
return host.simulation.triggerRecipeChainAsync(recipeId, options);
|
|
411
|
+
};
|
|
412
|
+
venusApi.simulation.getAvailableRecipesAsync = async (options) => {
|
|
413
|
+
return host.simulation.getAvailableRecipesAsync(options);
|
|
414
|
+
};
|
|
415
|
+
venusApi.simulation.getRecipeRequirementsAsync = (recipe) => {
|
|
416
|
+
return host.simulation.getRecipeRequirementsAsync(recipe);
|
|
417
|
+
};
|
|
418
|
+
venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
|
|
419
|
+
return host.simulation.getBatchRecipeRequirementsAsync(recipes);
|
|
420
|
+
};
|
|
421
|
+
venusApi.simulation.resolveFieldValueAsync = (entityId, fieldPath, entity) => {
|
|
422
|
+
return host.simulation.resolveFieldValueAsync(entityId, fieldPath, entity);
|
|
423
|
+
};
|
|
424
|
+
venusApi.simulation.getEntityMetadataAsync = (entityId) => {
|
|
425
|
+
return host.simulation.getEntityMetadataAsync(entityId);
|
|
426
|
+
};
|
|
427
|
+
venusApi.simulation.getSlotAssignmentsAsync = (containerId) => {
|
|
428
|
+
return host.simulation.getSlotAssignmentsAsync(containerId);
|
|
429
|
+
};
|
|
430
|
+
venusApi.simulation.getSlotContainersAsync = () => {
|
|
431
|
+
return host.simulation.getSlotContainersAsync();
|
|
432
|
+
};
|
|
433
|
+
venusApi.simulation.assignItemToSlotAsync = (containerId, slotId, itemId) => {
|
|
434
|
+
return host.simulation.assignItemToSlotAsync(containerId, slotId, itemId);
|
|
435
|
+
};
|
|
436
|
+
venusApi.simulation.removeItemFromSlotAsync = (containerId, slotId) => {
|
|
437
|
+
return host.simulation.removeItemFromSlotAsync(containerId, slotId);
|
|
438
|
+
};
|
|
439
|
+
venusApi.simulation.getAvailableItemsAsync = (containerId, slotId) => {
|
|
440
|
+
return host.simulation.getAvailableItemsAsync(containerId, slotId);
|
|
441
|
+
};
|
|
442
|
+
venusApi.simulation.calculatePowerPreviewAsync = (containerId, slotId, candidateItemId) => {
|
|
443
|
+
return host.simulation.calculatePowerPreviewAsync(
|
|
444
|
+
containerId,
|
|
445
|
+
slotId,
|
|
446
|
+
candidateItemId
|
|
447
|
+
);
|
|
448
|
+
};
|
|
449
|
+
venusApi.simulation.executeBatchOperationsAsync = (operations, validateOnly) => {
|
|
450
|
+
return host.simulation.executeBatchOperationsAsync(operations, validateOnly);
|
|
451
|
+
};
|
|
452
|
+
venusApi.simulation.validateSlotAssignmentAsync = (containerId, slotId, itemId) => {
|
|
453
|
+
return host.simulation.validateSlotAssignmentAsync(
|
|
454
|
+
containerId,
|
|
455
|
+
slotId,
|
|
456
|
+
itemId
|
|
457
|
+
);
|
|
458
|
+
};
|
|
459
|
+
venusApi.simulation.subscribeAsync = (options) => {
|
|
460
|
+
return host.simulation.subscribeAsync(options);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/version.ts
|
|
465
|
+
var SDK_VERSION = "3.4.3-beta.0";
|
|
466
|
+
|
|
467
|
+
// src/leaderboard/utils.ts
|
|
468
|
+
var HASH_ALGORITHM_WEB_CRYPTO = "SHA-256";
|
|
469
|
+
var HASH_ALGORITHM_NODE = "sha256";
|
|
470
|
+
async function computeScoreHash(score, duration, token, sealingNonce, sealingSecret) {
|
|
471
|
+
const payload = `score:${score}|duration:${duration}|token:${token}`;
|
|
472
|
+
const fullPayload = `${payload}|nonce:${sealingNonce}`;
|
|
473
|
+
const encoder = new TextEncoder();
|
|
474
|
+
const keyData = encoder.encode(sealingSecret);
|
|
475
|
+
const messageData = encoder.encode(fullPayload);
|
|
476
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
477
|
+
"raw",
|
|
478
|
+
keyData,
|
|
479
|
+
{ name: "HMAC", hash: HASH_ALGORITHM_WEB_CRYPTO },
|
|
480
|
+
false,
|
|
481
|
+
["sign"]
|
|
482
|
+
);
|
|
483
|
+
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
484
|
+
return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/leaderboard/RpcLeaderboardApi.ts
|
|
488
|
+
var RpcLeaderboardApi = class {
|
|
489
|
+
rpcClient;
|
|
490
|
+
/** Cache of score tokens for automatic hash computation */
|
|
491
|
+
tokenCache = /* @__PURE__ */ new Map();
|
|
492
|
+
constructor(rpcClient) {
|
|
493
|
+
this.rpcClient = rpcClient;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Create a score token for submitting a score.
|
|
497
|
+
* Token is cached for automatic hash computation if score sealing is enabled.
|
|
498
|
+
*
|
|
499
|
+
* @param mode - Optional game mode
|
|
500
|
+
* @returns Score token with sealing data if enabled
|
|
501
|
+
*/
|
|
502
|
+
async createScoreToken(mode) {
|
|
503
|
+
const token = await this.rpcClient.call(
|
|
504
|
+
"H5_LEADERBOARD_CREATE_SCORE_TOKEN" /* H5_LEADERBOARD_CREATE_SCORE_TOKEN */,
|
|
505
|
+
mode ? { mode } : {}
|
|
506
|
+
);
|
|
507
|
+
this.tokenCache.set(token.token, token);
|
|
508
|
+
return token;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Submit a score to the leaderboard.
|
|
512
|
+
* Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
|
|
513
|
+
*
|
|
514
|
+
* @param params - Score submission parameters
|
|
515
|
+
* @returns Submission result with acceptance status and rank
|
|
516
|
+
* @throws Error if token not found in cache
|
|
517
|
+
*/
|
|
518
|
+
async submitScore(params) {
|
|
519
|
+
let hash;
|
|
520
|
+
if (params.token) {
|
|
521
|
+
const cachedToken = this.tokenCache.get(params.token);
|
|
522
|
+
if (!cachedToken) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
"Invalid token: not found in cache. Did you call createScoreToken() first?"
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
|
|
528
|
+
hash = await computeScoreHash(
|
|
529
|
+
params.score,
|
|
530
|
+
params.duration,
|
|
531
|
+
params.token,
|
|
532
|
+
cachedToken.sealingNonce,
|
|
533
|
+
cachedToken.sealingSecret
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
this.tokenCache.delete(params.token);
|
|
537
|
+
}
|
|
538
|
+
return this.rpcClient.call(
|
|
539
|
+
"H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
|
|
540
|
+
{
|
|
541
|
+
token: params.token,
|
|
542
|
+
score: params.score,
|
|
543
|
+
duration: params.duration,
|
|
544
|
+
mode: params.mode,
|
|
545
|
+
telemetry: params.telemetry,
|
|
546
|
+
metadata: params.metadata,
|
|
547
|
+
hash
|
|
548
|
+
// undefined if no sealing, computed if sealing enabled
|
|
549
|
+
}
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
getPagedScores(options) {
|
|
553
|
+
return this.rpcClient.call(
|
|
554
|
+
"H5_LEADERBOARD_GET_PAGED_SCORES" /* H5_LEADERBOARD_GET_PAGED_SCORES */,
|
|
555
|
+
options ?? {}
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
getMyRank(options) {
|
|
559
|
+
return this.rpcClient.call(
|
|
560
|
+
"H5_LEADERBOARD_GET_MY_RANK" /* H5_LEADERBOARD_GET_MY_RANK */,
|
|
561
|
+
options ?? {}
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
getPodiumScores(options) {
|
|
565
|
+
return this.rpcClient.call(
|
|
566
|
+
"H5_LEADERBOARD_GET_PODIUM_SCORES" /* H5_LEADERBOARD_GET_PODIUM_SCORES */,
|
|
567
|
+
options ?? {}
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// src/leaderboard/MockLeaderboardApi.ts
|
|
573
|
+
var MockLeaderboardApi = class {
|
|
574
|
+
tokens = /* @__PURE__ */ new Map();
|
|
575
|
+
/** Cache of score tokens for automatic hash computation */
|
|
576
|
+
tokenCache = /* @__PURE__ */ new Map();
|
|
577
|
+
entriesByMode = /* @__PURE__ */ new Map();
|
|
578
|
+
tokenCounter = 0;
|
|
579
|
+
enableScoreSealing = false;
|
|
580
|
+
scoreSealingSecret = "mock-leaderboard-secret-key";
|
|
581
|
+
constructor(options) {
|
|
582
|
+
if (options?.enableScoreSealing) {
|
|
583
|
+
this.enableScoreSealing = true;
|
|
584
|
+
}
|
|
585
|
+
if (options?.scoreSealingSecret) {
|
|
586
|
+
this.scoreSealingSecret = options.scoreSealingSecret;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Configure mock leaderboard settings
|
|
591
|
+
*
|
|
592
|
+
* @param options - Configuration options
|
|
593
|
+
*/
|
|
594
|
+
configure(options) {
|
|
595
|
+
if (typeof options.enableScoreSealing === "boolean") {
|
|
596
|
+
this.enableScoreSealing = options.enableScoreSealing;
|
|
597
|
+
}
|
|
598
|
+
if (options.scoreSealingSecret) {
|
|
599
|
+
this.scoreSealingSecret = options.scoreSealingSecret;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
generateNonce() {
|
|
603
|
+
return (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).slice(0, 64);
|
|
604
|
+
}
|
|
605
|
+
getModeKey(mode) {
|
|
606
|
+
const normalizedMode = mode || "default";
|
|
607
|
+
return `${normalizedMode}`;
|
|
608
|
+
}
|
|
609
|
+
getEntriesForMode(mode) {
|
|
610
|
+
const key = this.getModeKey(mode);
|
|
611
|
+
if (!this.entriesByMode.has(key)) {
|
|
612
|
+
this.entriesByMode.set(key, []);
|
|
613
|
+
}
|
|
614
|
+
return this.entriesByMode.get(key);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Create a mock score token for testing.
|
|
618
|
+
* Token is cached for automatic hash computation if score sealing is enabled.
|
|
619
|
+
*
|
|
620
|
+
* @param mode - Optional game mode
|
|
621
|
+
* @returns Score token with sealing data if enabled
|
|
622
|
+
*/
|
|
623
|
+
async createScoreToken(mode) {
|
|
624
|
+
const token = `mock_token_${++this.tokenCounter}`;
|
|
625
|
+
const startTime = Date.now();
|
|
626
|
+
const expiresAt = startTime + 36e5;
|
|
627
|
+
const resolvedMode = mode || "default";
|
|
628
|
+
const sealingNonce = this.enableScoreSealing ? this.generateNonce() : null;
|
|
629
|
+
const sealingSecret = this.enableScoreSealing ? this.scoreSealingSecret : null;
|
|
630
|
+
this.tokens.set(token, {
|
|
631
|
+
id: token,
|
|
632
|
+
expiresAt,
|
|
633
|
+
mode: resolvedMode,
|
|
634
|
+
sealingNonce,
|
|
635
|
+
used: false
|
|
636
|
+
});
|
|
637
|
+
const result = {
|
|
638
|
+
token,
|
|
639
|
+
startTime,
|
|
640
|
+
expiresAt,
|
|
641
|
+
sealingNonce,
|
|
642
|
+
sealingSecret,
|
|
643
|
+
mode: resolvedMode
|
|
644
|
+
};
|
|
645
|
+
this.tokenCache.set(token, result);
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Submit a mock score to the leaderboard.
|
|
650
|
+
* Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
|
|
651
|
+
*
|
|
652
|
+
* @param params - Score submission parameters
|
|
653
|
+
* @returns Submission result with acceptance status and rank
|
|
654
|
+
* @throws Error if token not found in cache or validation fails
|
|
655
|
+
*/
|
|
656
|
+
async submitScore(params) {
|
|
657
|
+
let hash;
|
|
658
|
+
if (params.token) {
|
|
659
|
+
const cachedToken = this.tokenCache.get(params.token);
|
|
660
|
+
if (!cachedToken) {
|
|
661
|
+
throw new Error(
|
|
662
|
+
"Invalid token: not found in cache. Did you call createScoreToken() first?"
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
|
|
666
|
+
hash = await computeScoreHash(
|
|
667
|
+
params.score,
|
|
668
|
+
params.duration,
|
|
669
|
+
params.token,
|
|
670
|
+
cachedToken.sealingNonce,
|
|
671
|
+
cachedToken.sealingSecret
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (!params.token) {
|
|
676
|
+
const mode = params.mode || "default";
|
|
677
|
+
const submittedAt2 = Date.now();
|
|
678
|
+
const entry2 = {
|
|
679
|
+
profileId: `mock_profile`,
|
|
680
|
+
username: "Mock Player",
|
|
681
|
+
avatarUrl: null,
|
|
682
|
+
score: params.score,
|
|
683
|
+
duration: params.duration,
|
|
684
|
+
submittedAt: submittedAt2,
|
|
685
|
+
token: "simple-mode",
|
|
686
|
+
rank: null,
|
|
687
|
+
zScore: null,
|
|
688
|
+
isAnomaly: false,
|
|
689
|
+
trustScore: 50,
|
|
690
|
+
metadata: params.metadata ?? null,
|
|
691
|
+
isSeed: false
|
|
692
|
+
};
|
|
693
|
+
const modeEntries2 = this.getEntriesForMode(mode);
|
|
694
|
+
modeEntries2.push(entry2);
|
|
695
|
+
modeEntries2.sort((a, b) => {
|
|
696
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
697
|
+
return a.submittedAt - b.submittedAt;
|
|
698
|
+
});
|
|
699
|
+
modeEntries2.forEach((e, index) => {
|
|
700
|
+
modeEntries2[index] = { ...e, rank: index + 1 };
|
|
701
|
+
});
|
|
702
|
+
const inserted2 = modeEntries2.find((e) => e.submittedAt === submittedAt2);
|
|
703
|
+
return {
|
|
704
|
+
accepted: true,
|
|
705
|
+
rank: inserted2?.rank ?? null
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
const scoreToken = this.tokens.get(params.token);
|
|
709
|
+
if (!scoreToken) {
|
|
710
|
+
throw new Error("Invalid score token");
|
|
711
|
+
}
|
|
712
|
+
if (scoreToken.expiresAt < Date.now()) {
|
|
713
|
+
throw new Error("Invalid or expired score token");
|
|
714
|
+
}
|
|
715
|
+
if (scoreToken.used) {
|
|
716
|
+
throw new Error("Score token already used");
|
|
717
|
+
}
|
|
718
|
+
if (params.mode && params.mode !== scoreToken.mode) {
|
|
719
|
+
throw new Error("Submission mode does not match token mode");
|
|
720
|
+
}
|
|
721
|
+
if (scoreToken.sealingNonce && !hash) {
|
|
722
|
+
throw new Error("Score hash required when score sealing is enabled");
|
|
723
|
+
}
|
|
724
|
+
const submittedAt = Date.now();
|
|
725
|
+
const entry = {
|
|
726
|
+
profileId: `mock_profile`,
|
|
727
|
+
username: "Mock Player",
|
|
728
|
+
avatarUrl: null,
|
|
729
|
+
score: params.score,
|
|
730
|
+
duration: params.duration,
|
|
731
|
+
submittedAt,
|
|
732
|
+
token: params.token,
|
|
733
|
+
rank: null,
|
|
734
|
+
zScore: null,
|
|
735
|
+
isAnomaly: false,
|
|
736
|
+
trustScore: 50,
|
|
737
|
+
metadata: params.metadata ?? null,
|
|
738
|
+
isSeed: false
|
|
739
|
+
};
|
|
740
|
+
const modeEntries = this.getEntriesForMode(scoreToken.mode);
|
|
741
|
+
modeEntries.push(entry);
|
|
742
|
+
modeEntries.sort((a, b) => {
|
|
743
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
744
|
+
return a.submittedAt - b.submittedAt;
|
|
745
|
+
});
|
|
746
|
+
modeEntries.forEach((e, index) => {
|
|
747
|
+
modeEntries[index] = { ...e, rank: index + 1 };
|
|
748
|
+
});
|
|
749
|
+
scoreToken.used = true;
|
|
750
|
+
scoreToken.sealingNonce = null;
|
|
751
|
+
this.tokenCache.delete(params.token);
|
|
752
|
+
const inserted = modeEntries.find((e) => e.token === params.token && e.submittedAt === submittedAt);
|
|
753
|
+
return {
|
|
754
|
+
accepted: true,
|
|
755
|
+
rank: inserted?.rank ?? null
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
async getPagedScores(options) {
|
|
759
|
+
const limit = options?.limit ?? 10;
|
|
760
|
+
const mode = options?.mode ?? "default";
|
|
761
|
+
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
762
|
+
const entries = modeEntries.slice(0, limit).map((entry) => ({
|
|
763
|
+
...entry
|
|
764
|
+
}));
|
|
765
|
+
return {
|
|
766
|
+
variant: "standard",
|
|
767
|
+
entries,
|
|
768
|
+
totalEntries: modeEntries.length,
|
|
769
|
+
nextCursor: null,
|
|
770
|
+
playerRank: null,
|
|
771
|
+
periodInstance: options?.period ?? "alltime"
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
async getMyRank(_options) {
|
|
775
|
+
const mode = _options?.mode ?? "default";
|
|
776
|
+
const modeEntries = this.getEntriesForMode(mode);
|
|
777
|
+
const playerEntry = modeEntries[0] ?? null;
|
|
778
|
+
return {
|
|
779
|
+
rank: playerEntry?.rank ?? null,
|
|
780
|
+
score: playerEntry?.score,
|
|
781
|
+
totalPlayers: modeEntries.length,
|
|
782
|
+
percentile: playerEntry ? Math.max(0, 1 - ((playerEntry.rank ?? 1) - 1) / Math.max(modeEntries.length, 1)) : void 0,
|
|
783
|
+
trustScore: 50,
|
|
784
|
+
periodInstance: _options?.period ?? "alltime"
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
async getPodiumScores(options) {
|
|
788
|
+
const mode = options?.mode ?? "default";
|
|
789
|
+
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
790
|
+
const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
|
|
791
|
+
const aheadCount = Math.max(0, Math.min(options?.contextAhead ?? 4, 10));
|
|
792
|
+
const behindCount = Math.max(0, Math.min(options?.contextBehind ?? 2, 10));
|
|
793
|
+
const topEntries = modeEntries.slice(0, topCount);
|
|
794
|
+
const playerEntry = modeEntries[0] ?? null;
|
|
795
|
+
const totalEntries = modeEntries.length;
|
|
796
|
+
let playerRank = playerEntry?.rank ?? null;
|
|
797
|
+
let beforePlayer = [];
|
|
798
|
+
let afterPlayer = [];
|
|
799
|
+
let totalBefore = playerRank ? playerRank - 1 : 0;
|
|
800
|
+
let totalAfter = playerRank ? Math.max(totalEntries - playerRank, 0) : 0;
|
|
801
|
+
let omittedBefore = totalBefore;
|
|
802
|
+
let omittedAfter = totalAfter;
|
|
803
|
+
if (playerRank && playerRank > 0) {
|
|
804
|
+
const beforeStart = Math.max(playerRank - aheadCount - 1, 0);
|
|
805
|
+
beforePlayer = modeEntries.slice(beforeStart, playerRank - 1);
|
|
806
|
+
const afterEnd = Math.min(playerRank + behindCount, totalEntries);
|
|
807
|
+
afterPlayer = modeEntries.slice(playerRank, afterEnd);
|
|
808
|
+
const shownTopAhead = topEntries.filter((entry) => (entry.rank ?? 0) > 0 && (entry.rank ?? 0) < playerRank).length;
|
|
809
|
+
omittedBefore = Math.max(totalBefore - (beforePlayer.length + shownTopAhead), 0);
|
|
810
|
+
omittedAfter = Math.max(totalAfter - afterPlayer.length, 0);
|
|
811
|
+
}
|
|
812
|
+
return {
|
|
813
|
+
variant: "highlight",
|
|
814
|
+
entries: topEntries,
|
|
815
|
+
totalEntries,
|
|
816
|
+
nextCursor: null,
|
|
817
|
+
playerRank: playerRank ?? null,
|
|
818
|
+
periodInstance: options?.period ?? "alltime",
|
|
819
|
+
context: {
|
|
820
|
+
topEntries,
|
|
821
|
+
beforePlayer,
|
|
822
|
+
playerEntry: playerEntry ?? null,
|
|
823
|
+
afterPlayer,
|
|
824
|
+
totalBefore,
|
|
825
|
+
totalAfter,
|
|
826
|
+
omittedBefore,
|
|
827
|
+
omittedAfter
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// src/leaderboard/index.ts
|
|
834
|
+
function initializeLeaderboard(venusApiInstance, host) {
|
|
835
|
+
venusApiInstance.leaderboard = host.leaderboard;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// src/social/RpcSocialApi.ts
|
|
839
|
+
var RpcSocialApi = class {
|
|
840
|
+
constructor(rpcClient) {
|
|
841
|
+
this.rpcClient = rpcClient;
|
|
842
|
+
}
|
|
843
|
+
async shareLinkAsync(options) {
|
|
844
|
+
const result = await this.rpcClient.call("H5_SHARE_LINK" /* SHARE_LINK */, {
|
|
845
|
+
launchParams: options.launchParams,
|
|
846
|
+
metadata: options.metadata ?? {}
|
|
847
|
+
});
|
|
848
|
+
return {
|
|
849
|
+
shareUrl: result.shareUrl
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
async createQRCodeAsync(options) {
|
|
853
|
+
const result = await this.rpcClient.call(
|
|
854
|
+
"H5_CREATE_SHARE_QRCODE" /* CREATE_SHARE_QRCODE */,
|
|
855
|
+
{
|
|
856
|
+
launchParams: options.launchParams,
|
|
857
|
+
metadata: options.metadata ?? {},
|
|
858
|
+
qrOptions: options.qrOptions ?? {}
|
|
859
|
+
}
|
|
860
|
+
);
|
|
861
|
+
return {
|
|
862
|
+
shareUrl: result.shareUrl,
|
|
863
|
+
qrCode: result.qrCode
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// src/VenusTransport.ts
|
|
869
|
+
var VenusTransport = class {
|
|
870
|
+
messageHandler;
|
|
871
|
+
onNotificationCallbacks = [];
|
|
872
|
+
onNotificationCallbacksToRemove = [];
|
|
873
|
+
onVenusMessageCallbacks = [];
|
|
874
|
+
onResponseCallbacks = [];
|
|
875
|
+
onResponseCallbacksToRemove = [];
|
|
876
|
+
_instanceId = null;
|
|
877
|
+
isStarted = false;
|
|
878
|
+
isProcessingMessage = false;
|
|
879
|
+
constructor() {
|
|
880
|
+
this.messageHandler = async (event) => {
|
|
881
|
+
this.isProcessingMessage = true;
|
|
882
|
+
let message;
|
|
883
|
+
if (typeof event.data === "string") {
|
|
884
|
+
message = JSON.parse(event.data);
|
|
885
|
+
} else {
|
|
886
|
+
message = event.data;
|
|
887
|
+
}
|
|
888
|
+
if (!message) {
|
|
889
|
+
this.logInfo("No message found. Ignoring message...");
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
this.notifyVenusMessageReceived(message);
|
|
893
|
+
if (message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "AWAKE" /* AWAKE */ || message.type === "SLEEP" /* SLEEP */ || message.type === "QUIT" /* QUIT */) {
|
|
894
|
+
const notification = {
|
|
895
|
+
type: "rpc-notification",
|
|
896
|
+
id: message.type,
|
|
897
|
+
payload: message.data
|
|
898
|
+
};
|
|
899
|
+
this.handleNotification(notification);
|
|
900
|
+
this.isProcessingMessage = false;
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
const messageData = message.data;
|
|
904
|
+
if (!messageData) {
|
|
905
|
+
this.logWarn("No data found. Ignoring message...");
|
|
906
|
+
this.isProcessingMessage = false;
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (message.type === "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */) {
|
|
910
|
+
const notification = {
|
|
911
|
+
type: "rpc-notification",
|
|
912
|
+
id: message.type,
|
|
913
|
+
payload: message.data
|
|
914
|
+
};
|
|
915
|
+
this.handleNotification(notification);
|
|
916
|
+
this.isProcessingMessage = false;
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const requestId = messageData.requestId;
|
|
920
|
+
if (!requestId) {
|
|
921
|
+
this.logWarn("No requestId. Ignoring message...");
|
|
922
|
+
this.isProcessingMessage = false;
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
if (message.type !== "H5_RESPONSE" /* H5_RESPONSE */) {
|
|
926
|
+
this.logWarn(`Ignoring unknown message type: ${message.type}`);
|
|
927
|
+
this.isProcessingMessage = false;
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const success = messageData.success;
|
|
931
|
+
let error = void 0;
|
|
932
|
+
if (!success) {
|
|
933
|
+
error = {
|
|
934
|
+
message: messageData.error || "Unknown error"
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
let result = messageData.value;
|
|
938
|
+
if (result === void 0) {
|
|
939
|
+
result = messageData.data;
|
|
940
|
+
}
|
|
941
|
+
const response = {
|
|
942
|
+
type: "rpc-response",
|
|
943
|
+
id: requestId,
|
|
944
|
+
result,
|
|
945
|
+
method: message.type,
|
|
946
|
+
error
|
|
947
|
+
};
|
|
948
|
+
await this.handleResponse(response);
|
|
949
|
+
this.isProcessingMessage = false;
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
onNotification(callback) {
|
|
953
|
+
this.onNotificationCallbacks.push(callback);
|
|
954
|
+
return {
|
|
955
|
+
unsubscribe: () => {
|
|
956
|
+
if (this.isProcessingMessage) {
|
|
957
|
+
this.onNotificationCallbacks.push(callback);
|
|
958
|
+
} else {
|
|
959
|
+
this.removeOnNotificationCallback(callback);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
onRequest(callback) {
|
|
965
|
+
throw new Error("Method not implemented.");
|
|
966
|
+
}
|
|
967
|
+
onResponse(callback) {
|
|
968
|
+
this.onResponseCallbacks.push(callback);
|
|
969
|
+
return {
|
|
970
|
+
unsubscribe: () => {
|
|
971
|
+
if (this.isProcessingMessage) {
|
|
972
|
+
this.onResponseCallbacksToRemove.push(callback);
|
|
973
|
+
} else {
|
|
974
|
+
this.removeOnResponseCallback(callback);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
get instanceId() {
|
|
980
|
+
return this._instanceId;
|
|
981
|
+
}
|
|
982
|
+
set instanceId(instanceId) {
|
|
983
|
+
this._instanceId = instanceId;
|
|
984
|
+
}
|
|
985
|
+
sendRequest(request) {
|
|
986
|
+
const instanceId = this.instanceId || "unknown";
|
|
987
|
+
const method = request.method;
|
|
988
|
+
const message = {
|
|
989
|
+
type: method,
|
|
990
|
+
direction: "H5_TO_APP",
|
|
991
|
+
data: {
|
|
992
|
+
...request.args,
|
|
993
|
+
requestId: request.id
|
|
994
|
+
},
|
|
995
|
+
instanceId,
|
|
996
|
+
timestamp: Date.now()
|
|
997
|
+
};
|
|
998
|
+
this.sendVenusMessage(message);
|
|
999
|
+
}
|
|
1000
|
+
sendVenusMessage(message) {
|
|
1001
|
+
const messageAsString = JSON.stringify(message, null, 2);
|
|
1002
|
+
const reactNativeWebView = window.ReactNativeWebView;
|
|
1003
|
+
if (reactNativeWebView) {
|
|
1004
|
+
reactNativeWebView.postMessage(messageAsString);
|
|
1005
|
+
} else {
|
|
1006
|
+
window.parent.postMessage(messageAsString, "*");
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
sendResponse(response) {
|
|
1010
|
+
throw new Error("Method not implemented.");
|
|
1011
|
+
}
|
|
1012
|
+
start() {
|
|
1013
|
+
if (this.isStarted) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
this.isStarted = true;
|
|
1017
|
+
window.addEventListener("message", this.messageHandler, true);
|
|
1018
|
+
this.logInfo(`Started`);
|
|
1019
|
+
}
|
|
1020
|
+
stop() {
|
|
1021
|
+
if (!this.isStarted) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
this.isStarted = false;
|
|
1025
|
+
window.removeEventListener("message", this.messageHandler);
|
|
1026
|
+
this.logInfo(`Stopped`);
|
|
1027
|
+
}
|
|
1028
|
+
handleNotification(notification) {
|
|
1029
|
+
for (const callback of this.onNotificationCallbacks) {
|
|
1030
|
+
callback(notification);
|
|
1031
|
+
}
|
|
1032
|
+
for (const callback of this.onNotificationCallbacksToRemove) {
|
|
1033
|
+
this.removeOnNotificationCallback(callback);
|
|
1034
|
+
}
|
|
1035
|
+
this.onNotificationCallbacksToRemove.length = 0;
|
|
1036
|
+
}
|
|
1037
|
+
async handleResponse(response) {
|
|
1038
|
+
for (const callback of this.onResponseCallbacks) {
|
|
1039
|
+
const consumed = await callback(response);
|
|
1040
|
+
if (consumed) {
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
for (const callback of this.onResponseCallbacksToRemove) {
|
|
1045
|
+
this.removeOnResponseCallback(callback);
|
|
1046
|
+
}
|
|
1047
|
+
this.onResponseCallbacksToRemove.length = 0;
|
|
1048
|
+
}
|
|
1049
|
+
removeOnResponseCallback(callback) {
|
|
1050
|
+
this.onResponseCallbacks.splice(
|
|
1051
|
+
this.onResponseCallbacks.indexOf(callback),
|
|
1052
|
+
1
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
removeOnNotificationCallback(callback) {
|
|
1056
|
+
this.onNotificationCallbacks.splice(
|
|
1057
|
+
this.onNotificationCallbacks.indexOf(callback),
|
|
1058
|
+
1
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
logInfo(message, ...params) {
|
|
1062
|
+
console.log(`[Venus Transport] ${message}`, ...params);
|
|
1063
|
+
}
|
|
1064
|
+
logWarn(message, ...params) {
|
|
1065
|
+
console.warn(`[Venus Transport] ${message}`, ...params);
|
|
1066
|
+
}
|
|
1067
|
+
onVenusMessage(callback) {
|
|
1068
|
+
this.onVenusMessageCallbacks.push(callback);
|
|
1069
|
+
return {
|
|
1070
|
+
unsubscribe: () => {
|
|
1071
|
+
this.onVenusMessageCallbacks.splice(
|
|
1072
|
+
this.onVenusMessageCallbacks.indexOf(callback),
|
|
1073
|
+
1
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
notifyVenusMessageReceived(message) {
|
|
1079
|
+
for (const callback of this.onVenusMessageCallbacks) {
|
|
1080
|
+
callback(message);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
// src/RemoteHost.ts
|
|
1086
|
+
var getCdnBaseUrl = () => {
|
|
1087
|
+
return "https://venus-static-01293ak.web.app/";
|
|
1088
|
+
};
|
|
1089
|
+
var RemoteHost = class {
|
|
1090
|
+
ads;
|
|
1091
|
+
analytics;
|
|
1092
|
+
deviceCache;
|
|
1093
|
+
appStorage;
|
|
1094
|
+
globalStorage;
|
|
1095
|
+
avatar3d;
|
|
1096
|
+
navigation;
|
|
1097
|
+
notifications;
|
|
1098
|
+
popups;
|
|
1099
|
+
profile;
|
|
1100
|
+
system;
|
|
1101
|
+
cdn;
|
|
1102
|
+
time;
|
|
1103
|
+
ai;
|
|
1104
|
+
haptics;
|
|
1105
|
+
features;
|
|
1106
|
+
lifecycle;
|
|
1107
|
+
simulation;
|
|
1108
|
+
rooms;
|
|
1109
|
+
logging;
|
|
1110
|
+
iap;
|
|
1111
|
+
leaderboard;
|
|
1112
|
+
preloader;
|
|
1113
|
+
social;
|
|
1114
|
+
context;
|
|
1115
|
+
get isInitialized() {
|
|
1116
|
+
return this._isInitialized;
|
|
1117
|
+
}
|
|
1118
|
+
venusApi;
|
|
1119
|
+
rpcClient;
|
|
1120
|
+
_isInitialized = false;
|
|
1121
|
+
constructor(venusApi) {
|
|
1122
|
+
this.venusApi = venusApi;
|
|
1123
|
+
const rpcClient = new RpcClient();
|
|
1124
|
+
this.rpcClient = rpcClient;
|
|
1125
|
+
this.ads = new RpcAdsApi(rpcClient);
|
|
1126
|
+
this.analytics = new RpcAnalyticsApi(rpcClient);
|
|
1127
|
+
this.deviceCache = new RpcStorageApi(rpcClient, {
|
|
1128
|
+
clear: "H5_DEVICE_CACHE_CLEAR" /* DEVICE_CACHE_CLEAR */,
|
|
1129
|
+
getItem: "H5_DEVICE_CACHE_GET_ITEM" /* DEVICE_CACHE_GET_ITEM */,
|
|
1130
|
+
getKey: "H5_DEVICE_CACHE_KEY" /* DEVICE_CACHE_KEY */,
|
|
1131
|
+
length: "H5_DEVICE_CACHE_LENGTH" /* DEVICE_CACHE_LENGTH */,
|
|
1132
|
+
removeItem: "H5_DEVICE_CACHE_REMOVE_ITEM" /* DEVICE_CACHE_REMOVE_ITEM */,
|
|
1133
|
+
setItem: "H5_DEVICE_CACHE_SET_ITEM" /* DEVICE_CACHE_SET_ITEM */
|
|
1134
|
+
});
|
|
1135
|
+
this.appStorage = new RpcStorageApi(rpcClient, {
|
|
1136
|
+
clear: "H5_APP_STORAGE_CLEAR" /* APP_STORAGE_CLEAR */,
|
|
1137
|
+
getItem: "H5_APP_STORAGE_GET_ITEM" /* APP_STORAGE_GET_ITEM */,
|
|
1138
|
+
getKey: "H5_APP_STORAGE_KEY" /* APP_STORAGE_KEY */,
|
|
1139
|
+
length: "H5_APP_STORAGE_LENGTH" /* APP_STORAGE_LENGTH */,
|
|
1140
|
+
removeItem: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */,
|
|
1141
|
+
setItem: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
1142
|
+
getAllItems: "H5_APP_STORAGE_GET_ALL_ITEMS" /* APP_STORAGE_GET_ALL_ITEMS */,
|
|
1143
|
+
setMultipleItems: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
1144
|
+
removeMultipleItems: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */
|
|
1145
|
+
});
|
|
1146
|
+
this.globalStorage = new RpcStorageApi(rpcClient, {
|
|
1147
|
+
clear: "H5_GLOBAL_STORAGE_CLEAR" /* GLOBAL_STORAGE_CLEAR */,
|
|
1148
|
+
getItem: "H5_GLOBAL_STORAGE_GET_ITEM" /* GLOBAL_STORAGE_GET_ITEM */,
|
|
1149
|
+
getKey: "H5_GLOBAL_STORAGE_KEY" /* GLOBAL_STORAGE_KEY */,
|
|
1150
|
+
length: "H5_GLOBAL_STORAGE_LENGTH" /* GLOBAL_STORAGE_LENGTH */,
|
|
1151
|
+
removeItem: "H5_GLOBAL_STORAGE_REMOVE_ITEM" /* GLOBAL_STORAGE_REMOVE_ITEM */,
|
|
1152
|
+
setItem: "H5_GLOBAL_STORAGE_SET_ITEM" /* GLOBAL_STORAGE_SET_ITEM */,
|
|
1153
|
+
getAllItems: "H5_GLOBAL_STORAGE_GET_ALL_ITEMS" /* GLOBAL_STORAGE_GET_ALL_ITEMS */,
|
|
1154
|
+
setMultipleItems: "H5_GLOBAL_STORAGE_SET_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_SET_MULTIPLE_ITEMS */,
|
|
1155
|
+
removeMultipleItems: "H5_GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS */
|
|
1156
|
+
});
|
|
1157
|
+
this.avatar3d = new RpcAvatarApi(rpcClient, venusApi);
|
|
1158
|
+
this.navigation = new RpcNavigationApi(rpcClient, venusApi);
|
|
1159
|
+
this.notifications = new RpcNotificationsApi(rpcClient);
|
|
1160
|
+
this.popups = new RpcPopupsApi(rpcClient);
|
|
1161
|
+
this.profile = new HostProfileApi(venusApi);
|
|
1162
|
+
const deviceApi = new HostDeviceApi(venusApi);
|
|
1163
|
+
const environmentApi = new HostEnvironmentApi(venusApi);
|
|
1164
|
+
this.system = new HostSystemApi(deviceApi, environmentApi, venusApi);
|
|
1165
|
+
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
1166
|
+
this.time = new HostTimeApi(rpcClient, venusApi);
|
|
1167
|
+
this.ai = new RpcAiApi(rpcClient);
|
|
1168
|
+
this.haptics = new RpcHapticsApi(rpcClient);
|
|
1169
|
+
this.features = new RpcFeaturesApi(rpcClient);
|
|
1170
|
+
this.lifecycle = new RpcLifecycleApi(rpcClient);
|
|
1171
|
+
this.simulation = new RpcSimulationApi(rpcClient);
|
|
1172
|
+
this.rooms = new RpcRoomsApi(rpcClient);
|
|
1173
|
+
this.logging = new RpcLoggingApi(this, rpcClient);
|
|
1174
|
+
this.iap = new RpcIapApi(rpcClient);
|
|
1175
|
+
this.leaderboard = new RpcLeaderboardApi(rpcClient);
|
|
1176
|
+
this.preloader = new RpcPreloaderApi(rpcClient);
|
|
1177
|
+
this.social = new RpcSocialApi(rpcClient);
|
|
1178
|
+
venusApi.isMock = () => false;
|
|
1179
|
+
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
1180
|
+
initializeRoomsApi(this.venusApi, this);
|
|
1181
|
+
}
|
|
1182
|
+
async initialize(options) {
|
|
1183
|
+
this.log("Initializing Remote Host...");
|
|
1184
|
+
const transport = new VenusTransport();
|
|
1185
|
+
transport.start();
|
|
1186
|
+
this.rpcClient.start(transport);
|
|
1187
|
+
const roomsApi = this.rooms;
|
|
1188
|
+
roomsApi.setupNotifications(transport);
|
|
1189
|
+
const response = await this.rpcClient.call(
|
|
1190
|
+
"INITIALIZE_SDK" /* INIT_SDK */,
|
|
1191
|
+
{},
|
|
1192
|
+
5e3
|
|
1193
|
+
);
|
|
1194
|
+
transport.instanceId = response.instanceId;
|
|
1195
|
+
this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
|
|
1196
|
+
const profile = response.profile;
|
|
1197
|
+
const sanitizedProfile = {
|
|
1198
|
+
id: profile.id,
|
|
1199
|
+
username: profile.username,
|
|
1200
|
+
avatarUrl: profile.avatarUrl ?? null,
|
|
1201
|
+
isAnonymous: Boolean(profile.isAnonymous)
|
|
1202
|
+
};
|
|
1203
|
+
this.venusApi._profileData = sanitizedProfile;
|
|
1204
|
+
this.venusApi._deviceData = response.device;
|
|
1205
|
+
this.venusApi._environmentData = response.environment;
|
|
1206
|
+
this.venusApi._localeData = response.locale;
|
|
1207
|
+
this.venusApi._languageCodeData = response.languageCode;
|
|
1208
|
+
this._isInitialized = true;
|
|
1209
|
+
this.venusApi.launchParams = response.launchParams;
|
|
1210
|
+
await this.rpcClient.call("READY" /* READY */, {});
|
|
1211
|
+
const safeArea = response.safeArea;
|
|
1212
|
+
if (safeArea) {
|
|
1213
|
+
this.venusApi._safeAreaData = safeArea;
|
|
1214
|
+
}
|
|
1215
|
+
this.context = {
|
|
1216
|
+
safeArea,
|
|
1217
|
+
initializeAsleep: response.initializeAsleep
|
|
1218
|
+
};
|
|
1219
|
+
return this.context;
|
|
1220
|
+
}
|
|
1221
|
+
log(message) {
|
|
1222
|
+
console.log(`[Venus SDK] [Remote Host] ${message}`);
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
// src/MockHost.ts
|
|
1227
|
+
var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
|
|
1228
|
+
function createUnavailableRoomsApi() {
|
|
1229
|
+
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
1230
|
+
return {
|
|
1231
|
+
async createRoomAsync() {
|
|
1232
|
+
throw roomsUnavailableError();
|
|
1233
|
+
},
|
|
1234
|
+
async joinOrCreateRoomAsync() {
|
|
1235
|
+
throw roomsUnavailableError();
|
|
1236
|
+
},
|
|
1237
|
+
async joinRoomByCodeAsync() {
|
|
1238
|
+
throw roomsUnavailableError();
|
|
1239
|
+
},
|
|
1240
|
+
async getUserRoomsAsync() {
|
|
1241
|
+
throw roomsUnavailableError();
|
|
1242
|
+
},
|
|
1243
|
+
async subscribeAsync() {
|
|
1244
|
+
throw roomsUnavailableError();
|
|
1245
|
+
},
|
|
1246
|
+
async updateRoomDataAsync() {
|
|
1247
|
+
throw roomsUnavailableError();
|
|
1248
|
+
},
|
|
1249
|
+
async getRoomDataAsync() {
|
|
1250
|
+
throw roomsUnavailableError();
|
|
1251
|
+
},
|
|
1252
|
+
async sendRoomMessageAsync() {
|
|
1253
|
+
throw roomsUnavailableError();
|
|
1254
|
+
},
|
|
1255
|
+
async leaveRoomAsync() {
|
|
1256
|
+
throw roomsUnavailableError();
|
|
1257
|
+
},
|
|
1258
|
+
async kickPlayerAsync() {
|
|
1259
|
+
throw roomsUnavailableError();
|
|
1260
|
+
},
|
|
1261
|
+
async startRoomGameAsync() {
|
|
1262
|
+
throw roomsUnavailableError();
|
|
1263
|
+
},
|
|
1264
|
+
async proposeMoveAsync() {
|
|
1265
|
+
throw roomsUnavailableError();
|
|
1266
|
+
},
|
|
1267
|
+
async validateMoveAsync() {
|
|
1268
|
+
throw roomsUnavailableError();
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
var SIMULATION_UNAVAILABLE_MESSAGE = "[Venus SDK] Simulation API is only available when running inside the Venus host environment.";
|
|
1273
|
+
function createUnavailableSimulationApi() {
|
|
1274
|
+
const simulationUnavailableError = () => new Error(SIMULATION_UNAVAILABLE_MESSAGE);
|
|
1275
|
+
return {
|
|
1276
|
+
isEnabled() {
|
|
1277
|
+
return false;
|
|
1278
|
+
},
|
|
1279
|
+
async getStateAsync() {
|
|
1280
|
+
throw simulationUnavailableError();
|
|
1281
|
+
},
|
|
1282
|
+
async getConfigAsync() {
|
|
1283
|
+
throw simulationUnavailableError();
|
|
1284
|
+
},
|
|
1285
|
+
async executeRecipeAsync() {
|
|
1286
|
+
throw simulationUnavailableError();
|
|
1287
|
+
},
|
|
1288
|
+
async getActiveRunsAsync() {
|
|
1289
|
+
throw simulationUnavailableError();
|
|
1290
|
+
},
|
|
1291
|
+
async collectRecipeAsync() {
|
|
1292
|
+
throw simulationUnavailableError();
|
|
1293
|
+
},
|
|
1294
|
+
async executeScopedRecipeAsync() {
|
|
1295
|
+
throw simulationUnavailableError();
|
|
1296
|
+
},
|
|
1297
|
+
async triggerRecipeChainAsync() {
|
|
1298
|
+
throw simulationUnavailableError();
|
|
1299
|
+
},
|
|
1300
|
+
async getAvailableRecipesAsync() {
|
|
1301
|
+
throw simulationUnavailableError();
|
|
1302
|
+
},
|
|
1303
|
+
async getRecipeRequirementsAsync() {
|
|
1304
|
+
throw simulationUnavailableError();
|
|
1305
|
+
},
|
|
1306
|
+
async getBatchRecipeRequirementsAsync() {
|
|
1307
|
+
throw simulationUnavailableError();
|
|
1308
|
+
},
|
|
1309
|
+
async resolveFieldValueAsync() {
|
|
1310
|
+
throw simulationUnavailableError();
|
|
1311
|
+
},
|
|
1312
|
+
async getEntityMetadataAsync() {
|
|
1313
|
+
throw simulationUnavailableError();
|
|
1314
|
+
},
|
|
1315
|
+
async getSlotContainersAsync() {
|
|
1316
|
+
throw simulationUnavailableError();
|
|
1317
|
+
},
|
|
1318
|
+
async getSlotAssignmentsAsync() {
|
|
1319
|
+
throw simulationUnavailableError();
|
|
1320
|
+
},
|
|
1321
|
+
async assignItemToSlotAsync() {
|
|
1322
|
+
throw simulationUnavailableError();
|
|
1323
|
+
},
|
|
1324
|
+
async removeItemFromSlotAsync() {
|
|
1325
|
+
throw simulationUnavailableError();
|
|
1326
|
+
},
|
|
1327
|
+
async getAvailableItemsAsync() {
|
|
1328
|
+
throw simulationUnavailableError();
|
|
1329
|
+
},
|
|
1330
|
+
async calculatePowerPreviewAsync() {
|
|
1331
|
+
throw simulationUnavailableError();
|
|
1332
|
+
},
|
|
1333
|
+
async validateSlotAssignmentAsync() {
|
|
1334
|
+
throw simulationUnavailableError();
|
|
1335
|
+
},
|
|
1336
|
+
async executeBatchOperationsAsync() {
|
|
1337
|
+
throw simulationUnavailableError();
|
|
1338
|
+
},
|
|
1339
|
+
async subscribeAsync() {
|
|
1340
|
+
throw simulationUnavailableError();
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
var MockHost = class {
|
|
1345
|
+
ads;
|
|
1346
|
+
analytics;
|
|
1347
|
+
deviceCache;
|
|
1348
|
+
appStorage;
|
|
1349
|
+
globalStorage;
|
|
1350
|
+
avatar3d;
|
|
1351
|
+
navigation;
|
|
1352
|
+
notifications;
|
|
1353
|
+
popups;
|
|
1354
|
+
profile;
|
|
1355
|
+
system;
|
|
1356
|
+
cdn;
|
|
1357
|
+
time;
|
|
1358
|
+
ai;
|
|
1359
|
+
haptics;
|
|
1360
|
+
features;
|
|
1361
|
+
lifecycle;
|
|
1362
|
+
simulation;
|
|
1363
|
+
rooms;
|
|
1364
|
+
logging;
|
|
1365
|
+
iap;
|
|
1366
|
+
leaderboard;
|
|
1367
|
+
preloader;
|
|
1368
|
+
social;
|
|
1369
|
+
context;
|
|
1370
|
+
state = 0 /* PLAYING */;
|
|
1371
|
+
get isInitialized() {
|
|
1372
|
+
return this._isInitialized;
|
|
1373
|
+
}
|
|
1374
|
+
venusApi;
|
|
1375
|
+
_isInitialized = false;
|
|
1376
|
+
_overlay;
|
|
1377
|
+
_mockLifecyclesApi;
|
|
1378
|
+
_mockAdsApi;
|
|
1379
|
+
constructor(venusApi) {
|
|
1380
|
+
this.venusApi = venusApi;
|
|
1381
|
+
this._overlay = this.createOverlay();
|
|
1382
|
+
this._mockAdsApi = new MockAdsApi(this._overlay);
|
|
1383
|
+
this._mockLifecyclesApi = new MockLifecycleApi();
|
|
1384
|
+
this.ads = this._mockAdsApi;
|
|
1385
|
+
this.analytics = new MockAnalyticsApi();
|
|
1386
|
+
const appUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
1387
|
+
this.deviceCache = createMockStorageApi("deviceCache", appUrl);
|
|
1388
|
+
this.appStorage = createMockStorageApi("appStorage", appUrl);
|
|
1389
|
+
this.globalStorage = createMockStorageApi("globalStorage");
|
|
1390
|
+
this.simulation = createUnavailableSimulationApi();
|
|
1391
|
+
this.rooms = createUnavailableRoomsApi();
|
|
1392
|
+
this.leaderboard = new MockLeaderboardApi();
|
|
1393
|
+
this.avatar3d = new MockAvatarApi(venusApi);
|
|
1394
|
+
this.navigation = new MockNavigationApi(venusApi);
|
|
1395
|
+
this.notifications = new MockNotificationsApi(venusApi);
|
|
1396
|
+
this.popups = new MockPopupsApi(this._overlay);
|
|
1397
|
+
this.profile = new MockProfileApi(venusApi);
|
|
1398
|
+
const deviceApi = new MockDeviceApi(venusApi);
|
|
1399
|
+
const environmentApi = new MockEnvironmentApi(venusApi);
|
|
1400
|
+
this.system = new MockSystemApi(deviceApi, environmentApi, venusApi);
|
|
1401
|
+
this.cdn = new MockCdnApi(venusApi);
|
|
1402
|
+
this.time = new MockTimeApi(venusApi);
|
|
1403
|
+
this.ai = new MockAiApi();
|
|
1404
|
+
this.haptics = new MockHapticsApi(venusApi);
|
|
1405
|
+
this.features = new MockFeaturesApi();
|
|
1406
|
+
this.lifecycle = this._mockLifecyclesApi;
|
|
1407
|
+
this.logging = new MockLoggingApi();
|
|
1408
|
+
this.iap = new MockIapApi();
|
|
1409
|
+
this.social = new MockSocialApi();
|
|
1410
|
+
initializeRoomsApi(this.venusApi, this);
|
|
1411
|
+
this.preloader = new MockPreloaderApi();
|
|
1412
|
+
venusApi.isMock = () => true;
|
|
1413
|
+
this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
|
|
1414
|
+
}
|
|
1415
|
+
initialize(options) {
|
|
1416
|
+
this._isInitialized = true;
|
|
1417
|
+
this.venusApi._profileData = this.profile.getCurrentProfile();
|
|
1418
|
+
this.venusApi._deviceData = this.system.getDevice();
|
|
1419
|
+
this.venusApi._environmentData = this.system.getEnvironment();
|
|
1420
|
+
this.venusApi._localeData = this.venusApi._mock?.locale || "en-US";
|
|
1421
|
+
this.venusApi._languageCodeData = this.venusApi._mock?.languageCode || "en";
|
|
1422
|
+
this.context = {
|
|
1423
|
+
initializeAsleep: false,
|
|
1424
|
+
safeArea: this.venusApi._safeAreaData
|
|
1425
|
+
};
|
|
1426
|
+
return Promise.resolve(this.context);
|
|
1427
|
+
}
|
|
1428
|
+
createOverlay() {
|
|
1429
|
+
const overlayContainer = document.createElement("div");
|
|
1430
|
+
overlayContainer.id = "venus-mock-overlay";
|
|
1431
|
+
overlayContainer.style.cssText = `
|
|
1432
|
+
position: fixed;
|
|
1433
|
+
top: 0;
|
|
1434
|
+
left: 0;
|
|
1435
|
+
width: 100%;
|
|
1436
|
+
height: 100%;
|
|
1437
|
+
pointer-events: none;
|
|
1438
|
+
z-index: 10000;
|
|
1439
|
+
`;
|
|
1440
|
+
document.body.appendChild(overlayContainer);
|
|
1441
|
+
const menuButton = this.createOverlayButton(
|
|
1442
|
+
"close",
|
|
1443
|
+
"Menu",
|
|
1444
|
+
{ x: window.innerWidth - 48, y: 16, width: 32, height: 32 },
|
|
1445
|
+
() => {
|
|
1446
|
+
this.handleMenuButtonClicked();
|
|
1447
|
+
},
|
|
1448
|
+
"rgba(59, 130, 246, 0.7)",
|
|
1449
|
+
// Blue background instead of black
|
|
1450
|
+
"#FFFFFF"
|
|
1451
|
+
);
|
|
1452
|
+
overlayContainer.appendChild(menuButton);
|
|
1453
|
+
const adOverlay = this.setupAdOverlay();
|
|
1454
|
+
const actionSheet = this.setupActionSheetOverlay();
|
|
1455
|
+
window.addEventListener("resize", () => {
|
|
1456
|
+
this.updateOverlayLayout();
|
|
1457
|
+
});
|
|
1458
|
+
return {
|
|
1459
|
+
container: overlayContainer,
|
|
1460
|
+
elements: {
|
|
1461
|
+
menuButton
|
|
1462
|
+
},
|
|
1463
|
+
appVisibilityState: "visible",
|
|
1464
|
+
actionSheetOverlay: actionSheet,
|
|
1465
|
+
adOverlay,
|
|
1466
|
+
showAdOverlay: () => {
|
|
1467
|
+
return this.showAdOverlay("REWARDED VIDEO AD");
|
|
1468
|
+
},
|
|
1469
|
+
showActionSheet: (items, options) => {
|
|
1470
|
+
return this.showActionSheetOverlay(items, options);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
async handleMenuButtonClicked() {
|
|
1475
|
+
if (this.state === 0 /* PLAYING */) {
|
|
1476
|
+
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
1477
|
+
this.state = 1 /* PAUSED */;
|
|
1478
|
+
}
|
|
1479
|
+
const actionSheetItems = [];
|
|
1480
|
+
const awakeAction = {
|
|
1481
|
+
label: "\u23F0 Awake",
|
|
1482
|
+
id: "awakeAction"
|
|
1483
|
+
};
|
|
1484
|
+
const sleepAction = {
|
|
1485
|
+
label: "\u{1F4A4} Sleep",
|
|
1486
|
+
id: "sleepAction"
|
|
1487
|
+
};
|
|
1488
|
+
const quitAction = {
|
|
1489
|
+
label: "\u{1F6D1} Quit",
|
|
1490
|
+
id: "quitAction"
|
|
1491
|
+
};
|
|
1492
|
+
const playAction = {
|
|
1493
|
+
label: "\u25B6\uFE0F Play",
|
|
1494
|
+
id: "playAction"
|
|
1495
|
+
};
|
|
1496
|
+
if (this.state === 1 /* PAUSED */) {
|
|
1497
|
+
actionSheetItems.push(sleepAction);
|
|
1498
|
+
} else if (this.state === 2 /* SLEEPING */) {
|
|
1499
|
+
actionSheetItems.push(awakeAction);
|
|
1500
|
+
}
|
|
1501
|
+
if (this.state !== 3 /* TERMINATED */) {
|
|
1502
|
+
actionSheetItems.push(quitAction);
|
|
1503
|
+
} else if (this.state === 3 /* TERMINATED */) {
|
|
1504
|
+
actionSheetItems.push(playAction);
|
|
1505
|
+
}
|
|
1506
|
+
const action = await this.showActionSheetOverlay(actionSheetItems);
|
|
1507
|
+
if (action === awakeAction.id) {
|
|
1508
|
+
this.tryAwake();
|
|
1509
|
+
} else if (action === sleepAction.id) {
|
|
1510
|
+
this.trySleep();
|
|
1511
|
+
} else if (action === playAction.id) {
|
|
1512
|
+
this.tryPlay();
|
|
1513
|
+
} else if (action === quitAction.id) {
|
|
1514
|
+
this.tryQuit();
|
|
1515
|
+
} else {
|
|
1516
|
+
this.tryResume();
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
tryAwake() {
|
|
1520
|
+
if (this.state === 2 /* SLEEPING */) {
|
|
1521
|
+
this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
|
|
1522
|
+
this.state = 1 /* PAUSED */;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
trySleep() {
|
|
1526
|
+
if (this.state === 1 /* PAUSED */) {
|
|
1527
|
+
this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
|
|
1528
|
+
this.state = 2 /* SLEEPING */;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
tryPlay() {
|
|
1532
|
+
if (this.state === 3 /* TERMINATED */) {
|
|
1533
|
+
this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
|
|
1534
|
+
this.state = 1 /* PAUSED */;
|
|
1535
|
+
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
1536
|
+
this.state = 0 /* PLAYING */;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
tryQuit() {
|
|
1540
|
+
if (this.state === 0 /* PLAYING */) {
|
|
1541
|
+
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
1542
|
+
this.state = 1 /* PAUSED */;
|
|
1543
|
+
}
|
|
1544
|
+
if (this.state === 1 /* PAUSED */) {
|
|
1545
|
+
this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
|
|
1546
|
+
this.state = 2 /* SLEEPING */;
|
|
1547
|
+
}
|
|
1548
|
+
if (this.state === 2 /* SLEEPING */) {
|
|
1549
|
+
this.triggerLifecycleEvent("QUIT" /* QUIT */);
|
|
1550
|
+
this.state = 3 /* TERMINATED */;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
tryResume() {
|
|
1554
|
+
if (this.state === 1 /* PAUSED */) {
|
|
1555
|
+
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
1556
|
+
this.state = 0 /* PLAYING */;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
async showAdOverlay(type) {
|
|
1560
|
+
return new Promise((resolve, reject) => {
|
|
1561
|
+
const overlay = this._overlay;
|
|
1562
|
+
const adOverlay = overlay.adOverlay;
|
|
1563
|
+
overlay.adOverlay.innerHTML = "";
|
|
1564
|
+
const heading = document.createElement("h1");
|
|
1565
|
+
heading.style.cssText = `
|
|
1566
|
+
font-size: 24px;
|
|
1567
|
+
margin-bottom: 20px;
|
|
1568
|
+
text-align: center;
|
|
1569
|
+
`;
|
|
1570
|
+
heading.innerText = type === "interstitial" ? "INTERSTITIAL AD" : "REWARDED VIDEO AD";
|
|
1571
|
+
overlay.adOverlay.appendChild(heading);
|
|
1572
|
+
const content = document.createElement("div");
|
|
1573
|
+
content.style.cssText = `
|
|
1574
|
+
width: 300px;
|
|
1575
|
+
height: 250px;
|
|
1576
|
+
background-color: #1e40af;
|
|
1577
|
+
display: flex;
|
|
1578
|
+
align-items: center;
|
|
1579
|
+
justify-content: center;
|
|
1580
|
+
margin-bottom: 20px;
|
|
1581
|
+
border-radius: 8px;
|
|
1582
|
+
`;
|
|
1583
|
+
content.innerText = "Mock Ad Content";
|
|
1584
|
+
adOverlay.appendChild(content);
|
|
1585
|
+
const timer = document.createElement("p");
|
|
1586
|
+
timer.style.cssText = `
|
|
1587
|
+
margin-bottom: 20px;
|
|
1588
|
+
font-size: 16px;
|
|
1589
|
+
`;
|
|
1590
|
+
timer.innerText = "Normally ads would have a timer...";
|
|
1591
|
+
adOverlay.appendChild(timer);
|
|
1592
|
+
const okButton = document.createElement("button");
|
|
1593
|
+
okButton.style.cssText = `
|
|
1594
|
+
padding: 10px 40px;
|
|
1595
|
+
background-color: #2563eb;
|
|
1596
|
+
color: white;
|
|
1597
|
+
border: none;
|
|
1598
|
+
border-radius: 4px;
|
|
1599
|
+
font-size: 16px;
|
|
1600
|
+
cursor: pointer;
|
|
1601
|
+
`;
|
|
1602
|
+
okButton.innerText = "Close Ad";
|
|
1603
|
+
adOverlay.appendChild(okButton);
|
|
1604
|
+
adOverlay.style.display = "flex";
|
|
1605
|
+
okButton.onclick = () => {
|
|
1606
|
+
this.hideAdOverlay();
|
|
1607
|
+
resolve(true);
|
|
1608
|
+
};
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
hideAdOverlay() {
|
|
1612
|
+
const overlay = this._overlay;
|
|
1613
|
+
if (overlay.adOverlay) {
|
|
1614
|
+
overlay.adOverlay.style.display = "none";
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
setupActionSheetOverlay() {
|
|
1618
|
+
const actionSheetOverlay = document.createElement("div");
|
|
1619
|
+
actionSheetOverlay.id = "venus-action-sheet-overlay";
|
|
1620
|
+
actionSheetOverlay.style.cssText = `
|
|
1621
|
+
position: fixed;
|
|
1622
|
+
top: 0;
|
|
1623
|
+
left: 0;
|
|
1624
|
+
width: 100%;
|
|
1625
|
+
height: 100%;
|
|
1626
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
1627
|
+
display: flex;
|
|
1628
|
+
align-items: center;
|
|
1629
|
+
justify-content: center;
|
|
1630
|
+
z-index: 10600;
|
|
1631
|
+
font-family: sans-serif;
|
|
1632
|
+
display: none;
|
|
1633
|
+
`;
|
|
1634
|
+
document.body.appendChild(actionSheetOverlay);
|
|
1635
|
+
return actionSheetOverlay;
|
|
1636
|
+
}
|
|
1637
|
+
createOverlayButton(id, text, position, onClick, background, color) {
|
|
1638
|
+
const button = document.createElement("button");
|
|
1639
|
+
button.id = `venus-mock-${id}-button`;
|
|
1640
|
+
button.innerText = text;
|
|
1641
|
+
button.style.cssText = `
|
|
1642
|
+
position: absolute;
|
|
1643
|
+
left: ${position.x}px;
|
|
1644
|
+
top: ${position.y}px;
|
|
1645
|
+
width: ${position.width}px;
|
|
1646
|
+
min-width: ${position.width}px;
|
|
1647
|
+
height: ${position.height}px;
|
|
1648
|
+
background: ${background};
|
|
1649
|
+
color: ${color};
|
|
1650
|
+
border: none;
|
|
1651
|
+
border-radius: 8px;
|
|
1652
|
+
font-family: sans-serif;
|
|
1653
|
+
font-weight: bold;
|
|
1654
|
+
font-size: ${Math.min(position.width, position.height) / 3}px;
|
|
1655
|
+
cursor: pointer;
|
|
1656
|
+
pointer-events: auto;
|
|
1657
|
+
display: flex;
|
|
1658
|
+
align-items: center;
|
|
1659
|
+
justify-content: center;
|
|
1660
|
+
opacity: 0.9;
|
|
1661
|
+
transition: opacity 0.2s;
|
|
1662
|
+
`;
|
|
1663
|
+
button.addEventListener("click", onClick);
|
|
1664
|
+
button.addEventListener("mouseover", () => {
|
|
1665
|
+
button.style.opacity = "1";
|
|
1666
|
+
});
|
|
1667
|
+
button.addEventListener("mouseout", () => {
|
|
1668
|
+
button.style.opacity = "0.9";
|
|
1669
|
+
});
|
|
1670
|
+
return button;
|
|
1671
|
+
}
|
|
1672
|
+
updateOverlayLayout() {
|
|
1673
|
+
const overlay = this._overlay;
|
|
1674
|
+
const menuBtn = overlay.elements.menuButton;
|
|
1675
|
+
menuBtn.style.left = `${window.innerWidth - 48}px`;
|
|
1676
|
+
menuBtn.style.top = "16px";
|
|
1677
|
+
menuBtn.style.width = "32px";
|
|
1678
|
+
menuBtn.style.minWidth = "32px";
|
|
1679
|
+
menuBtn.style.height = "32px";
|
|
1680
|
+
}
|
|
1681
|
+
triggerLifecycleEvent(name) {
|
|
1682
|
+
console.log("Trigger Lifecycle Event: ", name);
|
|
1683
|
+
if (name == "PAUSE" /* PAUSE */) {
|
|
1684
|
+
this._mockLifecyclesApi.triggerPauseCallbacks();
|
|
1685
|
+
} else if (name == "RESUME" /* RESUME */) {
|
|
1686
|
+
this._mockLifecyclesApi.triggerResumeCallbacks();
|
|
1687
|
+
} else if (name == "QUIT" /* QUIT */) {
|
|
1688
|
+
this._mockLifecyclesApi.triggerQuitCallbacks();
|
|
1689
|
+
} else if (name == "AWAKE" /* AWAKE */) {
|
|
1690
|
+
this._mockLifecyclesApi.triggerAwakeCallbacks();
|
|
1691
|
+
} else if (name == "SLEEP" /* SLEEP */) {
|
|
1692
|
+
this._mockLifecyclesApi.triggerSleepCallbacks();
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
setOverlayElementVisibility(element, visible) {
|
|
1696
|
+
const overlay = this._overlay;
|
|
1697
|
+
const elements = overlay.elements;
|
|
1698
|
+
if (elements[element]) {
|
|
1699
|
+
elements[element].style.display = visible ? "flex" : "none";
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
setupAdOverlay() {
|
|
1703
|
+
const adOverlay = document.createElement("div");
|
|
1704
|
+
adOverlay.id = "venus-ad-overlay";
|
|
1705
|
+
adOverlay.style.cssText = `
|
|
1706
|
+
position: fixed;
|
|
1707
|
+
top: 0;
|
|
1708
|
+
left: 0;
|
|
1709
|
+
width: 100%;
|
|
1710
|
+
height: 100%;
|
|
1711
|
+
background-color: rgba(37, 99, 235, 0.9);
|
|
1712
|
+
color: white;
|
|
1713
|
+
display: flex;
|
|
1714
|
+
flex-direction: column;
|
|
1715
|
+
align-items: center;
|
|
1716
|
+
justify-content: center;
|
|
1717
|
+
z-index: 10500;
|
|
1718
|
+
font-family: sans-serif;
|
|
1719
|
+
display: none;
|
|
1720
|
+
`;
|
|
1721
|
+
document.body.appendChild(adOverlay);
|
|
1722
|
+
return adOverlay;
|
|
1723
|
+
}
|
|
1724
|
+
log(msg, ...args) {
|
|
1725
|
+
console.log(`[Venus Mock] ${msg}`, ...args);
|
|
1726
|
+
}
|
|
1727
|
+
showActionSheetOverlay(items, options) {
|
|
1728
|
+
this.log("Showing ActionSheetOverlay...");
|
|
1729
|
+
return new Promise((resolve, reject) => {
|
|
1730
|
+
const overlay = this._overlay;
|
|
1731
|
+
overlay.actionSheetOverlay.innerHTML = "";
|
|
1732
|
+
overlay.actionSheetOverlay.style.display = "flex";
|
|
1733
|
+
const actionSheet = document.createElement("div");
|
|
1734
|
+
actionSheet.className = "venus-action-sheet";
|
|
1735
|
+
actionSheet.style.cssText = `
|
|
1736
|
+
background-color: white;
|
|
1737
|
+
border-radius: 8px;
|
|
1738
|
+
width: 80%;
|
|
1739
|
+
max-width: 400px;
|
|
1740
|
+
max-height: 80%;
|
|
1741
|
+
display: flex;
|
|
1742
|
+
flex-direction: column;
|
|
1743
|
+
overflow: hidden;
|
|
1744
|
+
color: black;
|
|
1745
|
+
`;
|
|
1746
|
+
if (options?.title) {
|
|
1747
|
+
const titleContainer = document.createElement("div");
|
|
1748
|
+
titleContainer.style.cssText = `
|
|
1749
|
+
padding: 16px;
|
|
1750
|
+
border-bottom: 1px solid #eaeaea;
|
|
1751
|
+
font-weight: bold;
|
|
1752
|
+
font-size: 18px;
|
|
1753
|
+
text-align: center;
|
|
1754
|
+
color: black;
|
|
1755
|
+
`;
|
|
1756
|
+
titleContainer.innerText = options.title;
|
|
1757
|
+
actionSheet.appendChild(titleContainer);
|
|
1758
|
+
}
|
|
1759
|
+
if (options?.message) {
|
|
1760
|
+
const messageContainer = document.createElement("div");
|
|
1761
|
+
messageContainer.style.cssText = `
|
|
1762
|
+
padding: 8px 16px;
|
|
1763
|
+
color: #666;
|
|
1764
|
+
font-size: 14px;
|
|
1765
|
+
text-align: center;
|
|
1766
|
+
`;
|
|
1767
|
+
messageContainer.innerText = options.message;
|
|
1768
|
+
actionSheet.appendChild(messageContainer);
|
|
1769
|
+
}
|
|
1770
|
+
const optionsContainer = document.createElement("div");
|
|
1771
|
+
optionsContainer.style.cssText = `
|
|
1772
|
+
overflow-y: auto;
|
|
1773
|
+
max-height: 300px;
|
|
1774
|
+
`;
|
|
1775
|
+
items.forEach((item, index) => {
|
|
1776
|
+
const optionItem = document.createElement("div");
|
|
1777
|
+
optionItem.style.cssText = `
|
|
1778
|
+
padding: 12px 16px;
|
|
1779
|
+
border-bottom: 1px solid #eaeaea;
|
|
1780
|
+
cursor: pointer;
|
|
1781
|
+
display: flex;
|
|
1782
|
+
align-items: center;
|
|
1783
|
+
transition: background-color 0.2s;
|
|
1784
|
+
color: black;
|
|
1785
|
+
`;
|
|
1786
|
+
optionItem.addEventListener("mouseover", () => {
|
|
1787
|
+
optionItem.style.backgroundColor = "#f5f5f5";
|
|
1788
|
+
});
|
|
1789
|
+
optionItem.addEventListener("mouseout", () => {
|
|
1790
|
+
optionItem.style.backgroundColor = "white";
|
|
1791
|
+
});
|
|
1792
|
+
if (item.icon) {
|
|
1793
|
+
const iconSpan = document.createElement("span");
|
|
1794
|
+
iconSpan.style.cssText = `
|
|
1795
|
+
margin-right: 12px;
|
|
1796
|
+
font-size: 16px;
|
|
1797
|
+
`;
|
|
1798
|
+
iconSpan.innerText = item.icon;
|
|
1799
|
+
optionItem.appendChild(iconSpan);
|
|
1800
|
+
}
|
|
1801
|
+
const labelSpan = document.createElement("span");
|
|
1802
|
+
labelSpan.style.cssText = `
|
|
1803
|
+
color: black;
|
|
1804
|
+
`;
|
|
1805
|
+
labelSpan.innerText = item.label;
|
|
1806
|
+
optionItem.appendChild(labelSpan);
|
|
1807
|
+
optionItem.addEventListener("click", () => {
|
|
1808
|
+
this.hideActionSheetOverlay();
|
|
1809
|
+
const optionId = item.id !== void 0 ? item.id : index;
|
|
1810
|
+
resolve(optionId);
|
|
1811
|
+
});
|
|
1812
|
+
optionsContainer.appendChild(optionItem);
|
|
1813
|
+
});
|
|
1814
|
+
actionSheet.appendChild(optionsContainer);
|
|
1815
|
+
if (!options?.disableCancel) {
|
|
1816
|
+
const cancelButton = document.createElement("div");
|
|
1817
|
+
cancelButton.style.cssText = `
|
|
1818
|
+
padding: 14px 16px;
|
|
1819
|
+
text-align: center;
|
|
1820
|
+
font-weight: bold;
|
|
1821
|
+
cursor: pointer;
|
|
1822
|
+
color: #3b82f6;
|
|
1823
|
+
border-top: 1px solid #eaeaea;
|
|
1824
|
+
`;
|
|
1825
|
+
cancelButton.innerText = options?.cancelButtonText || "Cancel";
|
|
1826
|
+
cancelButton.addEventListener("click", () => {
|
|
1827
|
+
this.hideActionSheetOverlay();
|
|
1828
|
+
resolve(null);
|
|
1829
|
+
});
|
|
1830
|
+
actionSheet.appendChild(cancelButton);
|
|
1831
|
+
}
|
|
1832
|
+
if (!options?.disableCancel) {
|
|
1833
|
+
const closeButton = document.createElement("div");
|
|
1834
|
+
closeButton.style.cssText = `
|
|
1835
|
+
position: absolute;
|
|
1836
|
+
top: 8px;
|
|
1837
|
+
right: 8px;
|
|
1838
|
+
width: 24px;
|
|
1839
|
+
height: 24px;
|
|
1840
|
+
border-radius: 12px;
|
|
1841
|
+
background-color: rgba(0,0,0,0.1);
|
|
1842
|
+
color: #666;
|
|
1843
|
+
display: flex;
|
|
1844
|
+
align-items: center;
|
|
1845
|
+
justify-content: center;
|
|
1846
|
+
cursor: pointer;
|
|
1847
|
+
font-size: 14px;
|
|
1848
|
+
`;
|
|
1849
|
+
closeButton.innerText = "\u2715";
|
|
1850
|
+
closeButton.addEventListener("click", () => {
|
|
1851
|
+
this.hideActionSheetOverlay();
|
|
1852
|
+
resolve(null);
|
|
1853
|
+
});
|
|
1854
|
+
actionSheet.appendChild(closeButton);
|
|
1855
|
+
overlay.actionSheetOverlay.appendChild(actionSheet);
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
hideActionSheetOverlay() {
|
|
1860
|
+
const overlay = this._overlay;
|
|
1861
|
+
if (overlay.actionSheetOverlay) {
|
|
1862
|
+
overlay.actionSheetOverlay.style.display = "none";
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
|
|
1867
|
+
// src/Host.ts
|
|
1868
|
+
async function createHost(venusApi, isMock) {
|
|
1869
|
+
if (isMock) {
|
|
1870
|
+
if (import.meta.env?.DEV && isSandboxEnabled()) {
|
|
1871
|
+
const { SandboxHost } = await import('./SandboxHost-JNX5UBGL.js');
|
|
1872
|
+
return new SandboxHost(venusApi);
|
|
1873
|
+
}
|
|
1874
|
+
return new MockHost(venusApi);
|
|
1875
|
+
} else {
|
|
1876
|
+
return new RemoteHost(venusApi);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
// src/social/index.ts
|
|
1881
|
+
function initializeSocial(venusApi, host) {
|
|
1882
|
+
venusApi.social = host.social;
|
|
1883
|
+
venusApi.getLaunchParams = () => {
|
|
1884
|
+
return venusApi.launchParams || {};
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
export { HASH_ALGORITHM_NODE, HASH_ALGORITHM_WEB_CRYPTO, MockLeaderboardApi, RemoteHost, RpcClient, RpcLeaderboardApi, RpcSimulationApi, RpcSocialApi, SDK_VERSION, computeScoreHash, createHost, initializeLeaderboard, initializeSimulation, initializeSocial };
|
|
1889
|
+
//# sourceMappingURL=chunk-DJ3WT3FA.js.map
|
|
1890
|
+
//# sourceMappingURL=chunk-DJ3WT3FA.js.map
|