@series-inc/venus-sdk 3.1.1-beta.0 → 3.1.1
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-meVfUcZy.d.mts → AdsApi-BV_VKgMO.d.mts} +467 -269
- package/dist/{AdsApi-meVfUcZy.d.ts → AdsApi-BV_VKgMO.d.ts} +467 -269
- package/dist/{chunk-EMVTVSGL.mjs → chunk-FTIFUYDL.mjs} +978 -1412
- package/dist/chunk-FTIFUYDL.mjs.map +1 -0
- package/dist/chunk-NSSMTXJJ.mjs +7 -0
- package/dist/{chunk-2PDL7CQK.mjs.map → chunk-NSSMTXJJ.mjs.map} +1 -1
- package/dist/chunk-UXY5CKKG.mjs +12 -0
- package/dist/chunk-UXY5CKKG.mjs.map +1 -0
- package/dist/{core-5JLON75E.mjs → core-62LWDHN7.mjs} +3 -3
- package/dist/{core-5JLON75E.mjs.map → core-62LWDHN7.mjs.map} +1 -1
- package/dist/index.cjs +1018 -1783
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +142 -68
- package/dist/index.d.ts +142 -68
- package/dist/index.mjs +3 -7
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +1091 -1883
- package/dist/venus-api/index.cjs.map +1 -1
- package/dist/venus-api/index.d.mts +2 -2
- package/dist/venus-api/index.d.ts +2 -2
- package/dist/venus-api/index.mjs +76 -418
- package/dist/venus-api/index.mjs.map +1 -1
- package/dist/vite/index.cjs.map +1 -1
- package/dist/vite/index.mjs.map +1 -1
- package/dist/webview/index.cjs +4 -335
- package/dist/webview/index.cjs.map +1 -1
- package/dist/webview/index.d.mts +7 -9
- package/dist/webview/index.d.ts +7 -9
- package/dist/webview/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-2PDL7CQK.mjs +0 -26
- package/dist/chunk-EMVTVSGL.mjs.map +0 -1
- package/dist/chunk-IZLOB7DV.mjs +0 -343
- package/dist/chunk-IZLOB7DV.mjs.map +0 -1
|
@@ -1,220 +1,5 @@
|
|
|
1
1
|
import { createMockDelay, MOCK_DELAYS, isWebPlatform } from './chunk-QABXMFND.mjs';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// src/rooms/VenusRoom.ts
|
|
5
|
-
var VenusRoom;
|
|
6
|
-
var init_VenusRoom = __esm({
|
|
7
|
-
"src/rooms/VenusRoom.ts"() {
|
|
8
|
-
VenusRoom = class {
|
|
9
|
-
constructor(roomData) {
|
|
10
|
-
__publicField(this, "id");
|
|
11
|
-
__publicField(this, "name");
|
|
12
|
-
__publicField(this, "players");
|
|
13
|
-
__publicField(this, "maxPlayers");
|
|
14
|
-
__publicField(this, "gameType");
|
|
15
|
-
__publicField(this, "appId");
|
|
16
|
-
__publicField(this, "type");
|
|
17
|
-
__publicField(this, "createdBy");
|
|
18
|
-
__publicField(this, "createdAt");
|
|
19
|
-
__publicField(this, "updatedAt");
|
|
20
|
-
__publicField(this, "isPrivate");
|
|
21
|
-
__publicField(this, "currentPlayers");
|
|
22
|
-
__publicField(this, "status");
|
|
23
|
-
__publicField(this, "customMetadata");
|
|
24
|
-
__publicField(this, "admins");
|
|
25
|
-
__publicField(this, "roomCode");
|
|
26
|
-
__publicField(this, "description");
|
|
27
|
-
__publicField(this, "data");
|
|
28
|
-
__publicField(this, "version");
|
|
29
|
-
__publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
30
|
-
this.id = roomData.id;
|
|
31
|
-
this.name = roomData.name;
|
|
32
|
-
this.players = roomData.currentPlayers || [];
|
|
33
|
-
this.maxPlayers = roomData.maxPlayers;
|
|
34
|
-
this.gameType = roomData.gameType;
|
|
35
|
-
this.appId = roomData.appId;
|
|
36
|
-
this.type = roomData.type;
|
|
37
|
-
this.createdBy = roomData.createdBy;
|
|
38
|
-
this.createdAt = roomData.createdAt;
|
|
39
|
-
this.updatedAt = roomData.updatedAt;
|
|
40
|
-
this.isPrivate = roomData.isPrivate;
|
|
41
|
-
this.currentPlayers = roomData.currentPlayers || [];
|
|
42
|
-
this.status = roomData.status;
|
|
43
|
-
this.customMetadata = roomData.customMetadata || {};
|
|
44
|
-
this.admins = roomData.admins || [];
|
|
45
|
-
this.roomCode = roomData.roomCode;
|
|
46
|
-
this.description = roomData.description;
|
|
47
|
-
this.data = roomData.data || {};
|
|
48
|
-
this.version = roomData.version;
|
|
49
|
-
console.log(`VenusRoom: Created room object for ${this.id}`, {
|
|
50
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
51
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
52
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
53
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
updateFromRoomData(newRoomData) {
|
|
57
|
-
if (newRoomData.id === this.id) {
|
|
58
|
-
this.name = newRoomData.name || this.name;
|
|
59
|
-
this.players = newRoomData.currentPlayers || this.players;
|
|
60
|
-
this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
|
|
61
|
-
this.gameType = newRoomData.gameType || this.gameType;
|
|
62
|
-
this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
|
|
63
|
-
this.customMetadata = newRoomData.customMetadata || this.customMetadata;
|
|
64
|
-
this.data = newRoomData.data || this.data;
|
|
65
|
-
this.status = newRoomData.status || this.status;
|
|
66
|
-
this.updatedAt = newRoomData.updatedAt || this.updatedAt;
|
|
67
|
-
console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
|
|
68
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
69
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
70
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
71
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// src/rooms/RoomsApi.ts
|
|
80
|
-
var init_RoomsApi = __esm({
|
|
81
|
-
"src/rooms/RoomsApi.ts"() {
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// src/rooms/index.ts
|
|
86
|
-
var rooms_exports = {};
|
|
87
|
-
__export(rooms_exports, {
|
|
88
|
-
VenusRoom: () => VenusRoom,
|
|
89
|
-
initializeRoomsApi: () => initializeRoomsApi,
|
|
90
|
-
setupRoomNotifications: () => setupRoomNotifications
|
|
91
|
-
});
|
|
92
|
-
function bindMethod(target, targetKey, source, sourceKey) {
|
|
93
|
-
const key = sourceKey ?? targetKey;
|
|
94
|
-
const fn = source?.[key];
|
|
95
|
-
if (typeof fn === "function") {
|
|
96
|
-
target[targetKey] = fn.bind(source);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
function setupRoomNotifications(transport, getSubscriptions) {
|
|
102
|
-
console.log("[Venus Rooms] Setting up room notification listeners");
|
|
103
|
-
return transport.onVenusMessage((message) => {
|
|
104
|
-
const subscriptions = getSubscriptions();
|
|
105
|
-
if (!subscriptions) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (message.type === "H5_ROOM_DATA_UPDATED") {
|
|
109
|
-
const messageData = message.data;
|
|
110
|
-
const { roomId, roomData } = messageData;
|
|
111
|
-
if (!roomId) return;
|
|
112
|
-
const callbacks = subscriptions.data?.[roomId] || [];
|
|
113
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
114
|
-
console.log(`[Venus Rooms] \u{1F514} Room data updated for ${roomId}, notifying ${callbacks.length} callbacks`, roomData);
|
|
115
|
-
callbacks.forEach((callback) => {
|
|
116
|
-
try {
|
|
117
|
-
callback(roomData);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error("[Venus Rooms] Error in room data callback:", error);
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
allEventsCallbacks.forEach((callback) => {
|
|
124
|
-
try {
|
|
125
|
-
callback({ type: message.type, ...messageData });
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
|
|
133
|
-
const messageData = message.data;
|
|
134
|
-
const { roomId } = messageData;
|
|
135
|
-
if (!roomId) return;
|
|
136
|
-
const callbacks = subscriptions.messages?.[roomId] || [];
|
|
137
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
138
|
-
console.log(`[Venus Rooms] \u{1F514} Room message event for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
139
|
-
callbacks.forEach((callback) => {
|
|
140
|
-
try {
|
|
141
|
-
callback(messageData);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error("[Venus Rooms] Error in room message callback:", error);
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
allEventsCallbacks.forEach((callback) => {
|
|
148
|
-
try {
|
|
149
|
-
callback({ type: message.type, ...messageData });
|
|
150
|
-
} catch (error) {
|
|
151
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
if (message.type === "app:h5:proposedMoveValidationUpdated") {
|
|
157
|
-
const messageData = message.data;
|
|
158
|
-
const { roomId } = messageData;
|
|
159
|
-
if (!roomId) return;
|
|
160
|
-
const callbacks = subscriptions.gameEvents?.[roomId] || [];
|
|
161
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
162
|
-
console.log(`[Venus Rooms] \u{1F514} Proposed move validation updated for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
163
|
-
callbacks.forEach((callback) => {
|
|
164
|
-
try {
|
|
165
|
-
callback(messageData);
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.error("[Venus Rooms] Error in game event callback:", error);
|
|
168
|
-
throw error;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
allEventsCallbacks.forEach((callback) => {
|
|
172
|
-
try {
|
|
173
|
-
callback({ type: message.type, ...messageData });
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function initializeRoomsApi(venusApi, host) {
|
|
183
|
-
const roomsApi = host?.rooms;
|
|
184
|
-
if (!roomsApi) {
|
|
185
|
-
console.warn(
|
|
186
|
-
"[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
|
|
187
|
-
);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const venus = venusApi;
|
|
191
|
-
const existingNamespace = venus.rooms || {};
|
|
192
|
-
const roomsNamespace = Object.assign({}, existingNamespace);
|
|
193
|
-
const namespaceBindings = [
|
|
194
|
-
["create", "createRoom"],
|
|
195
|
-
["joinOrCreate", "joinOrCreateRoom"],
|
|
196
|
-
["joinByCode", "joinRoomByCode"],
|
|
197
|
-
["list", "getUserRooms"],
|
|
198
|
-
["subscribeToRoom", "subscribe"],
|
|
199
|
-
["updateRoomData", "updateData"],
|
|
200
|
-
["getRoomData", "getData"],
|
|
201
|
-
["sendRoomMessage", "sendMessage"],
|
|
202
|
-
["leaveRoom", "leave"],
|
|
203
|
-
["startRoomGame", "startGame"],
|
|
204
|
-
["proposeMove"],
|
|
205
|
-
["validateMove"]
|
|
206
|
-
];
|
|
207
|
-
namespaceBindings.forEach(([targetKey, sourceKey]) => {
|
|
208
|
-
bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
|
|
209
|
-
});
|
|
210
|
-
venus.rooms = roomsNamespace;
|
|
211
|
-
}
|
|
212
|
-
var init_rooms = __esm({
|
|
213
|
-
"src/rooms/index.ts"() {
|
|
214
|
-
init_RoomsApi();
|
|
215
|
-
init_VenusRoom();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
2
|
+
import { __publicField } from './chunk-NSSMTXJJ.mjs';
|
|
218
3
|
|
|
219
4
|
// src/VenusMessageId.ts
|
|
220
5
|
var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
@@ -262,10 +47,6 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
262
47
|
VenusMessageId2["CONFIRM_DIALOG"] = "H5_CONFIRM_DIALOG";
|
|
263
48
|
VenusMessageId2["ACTION_SHEET_SHOW"] = "H5_ACTION_SHEET_SHOW";
|
|
264
49
|
VenusMessageId2["REQUEST_SERVER_TIME"] = "H5_REQUEST_SERVER_TIME";
|
|
265
|
-
VenusMessageId2["GET_POST_INTERACTIONS"] = "H5_GET_POST_INTERACTIONS";
|
|
266
|
-
VenusMessageId2["TOGGLE_LIKE"] = "H5_TOGGLE_LIKE";
|
|
267
|
-
VenusMessageId2["OPEN_COMMENTS"] = "H5_OPEN_COMMENTS";
|
|
268
|
-
VenusMessageId2["TOGGLE_FOLLOW"] = "H5_TOGGLE_FOLLOW";
|
|
269
50
|
VenusMessageId2["SHARE_LINK"] = "H5_SHARE_LINK";
|
|
270
51
|
VenusMessageId2["CREATE_SHARE_QRCODE"] = "H5_CREATE_SHARE_QRCODE";
|
|
271
52
|
VenusMessageId2["AI_CHAT_COMPLETION"] = "H5_AI_CHAT_COMPLETION";
|
|
@@ -307,6 +88,9 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
307
88
|
VenusMessageId2["H5_SIMULATION_GET_AVAILABLE_ITEMS"] = "H5_SIMULATION_GET_AVAILABLE_ITEMS";
|
|
308
89
|
VenusMessageId2["H5_SIMULATION_VALIDATE_ASSIGNMENT"] = "H5_SIMULATION_VALIDATE_ASSIGNMENT";
|
|
309
90
|
VenusMessageId2["H5_SIMULATION_BATCH_OPERATIONS"] = "H5_SIMULATION_BATCH_OPERATIONS";
|
|
91
|
+
VenusMessageId2["H5_SIMULATION_SUBSCRIBE"] = "H5_SIMULATION_SUBSCRIBE";
|
|
92
|
+
VenusMessageId2["H5_SIMULATION_UNSUBSCRIBE"] = "H5_SIMULATION_UNSUBSCRIBE";
|
|
93
|
+
VenusMessageId2["H5_SIMULATION_UPDATE"] = "H5_SIMULATION_UPDATE";
|
|
310
94
|
VenusMessageId2["H5_LEADERBOARD_CREATE_SCORE_TOKEN"] = "H5_LEADERBOARD_CREATE_SCORE_TOKEN";
|
|
311
95
|
VenusMessageId2["H5_LEADERBOARD_SUBMIT_SCORE"] = "H5_LEADERBOARD_SUBMIT_SCORE";
|
|
312
96
|
VenusMessageId2["H5_LEADERBOARD_GET_PAGED_SCORES"] = "H5_LEADERBOARD_GET_PAGED_SCORES";
|
|
@@ -554,7 +338,7 @@ var MockAvatarApi = class {
|
|
|
554
338
|
async deleteAvatar() {
|
|
555
339
|
console.log(`[Venus Mock] Deleting avatar3d config`);
|
|
556
340
|
const venusApi = this._venusApi;
|
|
557
|
-
const currentProfile = venusApi.
|
|
341
|
+
const currentProfile = venusApi.getProfile();
|
|
558
342
|
const profileId = currentProfile?.id || "default_profile";
|
|
559
343
|
localStorage.removeItem(`venus-mock-avatar3d-${profileId}`);
|
|
560
344
|
console.log(
|
|
@@ -569,7 +353,7 @@ var MockAvatarApi = class {
|
|
|
569
353
|
console.log(`[Venus Mock] Loading shared avatar3d by ID: ${avatar3dId}`);
|
|
570
354
|
config = await this.selectAvatarConfig(avatar3dId, false);
|
|
571
355
|
} else {
|
|
572
|
-
const currentProfile = venusApi.
|
|
356
|
+
const currentProfile = venusApi.getProfile();
|
|
573
357
|
const profileId = currentProfile?.id || "default_profile";
|
|
574
358
|
console.log(`[Venus Mock] Loading avatar3d for profile: ${profileId}`);
|
|
575
359
|
console.log(
|
|
@@ -586,7 +370,7 @@ var MockAvatarApi = class {
|
|
|
586
370
|
async saveAvatar(config) {
|
|
587
371
|
console.log(`[Venus Mock] Saving avatar3d config:`, config);
|
|
588
372
|
const venusApi = this._venusApi;
|
|
589
|
-
const currentProfile = venusApi.
|
|
373
|
+
const currentProfile = venusApi.getProfile();
|
|
590
374
|
const profileId = currentProfile?.id || "default_profile";
|
|
591
375
|
localStorage.setItem(
|
|
592
376
|
`venus-mock-avatar3d-${profileId}`,
|
|
@@ -1117,9 +901,15 @@ var HostCdnApi = class {
|
|
|
1117
901
|
|
|
1118
902
|
// src/cdn/MockCdnApi.ts
|
|
1119
903
|
var MockCdnApi = class {
|
|
1120
|
-
constructor() {
|
|
1121
|
-
__publicField(this, "
|
|
1122
|
-
this.
|
|
904
|
+
constructor(venusApi) {
|
|
905
|
+
__publicField(this, "venusApi");
|
|
906
|
+
this.venusApi = venusApi;
|
|
907
|
+
}
|
|
908
|
+
get baseUrl() {
|
|
909
|
+
return this.venusApi._mock?.cdnBaseUrl ?? "https://venus-static-01293ak.web.app/";
|
|
910
|
+
}
|
|
911
|
+
get forceRemoteCdn() {
|
|
912
|
+
return this.venusApi._mock?.cdnForceRemote ?? false;
|
|
1123
913
|
}
|
|
1124
914
|
async fetchBlob(path, options) {
|
|
1125
915
|
const controller = new AbortController();
|
|
@@ -1156,6 +946,10 @@ var MockCdnApi = class {
|
|
|
1156
946
|
return subPath;
|
|
1157
947
|
}
|
|
1158
948
|
const cleanSubPath = subPath.startsWith("/") ? subPath.slice(1) : subPath;
|
|
949
|
+
const isLocalhost = typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1");
|
|
950
|
+
if (isLocalhost && !this.forceRemoteCdn) {
|
|
951
|
+
return `/${cleanSubPath}`;
|
|
952
|
+
}
|
|
1159
953
|
const pathParts = cleanSubPath.split("/");
|
|
1160
954
|
const encodedParts = pathParts.map((part, index) => {
|
|
1161
955
|
return index === pathParts.length - 1 ? encodeURIComponent(part) : part;
|
|
@@ -1277,6 +1071,212 @@ function initializeCdn(venusApi, host) {
|
|
|
1277
1071
|
venusApi.cdn = host.cdn;
|
|
1278
1072
|
}
|
|
1279
1073
|
|
|
1074
|
+
// src/device/HostDeviceApi.ts
|
|
1075
|
+
var HostDeviceApi = class {
|
|
1076
|
+
constructor(venusApi) {
|
|
1077
|
+
__publicField(this, "venusApi");
|
|
1078
|
+
this.venusApi = venusApi;
|
|
1079
|
+
}
|
|
1080
|
+
getDevice() {
|
|
1081
|
+
const device = this.venusApi._deviceData;
|
|
1082
|
+
if (!device) {
|
|
1083
|
+
throw new Error(
|
|
1084
|
+
"[Venus SDK] Device info not available. You must await VenusAPI.initializeAsync() before calling getDevice(). INIT_SDK has not completed."
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
return device;
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// src/device/MockDeviceApi.ts
|
|
1092
|
+
var MockDeviceApi = class {
|
|
1093
|
+
constructor(venusApi) {
|
|
1094
|
+
__publicField(this, "venusApi");
|
|
1095
|
+
this.venusApi = venusApi;
|
|
1096
|
+
}
|
|
1097
|
+
getDevice() {
|
|
1098
|
+
const width = typeof window !== "undefined" ? window.innerWidth : 400;
|
|
1099
|
+
const height = typeof window !== "undefined" ? window.innerHeight : 800;
|
|
1100
|
+
return {
|
|
1101
|
+
screenSize: { width, height },
|
|
1102
|
+
viewportSize: {
|
|
1103
|
+
width: width - 20,
|
|
1104
|
+
// account for safe area
|
|
1105
|
+
height: height - 20
|
|
1106
|
+
},
|
|
1107
|
+
orientation: width > height ? "landscape" : "portrait",
|
|
1108
|
+
pixelRatio: typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1,
|
|
1109
|
+
fontScale: 1,
|
|
1110
|
+
deviceType: width > 768 ? "tablet" : "phone",
|
|
1111
|
+
hapticsEnabled: false,
|
|
1112
|
+
haptics: { supported: false, enabled: false }
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
// src/environment/HostEnvironmentApi.ts
|
|
1118
|
+
var HostEnvironmentApi = class {
|
|
1119
|
+
constructor(venusApi) {
|
|
1120
|
+
__publicField(this, "venusApi");
|
|
1121
|
+
this.venusApi = venusApi;
|
|
1122
|
+
}
|
|
1123
|
+
getEnvironment() {
|
|
1124
|
+
const environment = this.venusApi._environmentData;
|
|
1125
|
+
if (!environment) {
|
|
1126
|
+
throw new Error(
|
|
1127
|
+
"[Venus SDK] Environment info not available. You must await VenusAPI.initializeAsync() before calling getEnvironment(). INIT_SDK has not completed."
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
return environment;
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
// src/environment/MockEnvironmentApi.ts
|
|
1135
|
+
var MockEnvironmentApi = class {
|
|
1136
|
+
constructor(venusApi) {
|
|
1137
|
+
__publicField(this, "venusApi");
|
|
1138
|
+
this.venusApi = venusApi;
|
|
1139
|
+
}
|
|
1140
|
+
getEnvironment() {
|
|
1141
|
+
const getBrowser = () => {
|
|
1142
|
+
if (typeof navigator === "undefined") return "unknown";
|
|
1143
|
+
const userAgent = navigator.userAgent;
|
|
1144
|
+
if (/chrome|chromium|crios/i.test(userAgent)) return "chrome";
|
|
1145
|
+
if (/firefox|fxios/i.test(userAgent)) return "firefox";
|
|
1146
|
+
if (/safari/i.test(userAgent)) return "safari";
|
|
1147
|
+
if (/edg/i.test(userAgent)) return "edge";
|
|
1148
|
+
if (/opera|opr/i.test(userAgent)) return "opera";
|
|
1149
|
+
return "unknown";
|
|
1150
|
+
};
|
|
1151
|
+
return {
|
|
1152
|
+
isDevelopment: true,
|
|
1153
|
+
platform: "web",
|
|
1154
|
+
platformVersion: "mock-1.0",
|
|
1155
|
+
browserInfo: {
|
|
1156
|
+
browser: getBrowser(),
|
|
1157
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "mock-agent",
|
|
1158
|
+
isMobile: typeof navigator !== "undefined" ? /Mobi|Android/i.test(navigator.userAgent) : false,
|
|
1159
|
+
isTablet: typeof navigator !== "undefined" ? /iPad|Tablet|Pad/i.test(navigator.userAgent) : false,
|
|
1160
|
+
language: typeof navigator !== "undefined" ? navigator.language || "en-US" : "en-US"
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
// src/system/HostSystemApi.ts
|
|
1167
|
+
var HostSystemApi = class {
|
|
1168
|
+
constructor(deviceApi, environmentApi, venusApi) {
|
|
1169
|
+
__publicField(this, "deviceApi");
|
|
1170
|
+
__publicField(this, "environmentApi");
|
|
1171
|
+
__publicField(this, "venusApi");
|
|
1172
|
+
this.deviceApi = deviceApi;
|
|
1173
|
+
this.environmentApi = environmentApi;
|
|
1174
|
+
this.venusApi = venusApi;
|
|
1175
|
+
}
|
|
1176
|
+
getDevice() {
|
|
1177
|
+
return this.deviceApi.getDevice();
|
|
1178
|
+
}
|
|
1179
|
+
getEnvironment() {
|
|
1180
|
+
return this.environmentApi.getEnvironment();
|
|
1181
|
+
}
|
|
1182
|
+
getSafeArea() {
|
|
1183
|
+
const safeArea = this.venusApi._safeAreaData;
|
|
1184
|
+
if (!safeArea) {
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
"[Venus SDK] getSafeArea() called before initialization. Call VenusAPI.initializeAsync() first."
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
return { ...safeArea };
|
|
1190
|
+
}
|
|
1191
|
+
isMobile() {
|
|
1192
|
+
const environment = this.environmentApi.getEnvironment();
|
|
1193
|
+
if (environment.platform === "ios" || environment.platform === "android") {
|
|
1194
|
+
return true;
|
|
1195
|
+
}
|
|
1196
|
+
if (environment.browserInfo) {
|
|
1197
|
+
return environment.browserInfo.isMobile;
|
|
1198
|
+
}
|
|
1199
|
+
return true;
|
|
1200
|
+
}
|
|
1201
|
+
isWeb() {
|
|
1202
|
+
const environment = this.environmentApi.getEnvironment();
|
|
1203
|
+
if (environment.platform === "web") {
|
|
1204
|
+
return true;
|
|
1205
|
+
}
|
|
1206
|
+
if (environment.browserInfo && !environment.browserInfo.isMobile) {
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
// src/system/MockSystemApi.ts
|
|
1214
|
+
var MockSystemApi = class {
|
|
1215
|
+
constructor(deviceApi, environmentApi, venusApi) {
|
|
1216
|
+
__publicField(this, "deviceApi");
|
|
1217
|
+
__publicField(this, "environmentApi");
|
|
1218
|
+
__publicField(this, "venusApi");
|
|
1219
|
+
this.deviceApi = deviceApi;
|
|
1220
|
+
this.environmentApi = environmentApi;
|
|
1221
|
+
this.venusApi = venusApi;
|
|
1222
|
+
}
|
|
1223
|
+
getDevice() {
|
|
1224
|
+
return this.deviceApi.getDevice();
|
|
1225
|
+
}
|
|
1226
|
+
getEnvironment() {
|
|
1227
|
+
return this.environmentApi.getEnvironment();
|
|
1228
|
+
}
|
|
1229
|
+
getSafeArea() {
|
|
1230
|
+
const safeArea = this.venusApi._safeAreaData;
|
|
1231
|
+
if (!safeArea) {
|
|
1232
|
+
return {
|
|
1233
|
+
top: 0,
|
|
1234
|
+
right: 0,
|
|
1235
|
+
bottom: 34,
|
|
1236
|
+
left: 0
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
return { ...safeArea };
|
|
1240
|
+
}
|
|
1241
|
+
isMobile() {
|
|
1242
|
+
const environment = this.environmentApi.getEnvironment();
|
|
1243
|
+
if (environment.platform === "ios" || environment.platform === "android") {
|
|
1244
|
+
return true;
|
|
1245
|
+
}
|
|
1246
|
+
if (environment.browserInfo) {
|
|
1247
|
+
return environment.browserInfo.isMobile;
|
|
1248
|
+
}
|
|
1249
|
+
return true;
|
|
1250
|
+
}
|
|
1251
|
+
isWeb() {
|
|
1252
|
+
const environment = this.environmentApi.getEnvironment();
|
|
1253
|
+
if (environment.platform === "web") {
|
|
1254
|
+
return true;
|
|
1255
|
+
}
|
|
1256
|
+
if (environment.browserInfo && !environment.browserInfo.isMobile) {
|
|
1257
|
+
return true;
|
|
1258
|
+
}
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
// src/system/index.ts
|
|
1264
|
+
function initializeSystem(venusApi, host) {
|
|
1265
|
+
venusApi.system = host.system;
|
|
1266
|
+
venusApi.isMobile = () => {
|
|
1267
|
+
console.warn(
|
|
1268
|
+
"[Venus SDK] DEPRECATED: VenusAPI.isMobile() is deprecated. Use VenusAPI.system.isMobile() instead."
|
|
1269
|
+
);
|
|
1270
|
+
return host.system.isMobile();
|
|
1271
|
+
};
|
|
1272
|
+
venusApi.isWeb = () => {
|
|
1273
|
+
console.warn(
|
|
1274
|
+
"[Venus SDK] DEPRECATED: VenusAPI.isWeb() is deprecated. Use VenusAPI.system.isWeb() instead."
|
|
1275
|
+
);
|
|
1276
|
+
return host.system.isWeb();
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
1280
|
// src/features/RpcFeaturesApi.ts
|
|
1281
1281
|
var RpcFeaturesApi = class {
|
|
1282
1282
|
constructor(rcpClient) {
|
|
@@ -1759,13 +1759,8 @@ var MockNotificationsApi = class {
|
|
|
1759
1759
|
async cancelNotification(notificationId) {
|
|
1760
1760
|
const venusApi = this.venusApi;
|
|
1761
1761
|
if (isWebPlatform()) {
|
|
1762
|
-
console.log(
|
|
1763
|
-
"[Venus Mock] Cancel notification on web platform (simulated):",
|
|
1764
|
-
notificationId
|
|
1765
|
-
);
|
|
1766
1762
|
return true;
|
|
1767
1763
|
}
|
|
1768
|
-
console.log("[Venus Mock] Cancel local notification:", notificationId);
|
|
1769
1764
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1770
1765
|
if (venusApi._mock.scheduledNotifications && venusApi._mock.scheduledNotifications[notificationId]) {
|
|
1771
1766
|
delete venusApi._mock.scheduledNotifications[notificationId];
|
|
@@ -1775,12 +1770,8 @@ var MockNotificationsApi = class {
|
|
|
1775
1770
|
}
|
|
1776
1771
|
async getAllScheduledLocalNotifications() {
|
|
1777
1772
|
if (isWebPlatform()) {
|
|
1778
|
-
console.log(
|
|
1779
|
-
"[Venus Mock] Get notifications on web platform (returning empty list)"
|
|
1780
|
-
);
|
|
1781
1773
|
return [];
|
|
1782
1774
|
}
|
|
1783
|
-
console.log("[Venus Mock] Get all scheduled local notifications");
|
|
1784
1775
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1785
1776
|
const venusApi = this.venusApi;
|
|
1786
1777
|
const notifications = venusApi._mock.scheduledNotifications || {};
|
|
@@ -1788,10 +1779,8 @@ var MockNotificationsApi = class {
|
|
|
1788
1779
|
}
|
|
1789
1780
|
async isLocalNotificationsEnabled() {
|
|
1790
1781
|
if (isWebPlatform()) {
|
|
1791
|
-
console.log("[Venus Mock] Notifications not available on web platform");
|
|
1792
1782
|
return false;
|
|
1793
1783
|
}
|
|
1794
|
-
console.log("[Venus Mock] Check if local notifications are enabled");
|
|
1795
1784
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1796
1785
|
const venusApi = this.venusApi;
|
|
1797
1786
|
const isEnabled = venusApi._mock.notificationsEnabled !== false;
|
|
@@ -1800,9 +1789,6 @@ var MockNotificationsApi = class {
|
|
|
1800
1789
|
async scheduleAsync(title, body, seconds, notificationId, options) {
|
|
1801
1790
|
const { priority = 50, groupId, payload } = options || {};
|
|
1802
1791
|
if (isWebPlatform()) {
|
|
1803
|
-
console.log(
|
|
1804
|
-
"[Venus Mock] Notifications not supported on web platform, simulating success"
|
|
1805
|
-
);
|
|
1806
1792
|
console.info(
|
|
1807
1793
|
"\u{1F514} [Venus Mock] Notification would be scheduled:",
|
|
1808
1794
|
title || "Untitled",
|
|
@@ -1813,14 +1799,11 @@ var MockNotificationsApi = class {
|
|
|
1813
1799
|
const mockId = `mock-web-notification-${Date.now()}`;
|
|
1814
1800
|
return mockId;
|
|
1815
1801
|
}
|
|
1816
|
-
console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
|
|
1817
1802
|
const venusApi = this.venusApi;
|
|
1818
1803
|
if (!venusApi._mock.pendingRequests) {
|
|
1819
|
-
console.log("[Venus Mock] Initializing pendingRequests");
|
|
1820
1804
|
venusApi._mock.pendingRequests = {};
|
|
1821
1805
|
}
|
|
1822
1806
|
const requestId = Date.now().toString();
|
|
1823
|
-
console.log("[Venus Mock] Creating request with ID:", requestId);
|
|
1824
1807
|
return new Promise((resolve) => {
|
|
1825
1808
|
venusApi._mock.pendingRequests[requestId] = { resolve };
|
|
1826
1809
|
const id = notificationId || `mock-notification-${Date.now()}`;
|
|
@@ -1842,13 +1825,8 @@ var MockNotificationsApi = class {
|
|
|
1842
1825
|
async setLocalNotificationsEnabled(enabled) {
|
|
1843
1826
|
const venusApi = this.venusApi;
|
|
1844
1827
|
if (isWebPlatform()) {
|
|
1845
|
-
console.log(
|
|
1846
|
-
"[Venus Mock] Set notifications enabled on web platform (simulated):",
|
|
1847
|
-
enabled
|
|
1848
|
-
);
|
|
1849
1828
|
return true;
|
|
1850
1829
|
}
|
|
1851
|
-
console.log("[Venus Mock] Set local notifications enabled:", enabled);
|
|
1852
1830
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1853
1831
|
venusApi._mock.notificationsEnabled = enabled;
|
|
1854
1832
|
return enabled;
|
|
@@ -2073,16 +2051,20 @@ function initializePopups(venusApi, host) {
|
|
|
2073
2051
|
|
|
2074
2052
|
// src/profile/HostProfileApi.ts
|
|
2075
2053
|
var HostProfileApi = class {
|
|
2054
|
+
constructor(venusApi) {
|
|
2055
|
+
__publicField(this, "venusApi");
|
|
2056
|
+
this.venusApi = venusApi;
|
|
2057
|
+
}
|
|
2076
2058
|
getCurrentProfile() {
|
|
2077
|
-
const profile =
|
|
2059
|
+
const profile = this.venusApi._profileData;
|
|
2078
2060
|
if (!profile) {
|
|
2079
2061
|
throw new Error(
|
|
2080
|
-
"[Venus SDK]
|
|
2062
|
+
"[Venus SDK] Profile not available. You must await VenusAPI.initializeAsync() before calling getProfile(). INIT_SDK has not completed."
|
|
2081
2063
|
);
|
|
2082
2064
|
}
|
|
2083
2065
|
if (!profile.id || !profile.username) {
|
|
2084
2066
|
throw new Error(
|
|
2085
|
-
"[Venus SDK] INIT_SDK returned an incomplete profile (missing id/username). The host must supply
|
|
2067
|
+
"[Venus SDK] INIT_SDK returned an incomplete profile (missing id/username). The host must supply valid profile data."
|
|
2086
2068
|
);
|
|
2087
2069
|
}
|
|
2088
2070
|
return {
|
|
@@ -2096,6 +2078,10 @@ var HostProfileApi = class {
|
|
|
2096
2078
|
|
|
2097
2079
|
// src/profile/MockProfileApi.ts
|
|
2098
2080
|
var MockProfileApi = class {
|
|
2081
|
+
constructor(venusApi) {
|
|
2082
|
+
__publicField(this, "venusApi");
|
|
2083
|
+
this.venusApi = venusApi;
|
|
2084
|
+
}
|
|
2099
2085
|
getCurrentProfile() {
|
|
2100
2086
|
return {
|
|
2101
2087
|
id: "mock_profile_123",
|
|
@@ -2108,11 +2094,22 @@ var MockProfileApi = class {
|
|
|
2108
2094
|
|
|
2109
2095
|
// src/profile/index.ts
|
|
2110
2096
|
function initializeProfile(venusApi, host) {
|
|
2097
|
+
venusApi.getProfile = () => {
|
|
2098
|
+
return host.profile.getCurrentProfile();
|
|
2099
|
+
};
|
|
2111
2100
|
venusApi.getCurrentProfile = () => {
|
|
2101
|
+
console.warn(
|
|
2102
|
+
"[Venus SDK] DEPRECATED: VenusAPI.getCurrentProfile() is deprecated. Use VenusAPI.getProfile() instead. See migration guide: https://docs.venus.com/migration/profile-api"
|
|
2103
|
+
);
|
|
2112
2104
|
return host.profile.getCurrentProfile();
|
|
2113
2105
|
};
|
|
2114
2106
|
}
|
|
2115
2107
|
|
|
2108
|
+
// src/utils/idGenerator.ts
|
|
2109
|
+
function generateId() {
|
|
2110
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2116
2113
|
// src/rpc/RpcClient.ts
|
|
2117
2114
|
var RpcClient = class {
|
|
2118
2115
|
constructor() {
|
|
@@ -2155,7 +2152,7 @@ var RpcClient = class {
|
|
|
2155
2152
|
}
|
|
2156
2153
|
async call(method, args, timeout = 5e3) {
|
|
2157
2154
|
return new Promise((resolve, reject) => {
|
|
2158
|
-
const id =
|
|
2155
|
+
const id = generateId();
|
|
2159
2156
|
this.addPendingCall(id, resolve, reject);
|
|
2160
2157
|
const request = {
|
|
2161
2158
|
type: "rpc-request",
|
|
@@ -2192,9 +2189,6 @@ var RpcClient = class {
|
|
|
2192
2189
|
getPendingCall(id) {
|
|
2193
2190
|
return this.pendingCalls.get(id);
|
|
2194
2191
|
}
|
|
2195
|
-
generateId() {
|
|
2196
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
2197
|
-
}
|
|
2198
2192
|
handleRpcResponse(response) {
|
|
2199
2193
|
const pending = this.getPendingCall(response.id);
|
|
2200
2194
|
if (!pending) {
|
|
@@ -2216,50 +2210,470 @@ var RpcClient = class {
|
|
|
2216
2210
|
}
|
|
2217
2211
|
};
|
|
2218
2212
|
|
|
2219
|
-
// src/
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
this.
|
|
2248
|
-
this.
|
|
2213
|
+
// src/rooms/VenusRoom.ts
|
|
2214
|
+
var VenusRoom = class {
|
|
2215
|
+
constructor(roomData) {
|
|
2216
|
+
__publicField(this, "id");
|
|
2217
|
+
__publicField(this, "name");
|
|
2218
|
+
__publicField(this, "players");
|
|
2219
|
+
__publicField(this, "maxPlayers");
|
|
2220
|
+
__publicField(this, "gameType");
|
|
2221
|
+
__publicField(this, "appId");
|
|
2222
|
+
__publicField(this, "type");
|
|
2223
|
+
__publicField(this, "createdBy");
|
|
2224
|
+
__publicField(this, "createdAt");
|
|
2225
|
+
__publicField(this, "updatedAt");
|
|
2226
|
+
__publicField(this, "isPrivate");
|
|
2227
|
+
__publicField(this, "status");
|
|
2228
|
+
__publicField(this, "customMetadata");
|
|
2229
|
+
__publicField(this, "admins");
|
|
2230
|
+
__publicField(this, "roomCode");
|
|
2231
|
+
__publicField(this, "description");
|
|
2232
|
+
__publicField(this, "data");
|
|
2233
|
+
__publicField(this, "version");
|
|
2234
|
+
this.id = roomData.id;
|
|
2235
|
+
this.name = roomData.name;
|
|
2236
|
+
this.players = Array.isArray(roomData.currentPlayers) ? [...roomData.currentPlayers] : [];
|
|
2237
|
+
this.maxPlayers = roomData.maxPlayers;
|
|
2238
|
+
this.gameType = roomData.gameType;
|
|
2239
|
+
this.appId = roomData.appId;
|
|
2240
|
+
this.type = roomData.type;
|
|
2241
|
+
this.createdBy = roomData.createdBy;
|
|
2242
|
+
this.createdAt = roomData.createdAt;
|
|
2243
|
+
this.updatedAt = roomData.updatedAt;
|
|
2244
|
+
this.isPrivate = roomData.isPrivate;
|
|
2245
|
+
this.status = roomData.status;
|
|
2246
|
+
this.customMetadata = roomData.customMetadata || {};
|
|
2247
|
+
this.admins = Array.isArray(roomData.admins) ? [...roomData.admins] : [];
|
|
2248
|
+
this.roomCode = roomData.roomCode;
|
|
2249
|
+
this.description = roomData.description;
|
|
2250
|
+
this.data = roomData.data || {};
|
|
2251
|
+
this.version = roomData.version;
|
|
2249
2252
|
}
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2253
|
+
};
|
|
2254
|
+
|
|
2255
|
+
// src/rooms/setupRoomNotifications.ts
|
|
2256
|
+
function invokeCallbacks(callbacks, event, context) {
|
|
2257
|
+
callbacks.forEach((callback) => {
|
|
2258
|
+
try {
|
|
2259
|
+
callback(event);
|
|
2260
|
+
} catch (error) {
|
|
2261
|
+
console.error(`[Venus SDK] Error in ${context} callback:`, error);
|
|
2262
|
+
throw error;
|
|
2257
2263
|
}
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
const
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2266
|
+
function setupRoomNotifications(transport, getSubscriptions) {
|
|
2267
|
+
return transport.onVenusMessage((message) => {
|
|
2268
|
+
const subscriptions = getSubscriptions();
|
|
2269
|
+
if (!subscriptions) {
|
|
2270
|
+
return;
|
|
2271
|
+
}
|
|
2272
|
+
if (message.type === "H5_ROOM_DATA_UPDATED") {
|
|
2273
|
+
const messageData = message.data;
|
|
2274
|
+
const { roomId, roomData } = messageData;
|
|
2275
|
+
if (!roomId) return;
|
|
2276
|
+
const callbacks = subscriptions.data[roomId] || [];
|
|
2277
|
+
const event = {
|
|
2278
|
+
type: "H5_ROOM_DATA_UPDATED",
|
|
2279
|
+
roomId,
|
|
2280
|
+
roomData,
|
|
2281
|
+
timestamp: messageData.timestamp
|
|
2282
|
+
};
|
|
2283
|
+
invokeCallbacks(callbacks, event, "room data");
|
|
2284
|
+
}
|
|
2285
|
+
if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
|
|
2286
|
+
const messageData = message.data;
|
|
2287
|
+
const { roomId } = messageData;
|
|
2288
|
+
if (!roomId) return;
|
|
2289
|
+
const callbacks = subscriptions.messages[roomId] || [];
|
|
2290
|
+
const event = {
|
|
2291
|
+
type: message.type,
|
|
2292
|
+
roomId,
|
|
2293
|
+
message: messageData.message,
|
|
2294
|
+
timestamp: messageData.timestamp
|
|
2295
|
+
};
|
|
2296
|
+
invokeCallbacks(callbacks, event, "room message");
|
|
2297
|
+
}
|
|
2298
|
+
if (message.type === "app:h5:proposedMoveValidationUpdated") {
|
|
2299
|
+
const messageData = message.data;
|
|
2300
|
+
const { roomId } = messageData;
|
|
2301
|
+
if (!roomId) return;
|
|
2302
|
+
const callbacks = subscriptions.gameEvents[roomId] || [];
|
|
2303
|
+
const event = {
|
|
2304
|
+
type: "app:h5:proposedMoveValidationUpdated",
|
|
2305
|
+
roomId,
|
|
2306
|
+
proposedMoveData: messageData.proposedMoveData,
|
|
2307
|
+
proposedMoveId: messageData.proposedMoveId,
|
|
2308
|
+
changeType: messageData.changeType,
|
|
2309
|
+
timestamp: messageData.timestamp
|
|
2310
|
+
};
|
|
2311
|
+
invokeCallbacks(callbacks, event, "game event");
|
|
2312
|
+
}
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// src/rooms/RpcRoomsApi.ts
|
|
2317
|
+
var RpcRoomsApi = class {
|
|
2318
|
+
constructor(rpcClient) {
|
|
2319
|
+
__publicField(this, "rpcClient");
|
|
2320
|
+
__publicField(this, "subscriptions");
|
|
2321
|
+
this.rpcClient = rpcClient;
|
|
2322
|
+
this.subscriptions = {
|
|
2323
|
+
data: {},
|
|
2324
|
+
messages: {},
|
|
2325
|
+
gameEvents: {}
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
2330
|
+
*/
|
|
2331
|
+
getSubscriptions() {
|
|
2332
|
+
return this.subscriptions;
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Set up room notification routing from the transport
|
|
2336
|
+
*/
|
|
2337
|
+
setupNotifications(transport) {
|
|
2338
|
+
setupRoomNotifications(transport, () => this.getSubscriptions());
|
|
2339
|
+
}
|
|
2340
|
+
async createRoomAsync(options) {
|
|
2341
|
+
const response = await this.rpcClient.call(
|
|
2342
|
+
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
2343
|
+
{
|
|
2344
|
+
options
|
|
2345
|
+
}
|
|
2346
|
+
);
|
|
2347
|
+
if (response.success === false) {
|
|
2348
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to create room";
|
|
2349
|
+
throw new Error(errorMessage);
|
|
2350
|
+
}
|
|
2351
|
+
const room = new VenusRoom(response.roomData);
|
|
2352
|
+
return room;
|
|
2353
|
+
}
|
|
2354
|
+
async joinOrCreateRoomAsync(options) {
|
|
2355
|
+
const response = await this.rpcClient.call(
|
|
2356
|
+
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
2357
|
+
{
|
|
2358
|
+
options
|
|
2359
|
+
}
|
|
2360
|
+
);
|
|
2361
|
+
if (response.success === false) {
|
|
2362
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to join or create room";
|
|
2363
|
+
throw new Error(errorMessage);
|
|
2364
|
+
}
|
|
2365
|
+
const room = new VenusRoom(response.value.roomData);
|
|
2366
|
+
return {
|
|
2367
|
+
action: response.value.action,
|
|
2368
|
+
room,
|
|
2369
|
+
playersJoined: response.value.playersJoined
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
async joinRoomByCodeAsync(roomCode) {
|
|
2373
|
+
const response = await this.rpcClient.call(
|
|
2374
|
+
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
2375
|
+
{
|
|
2376
|
+
roomCode
|
|
2377
|
+
}
|
|
2378
|
+
);
|
|
2379
|
+
if (response?.success === false) {
|
|
2380
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to join room by code";
|
|
2381
|
+
throw new Error(errorMessage);
|
|
2382
|
+
}
|
|
2383
|
+
const room = new VenusRoom(response.roomData);
|
|
2384
|
+
return room;
|
|
2385
|
+
}
|
|
2386
|
+
// Get user's rooms with optional filtering
|
|
2387
|
+
async getUserRoomsAsync(options = {}) {
|
|
2388
|
+
const response = await this.rpcClient.call(
|
|
2389
|
+
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
2390
|
+
{
|
|
2391
|
+
includeArchived: options.includeArchived ?? false
|
|
2392
|
+
}
|
|
2393
|
+
);
|
|
2394
|
+
if (response?.success === false) {
|
|
2395
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to get user rooms";
|
|
2396
|
+
throw new Error(errorMessage);
|
|
2397
|
+
}
|
|
2398
|
+
const venusRooms = [];
|
|
2399
|
+
for (const roomData of response.rooms) {
|
|
2400
|
+
if (!roomData.id) {
|
|
2401
|
+
console.warn("[Venus SDK] getUserRooms: Skipping room with missing ID:", roomData);
|
|
2402
|
+
continue;
|
|
2403
|
+
}
|
|
2404
|
+
try {
|
|
2405
|
+
const venusRoom = new VenusRoom(roomData);
|
|
2406
|
+
venusRooms.push(venusRoom);
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
console.warn(
|
|
2409
|
+
"[Venus SDK] getUserRooms: Failed to create VenusRoom object:",
|
|
2410
|
+
error,
|
|
2411
|
+
roomData
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
return venusRooms;
|
|
2416
|
+
}
|
|
2417
|
+
async updateRoomDataAsync(room, updates, options = {}) {
|
|
2418
|
+
const response = await this.rpcClient.call(
|
|
2419
|
+
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
2420
|
+
{
|
|
2421
|
+
roomId: room.id,
|
|
2422
|
+
updates,
|
|
2423
|
+
merge: options.merge ?? true
|
|
2424
|
+
}
|
|
2425
|
+
);
|
|
2426
|
+
if (response?.success === false) {
|
|
2427
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to update room data";
|
|
2428
|
+
throw new Error(errorMessage);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
async getRoomDataAsync(room) {
|
|
2432
|
+
const response = await this.rpcClient.call(
|
|
2433
|
+
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
2434
|
+
{
|
|
2435
|
+
roomId: room.id
|
|
2436
|
+
}
|
|
2437
|
+
);
|
|
2438
|
+
if (response?.success === false) {
|
|
2439
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to get room data";
|
|
2440
|
+
throw new Error(errorMessage);
|
|
2441
|
+
}
|
|
2442
|
+
return response.data;
|
|
2443
|
+
}
|
|
2444
|
+
async sendRoomMessageAsync(venusRoom, request) {
|
|
2445
|
+
const response = await this.rpcClient.call(
|
|
2446
|
+
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
2447
|
+
{
|
|
2448
|
+
roomId: venusRoom.id,
|
|
2449
|
+
message: request.message,
|
|
2450
|
+
metadata: request.metadata
|
|
2451
|
+
}
|
|
2452
|
+
);
|
|
2453
|
+
if (response?.success === false) {
|
|
2454
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to send message";
|
|
2455
|
+
throw new Error(errorMessage);
|
|
2456
|
+
}
|
|
2457
|
+
return response.messageId;
|
|
2458
|
+
}
|
|
2459
|
+
async leaveRoomAsync(room) {
|
|
2460
|
+
const response = await this.rpcClient.call(
|
|
2461
|
+
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
2462
|
+
{
|
|
2463
|
+
roomId: room.id
|
|
2464
|
+
}
|
|
2465
|
+
);
|
|
2466
|
+
if (response?.success === false) {
|
|
2467
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to leave room";
|
|
2468
|
+
throw new Error(errorMessage);
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
async startRoomGameAsync(room, options = {}) {
|
|
2472
|
+
const response = await this.rpcClient.call(
|
|
2473
|
+
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
2474
|
+
{
|
|
2475
|
+
roomId: room.id,
|
|
2476
|
+
gameConfig: options.gameConfig ?? {},
|
|
2477
|
+
turnOrder: options.turnOrder ?? null
|
|
2478
|
+
}
|
|
2479
|
+
);
|
|
2480
|
+
if (response?.success === false) {
|
|
2481
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to start game";
|
|
2482
|
+
throw new Error(errorMessage);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
async proposeMoveAsync(room, proposalPayload) {
|
|
2486
|
+
const response = await this.rpcClient.call(
|
|
2487
|
+
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
2488
|
+
{
|
|
2489
|
+
roomId: room.id,
|
|
2490
|
+
gameSpecificState: proposalPayload.gameSpecificState,
|
|
2491
|
+
moveType: proposalPayload.moveType,
|
|
2492
|
+
clientContext: proposalPayload.clientContext,
|
|
2493
|
+
clientProposalId: proposalPayload.clientProposalId
|
|
2494
|
+
}
|
|
2495
|
+
);
|
|
2496
|
+
if (response?.success === false) {
|
|
2497
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to propose move";
|
|
2498
|
+
throw new Error(errorMessage);
|
|
2499
|
+
}
|
|
2500
|
+
return response.data;
|
|
2501
|
+
}
|
|
2502
|
+
async validateMoveAsync(_room, moveId, verdict) {
|
|
2503
|
+
return {
|
|
2504
|
+
success: true,
|
|
2505
|
+
moveId,
|
|
2506
|
+
isValid: verdict.isValid,
|
|
2507
|
+
reason: verdict.reason
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
async subscribeAsync(room, options = {}) {
|
|
2511
|
+
const roomId = room.id;
|
|
2512
|
+
const existingData = this.subscriptions.data[roomId];
|
|
2513
|
+
const existingMessages = this.subscriptions.messages[roomId];
|
|
2514
|
+
const existingGameEvents = this.subscriptions.gameEvents[roomId];
|
|
2515
|
+
const subscribeToData = Boolean(options.onData) && (existingData?.length ?? 0) === 0;
|
|
2516
|
+
const subscribeToMessages = Boolean(options.onMessages) && (existingMessages?.length ?? 0) === 0;
|
|
2517
|
+
const subscribeToProposedMoves = Boolean(options.onGameEvents) && (existingGameEvents?.length ?? 0) === 0;
|
|
2518
|
+
if (subscribeToData || subscribeToMessages || subscribeToProposedMoves) {
|
|
2519
|
+
try {
|
|
2520
|
+
await this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
2521
|
+
roomId,
|
|
2522
|
+
subscribeToData,
|
|
2523
|
+
subscribeToMessages,
|
|
2524
|
+
subscribeToProposedMoves
|
|
2525
|
+
});
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
console.error("[Venus SDK] Failed to set up room subscription:", error);
|
|
2528
|
+
throw error;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
if (options.onData) {
|
|
2532
|
+
if (!this.subscriptions.data[roomId]) {
|
|
2533
|
+
this.subscriptions.data[roomId] = [];
|
|
2534
|
+
}
|
|
2535
|
+
this.subscriptions.data[roomId].push(options.onData);
|
|
2536
|
+
}
|
|
2537
|
+
if (options.onMessages) {
|
|
2538
|
+
if (!this.subscriptions.messages[roomId]) {
|
|
2539
|
+
this.subscriptions.messages[roomId] = [];
|
|
2540
|
+
}
|
|
2541
|
+
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
2542
|
+
}
|
|
2543
|
+
if (options.onGameEvents) {
|
|
2544
|
+
if (!this.subscriptions.gameEvents[roomId]) {
|
|
2545
|
+
this.subscriptions.gameEvents[roomId] = [];
|
|
2546
|
+
}
|
|
2547
|
+
this.subscriptions.gameEvents[roomId].push(options.onGameEvents);
|
|
2548
|
+
}
|
|
2549
|
+
let disposed = false;
|
|
2550
|
+
return () => {
|
|
2551
|
+
if (disposed) return;
|
|
2552
|
+
disposed = true;
|
|
2553
|
+
if (options.onData) {
|
|
2554
|
+
const callbacks = this.subscriptions.data[roomId];
|
|
2555
|
+
if (callbacks) {
|
|
2556
|
+
const index = callbacks.indexOf(options.onData);
|
|
2557
|
+
if (index > -1) {
|
|
2558
|
+
callbacks.splice(index, 1);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
if (options.onMessages) {
|
|
2563
|
+
const callbacks = this.subscriptions.messages[roomId];
|
|
2564
|
+
if (callbacks) {
|
|
2565
|
+
const index = callbacks.indexOf(options.onMessages);
|
|
2566
|
+
if (index > -1) {
|
|
2567
|
+
callbacks.splice(index, 1);
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
if (options.onGameEvents) {
|
|
2572
|
+
const callbacks = this.subscriptions.gameEvents[roomId];
|
|
2573
|
+
if (callbacks) {
|
|
2574
|
+
const index = callbacks.indexOf(options.onGameEvents);
|
|
2575
|
+
if (index > -1) {
|
|
2576
|
+
callbacks.splice(index, 1);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
const hasAnySubscriptions = (this.subscriptions.data[roomId]?.length ?? 0) > 0 || (this.subscriptions.messages[roomId]?.length ?? 0) > 0 || (this.subscriptions.gameEvents[roomId]?.length ?? 0) > 0;
|
|
2581
|
+
if (!hasAnySubscriptions) {
|
|
2582
|
+
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
2583
|
+
roomId
|
|
2584
|
+
}).catch((error) => {
|
|
2585
|
+
console.error("[Venus SDK] Failed to clean up room subscription:", error);
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2592
|
+
// src/rooms/index.ts
|
|
2593
|
+
function bindMethod(target, targetKey, source, sourceKey) {
|
|
2594
|
+
const key = sourceKey ?? targetKey;
|
|
2595
|
+
const fn = source?.[key];
|
|
2596
|
+
if (typeof fn === "function") {
|
|
2597
|
+
target[targetKey] = fn.bind(source);
|
|
2598
|
+
return true;
|
|
2599
|
+
}
|
|
2600
|
+
return false;
|
|
2601
|
+
}
|
|
2602
|
+
function initializeRoomsApi(venusApi, host) {
|
|
2603
|
+
const roomsApi = host?.rooms;
|
|
2604
|
+
if (!roomsApi) {
|
|
2605
|
+
console.warn(
|
|
2606
|
+
"[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
|
|
2607
|
+
);
|
|
2608
|
+
return;
|
|
2609
|
+
}
|
|
2610
|
+
const venus = venusApi;
|
|
2611
|
+
const existingNamespace = venus.rooms || {};
|
|
2612
|
+
const roomsNamespace = Object.assign({}, existingNamespace);
|
|
2613
|
+
const namespaceBindings = [
|
|
2614
|
+
["createRoomAsync"],
|
|
2615
|
+
["joinOrCreateRoomAsync"],
|
|
2616
|
+
["joinRoomByCodeAsync"],
|
|
2617
|
+
["getUserRoomsAsync"],
|
|
2618
|
+
["subscribeAsync"],
|
|
2619
|
+
["updateRoomDataAsync"],
|
|
2620
|
+
["getRoomDataAsync"],
|
|
2621
|
+
["sendRoomMessageAsync"],
|
|
2622
|
+
["leaveRoomAsync"],
|
|
2623
|
+
["startRoomGameAsync"],
|
|
2624
|
+
["proposeMoveAsync"],
|
|
2625
|
+
["validateMoveAsync"]
|
|
2626
|
+
];
|
|
2627
|
+
namespaceBindings.forEach(([targetKey, sourceKey]) => {
|
|
2628
|
+
bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
|
|
2629
|
+
});
|
|
2630
|
+
venus.rooms = roomsNamespace;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
// src/storage/MockStorageApi.ts
|
|
2634
|
+
function createMockStorageApi(storageType, appUrl) {
|
|
2635
|
+
const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
|
|
2636
|
+
let prefix;
|
|
2637
|
+
let syncDelay = 0;
|
|
2638
|
+
switch (storageType) {
|
|
2639
|
+
case "deviceCache":
|
|
2640
|
+
prefix = "venus:app";
|
|
2641
|
+
syncDelay = 0;
|
|
2642
|
+
break;
|
|
2643
|
+
case "appStorage":
|
|
2644
|
+
prefix = "venus:app";
|
|
2645
|
+
syncDelay = 100;
|
|
2646
|
+
break;
|
|
2647
|
+
case "globalStorage":
|
|
2648
|
+
prefix = "venus:global";
|
|
2649
|
+
syncDelay = 100;
|
|
2650
|
+
break;
|
|
2651
|
+
default:
|
|
2652
|
+
throw new Error(`Unknown storage type: ${storageType}`);
|
|
2653
|
+
}
|
|
2654
|
+
prefix = storageType === "globalStorage" || !appIdentifier ? `${prefix}:` : `${prefix}:${appIdentifier}:`;
|
|
2655
|
+
return new MockStorageApi(prefix, syncDelay);
|
|
2656
|
+
}
|
|
2657
|
+
var MockStorageApi = class {
|
|
2658
|
+
constructor(prefix, syncDelay) {
|
|
2659
|
+
__publicField(this, "prefix");
|
|
2660
|
+
__publicField(this, "syncDelay");
|
|
2661
|
+
this.prefix = prefix;
|
|
2662
|
+
this.syncDelay = syncDelay;
|
|
2663
|
+
}
|
|
2664
|
+
async clear() {
|
|
2665
|
+
const fullLength = localStorage.length;
|
|
2666
|
+
for (let i = 0; i < fullLength; i++) {
|
|
2667
|
+
const fullKey = localStorage.key(i);
|
|
2668
|
+
if (fullKey && fullKey.startsWith(this.prefix)) {
|
|
2669
|
+
localStorage.removeItem(fullKey);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
await this.simulateSyncDelay();
|
|
2673
|
+
}
|
|
2674
|
+
async getAllItems() {
|
|
2675
|
+
const items = new Array();
|
|
2676
|
+
const fullLength = localStorage.length;
|
|
2263
2677
|
for (let i = 0; i < fullLength; i++) {
|
|
2264
2678
|
const fullKey = localStorage.key(i);
|
|
2265
2679
|
if (fullKey && fullKey.startsWith(this.prefix)) {
|
|
@@ -2449,24 +2863,20 @@ function initializeStorage(venusApiInstance, host) {
|
|
|
2449
2863
|
venusApiInstance.globalStorage = host.globalStorage;
|
|
2450
2864
|
}
|
|
2451
2865
|
|
|
2452
|
-
// src/simulation/utils.ts
|
|
2453
|
-
function sumContributions(contributions) {
|
|
2454
|
-
const totals = {};
|
|
2455
|
-
for (const profileId in contributions) {
|
|
2456
|
-
for (const entityId in contributions[profileId]) {
|
|
2457
|
-
const amount = contributions[profileId][entityId] || 0;
|
|
2458
|
-
totals[entityId] = (totals[entityId] || 0) + amount;
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
return totals;
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
2866
|
// src/simulation/RpcSimulationApi.ts
|
|
2465
2867
|
var RpcSimulationApi = class {
|
|
2466
2868
|
constructor(rpcClient) {
|
|
2467
2869
|
__publicField(this, "rpcClient");
|
|
2468
2870
|
__publicField(this, "_simulationConfig", null);
|
|
2871
|
+
__publicField(this, "subscriptionCallbacks", /* @__PURE__ */ new Map());
|
|
2469
2872
|
this.rpcClient = rpcClient;
|
|
2873
|
+
this.rpcClient.onNotification(
|
|
2874
|
+
"H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */,
|
|
2875
|
+
this.handleSimulationUpdate.bind(this)
|
|
2876
|
+
);
|
|
2877
|
+
}
|
|
2878
|
+
isEnabled() {
|
|
2879
|
+
return true;
|
|
2470
2880
|
}
|
|
2471
2881
|
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
2472
2882
|
return this.rpcClient.call(
|
|
@@ -2478,14 +2888,47 @@ var RpcSimulationApi = class {
|
|
|
2478
2888
|
}
|
|
2479
2889
|
);
|
|
2480
2890
|
}
|
|
2481
|
-
|
|
2482
|
-
|
|
2891
|
+
async subscribeAsync(options) {
|
|
2892
|
+
this.ensureValidSubscribeOptions(options);
|
|
2893
|
+
const subscriptionId = generateId();
|
|
2894
|
+
this.subscriptionCallbacks.set(subscriptionId, options.onUpdate);
|
|
2895
|
+
try {
|
|
2896
|
+
await this.rpcClient.call("H5_SIMULATION_SUBSCRIBE" /* H5_SIMULATION_SUBSCRIBE */, {
|
|
2897
|
+
subscriptionId,
|
|
2898
|
+
entities: options.entities,
|
|
2899
|
+
tags: options.tags,
|
|
2900
|
+
activeRuns: options.activeRuns,
|
|
2901
|
+
roomId: options.roomId
|
|
2902
|
+
});
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
2905
|
+
throw error;
|
|
2906
|
+
}
|
|
2907
|
+
let unsubscribed = false;
|
|
2908
|
+
return () => {
|
|
2909
|
+
if (unsubscribed) {
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
unsubscribed = true;
|
|
2913
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
2914
|
+
void this.rpcClient.call("H5_SIMULATION_UNSUBSCRIBE" /* H5_SIMULATION_UNSUBSCRIBE */, {
|
|
2915
|
+
subscriptionId
|
|
2916
|
+
}).catch((error) => {
|
|
2917
|
+
console.error(
|
|
2918
|
+
"[Venus SDK] Failed to unsubscribe simulation listener",
|
|
2919
|
+
error
|
|
2920
|
+
);
|
|
2921
|
+
});
|
|
2922
|
+
};
|
|
2483
2923
|
}
|
|
2484
2924
|
executeBatchOperationsAsync(operations, validateOnly) {
|
|
2485
|
-
return this.rpcClient.call(
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2925
|
+
return this.rpcClient.call(
|
|
2926
|
+
"H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */,
|
|
2927
|
+
{
|
|
2928
|
+
operations,
|
|
2929
|
+
validateOnly
|
|
2930
|
+
}
|
|
2931
|
+
);
|
|
2489
2932
|
}
|
|
2490
2933
|
async getAvailableItemsAsync(containerId, slotId) {
|
|
2491
2934
|
const response = await this.rpcClient.call(
|
|
@@ -2508,17 +2951,23 @@ var RpcSimulationApi = class {
|
|
|
2508
2951
|
);
|
|
2509
2952
|
}
|
|
2510
2953
|
assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
2511
|
-
return this.rpcClient.call(
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2954
|
+
return this.rpcClient.call(
|
|
2955
|
+
"H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */,
|
|
2956
|
+
{
|
|
2957
|
+
containerId,
|
|
2958
|
+
slotId,
|
|
2959
|
+
itemId
|
|
2960
|
+
}
|
|
2961
|
+
);
|
|
2516
2962
|
}
|
|
2517
2963
|
removeItemFromSlotAsync(containerId, slotId) {
|
|
2518
|
-
return this.rpcClient.call(
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2964
|
+
return this.rpcClient.call(
|
|
2965
|
+
"H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */,
|
|
2966
|
+
{
|
|
2967
|
+
containerId,
|
|
2968
|
+
slotId
|
|
2969
|
+
}
|
|
2970
|
+
);
|
|
2522
2971
|
}
|
|
2523
2972
|
async getSlotContainersAsync() {
|
|
2524
2973
|
const response = await this.rpcClient.call(
|
|
@@ -2543,7 +2992,6 @@ var RpcSimulationApi = class {
|
|
|
2543
2992
|
roomId
|
|
2544
2993
|
}
|
|
2545
2994
|
);
|
|
2546
|
-
console.log("[Venus SDK] getStateAsync", response);
|
|
2547
2995
|
if (response.configuration) {
|
|
2548
2996
|
this._simulationConfig = response.configuration;
|
|
2549
2997
|
}
|
|
@@ -2555,9 +3003,10 @@ var RpcSimulationApi = class {
|
|
|
2555
3003
|
}
|
|
2556
3004
|
const config = await this.rpcClient.call(
|
|
2557
3005
|
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
2558
|
-
{
|
|
3006
|
+
{
|
|
3007
|
+
roomId
|
|
3008
|
+
}
|
|
2559
3009
|
);
|
|
2560
|
-
console.log("[Venus SDK] getConfigAsync", config);
|
|
2561
3010
|
if (config) {
|
|
2562
3011
|
this._simulationConfig = config;
|
|
2563
3012
|
return config;
|
|
@@ -2565,14 +3014,17 @@ var RpcSimulationApi = class {
|
|
|
2565
3014
|
throw new Error("No simulation configuration available");
|
|
2566
3015
|
}
|
|
2567
3016
|
executeRecipeAsync(recipeId, inputs, options) {
|
|
2568
|
-
return this.rpcClient.call(
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
3017
|
+
return this.rpcClient.call(
|
|
3018
|
+
"H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */,
|
|
3019
|
+
{
|
|
3020
|
+
recipeId,
|
|
3021
|
+
inputs,
|
|
3022
|
+
roomId: options?.roomId,
|
|
3023
|
+
batchAmount: options?.batchAmount,
|
|
3024
|
+
allowPartialBatch: options?.allowPartialBatch,
|
|
3025
|
+
entity: options?.entity
|
|
3026
|
+
}
|
|
3027
|
+
);
|
|
2576
3028
|
}
|
|
2577
3029
|
collectRecipeAsync(runId) {
|
|
2578
3030
|
return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
|
|
@@ -2580,9 +3032,12 @@ var RpcSimulationApi = class {
|
|
|
2580
3032
|
});
|
|
2581
3033
|
}
|
|
2582
3034
|
getActiveRunsAsync(options) {
|
|
2583
|
-
return this.rpcClient.call(
|
|
2584
|
-
|
|
2585
|
-
|
|
3035
|
+
return this.rpcClient.call(
|
|
3036
|
+
"H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
|
|
3037
|
+
{
|
|
3038
|
+
roomId: options?.roomId
|
|
3039
|
+
}
|
|
3040
|
+
);
|
|
2586
3041
|
}
|
|
2587
3042
|
executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
2588
3043
|
return this.rpcClient.call(
|
|
@@ -2652,583 +3107,52 @@ var RpcSimulationApi = class {
|
|
|
2652
3107
|
);
|
|
2653
3108
|
return response.value;
|
|
2654
3109
|
}
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
if (typeof window === "undefined") return "unknown-app";
|
|
2660
|
-
const url = window.location.href;
|
|
2661
|
-
const match = url.match(/\/H5\/([^\/]+)/);
|
|
2662
|
-
return match ? match[1] : "unknown-app";
|
|
2663
|
-
}
|
|
2664
|
-
var MockSimulationApi = class {
|
|
2665
|
-
constructor(simulationConfig = null) {
|
|
2666
|
-
__publicField(this, "mockSimulationConfigs", /* @__PURE__ */ new Map());
|
|
2667
|
-
// appIdentifier -> config
|
|
2668
|
-
__publicField(this, "mockSimulationStates", /* @__PURE__ */ new Map());
|
|
2669
|
-
// appIdentifier -> config
|
|
2670
|
-
__publicField(this, "mockActiveTimers", /* @__PURE__ */ new Map());
|
|
2671
|
-
// appIdentifier -> timers[]
|
|
2672
|
-
__publicField(this, "appId");
|
|
2673
|
-
__publicField(this, "providedSimulationConfig");
|
|
2674
|
-
this.appId = generateAppIdentifier2();
|
|
2675
|
-
this.providedSimulationConfig = simulationConfig;
|
|
2676
|
-
}
|
|
2677
|
-
sumContributions(contributions) {
|
|
2678
|
-
return sumContributions(contributions);
|
|
2679
|
-
}
|
|
2680
|
-
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
2681
|
-
this.log("validateSlotAssignmentAsync called:", {
|
|
2682
|
-
containerId,
|
|
2683
|
-
slotId,
|
|
2684
|
-
itemId
|
|
2685
|
-
});
|
|
2686
|
-
return { valid: true, message: "Mock validation successful" };
|
|
2687
|
-
}
|
|
2688
|
-
async executeBatchOperationsAsync(operations, validateOnly) {
|
|
2689
|
-
this.log("executeBatchOperationsAsync called:", {
|
|
2690
|
-
operations,
|
|
2691
|
-
validateOnly
|
|
2692
|
-
});
|
|
2693
|
-
return {
|
|
2694
|
-
success: true,
|
|
2695
|
-
results: operations.map(() => ({ success: true }))
|
|
2696
|
-
};
|
|
2697
|
-
}
|
|
2698
|
-
async getAvailableItemsAsync(containerId, slotId) {
|
|
2699
|
-
console.log("[Venus Simulation Mock] getAvailableItemsAsync called:", {
|
|
2700
|
-
containerId,
|
|
2701
|
-
slotId
|
|
2702
|
-
});
|
|
2703
|
-
const appIdentifier = generateAppIdentifier2();
|
|
2704
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
2705
|
-
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
2706
|
-
entities: {}
|
|
2707
|
-
};
|
|
2708
|
-
const availableItems = Object.entries(config.entities).slice(0, 3).map(([entityId, entity]) => ({
|
|
2709
|
-
entityId,
|
|
2710
|
-
quantity: 1,
|
|
2711
|
-
metadata: entity.metadata,
|
|
2712
|
-
powerPreview: 100
|
|
2713
|
-
// Mock power value
|
|
2714
|
-
}));
|
|
2715
|
-
return availableItems;
|
|
2716
|
-
}
|
|
2717
|
-
async calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
2718
|
-
this.log("calculatePowerPreviewAsync called:", {
|
|
2719
|
-
containerId,
|
|
2720
|
-
slotId,
|
|
2721
|
-
candidateItemId
|
|
2722
|
-
});
|
|
2723
|
-
return {
|
|
2724
|
-
currentPower: 1e3,
|
|
2725
|
-
previewPower: 1200,
|
|
2726
|
-
powerDelta: 200,
|
|
2727
|
-
breakdown: { base: 800, weapon: 200, armor: 200 }
|
|
2728
|
-
};
|
|
2729
|
-
}
|
|
2730
|
-
async getSlotContainersAsync() {
|
|
2731
|
-
this.log("getSlotContainersAsync called");
|
|
2732
|
-
const appIdentifier = this.appId;
|
|
2733
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
2734
|
-
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
2735
|
-
entities: {}
|
|
2736
|
-
};
|
|
2737
|
-
const containers = Object.entries(config.entities).filter(([_, entity]) => entity.metadata?.slots).map(([entityId, entity]) => ({
|
|
2738
|
-
entityId,
|
|
2739
|
-
slots: entity.metadata?.slots,
|
|
2740
|
-
isOwned: true
|
|
2741
|
-
// Mock: assume all containers are owned
|
|
2742
|
-
}));
|
|
2743
|
-
return containers;
|
|
2744
|
-
}
|
|
2745
|
-
async getSlotAssignmentsAsync(containerId) {
|
|
2746
|
-
this.log("getSlotAssignmentsAsync called for:", containerId);
|
|
2747
|
-
return [];
|
|
2748
|
-
}
|
|
2749
|
-
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
2750
|
-
this.log("resolveFieldValueAsync called:", {
|
|
2751
|
-
entityId,
|
|
2752
|
-
fieldPath,
|
|
2753
|
-
entity
|
|
2754
|
-
});
|
|
2755
|
-
const mockValues = {
|
|
2756
|
-
basePower: 850,
|
|
2757
|
-
weaponPower: 300,
|
|
2758
|
-
armorPower: 150,
|
|
2759
|
-
total_power: 1300,
|
|
2760
|
-
total_defense_power: 5e3
|
|
2761
|
-
};
|
|
2762
|
-
return mockValues[fieldPath] || 100;
|
|
2763
|
-
}
|
|
2764
|
-
async getEntityMetadataAsync(entityId) {
|
|
2765
|
-
this.log("getEntityMetadataAsync called for:", entityId);
|
|
2766
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
2767
|
-
const appIdentifier = this.appId;
|
|
2768
|
-
const config = mockSimulationConfigs.get(
|
|
2769
|
-
appIdentifier
|
|
2770
|
-
) || {
|
|
2771
|
-
entities: {}};
|
|
2772
|
-
const entity = config.entities[entityId];
|
|
2773
|
-
return entity?.metadata || {};
|
|
2774
|
-
}
|
|
2775
|
-
async collectRecipeAsync(runId) {
|
|
2776
|
-
this.log("collectRecipeAsync called:", { runId });
|
|
2777
|
-
const mockRewards = {
|
|
2778
|
-
cash: Math.floor(Math.random() * 1e3) + 500,
|
|
2779
|
-
experience: Math.floor(Math.random() * 50) + 25
|
|
2780
|
-
};
|
|
2781
|
-
return {
|
|
2782
|
-
success: true,
|
|
2783
|
-
runId,
|
|
2784
|
-
rewards: mockRewards,
|
|
2785
|
-
message: "Rewards collected successfully"
|
|
2786
|
-
};
|
|
2787
|
-
}
|
|
2788
|
-
executeRecipeAsync(recipeId, inputs, options) {
|
|
2789
|
-
this.log("executeRecipeAsync called:", {
|
|
2790
|
-
recipeId,
|
|
2791
|
-
inputs,
|
|
2792
|
-
options
|
|
2793
|
-
});
|
|
2794
|
-
const appIdentifier = this.appId;
|
|
2795
|
-
return this.executeRecipe(appIdentifier, recipeId, inputs);
|
|
2796
|
-
}
|
|
2797
|
-
async executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
2798
|
-
this.log("executeScopedRecipeAsync called:", {
|
|
2799
|
-
recipeId,
|
|
2800
|
-
entity,
|
|
2801
|
-
inputs,
|
|
2802
|
-
roomId: options?.roomId,
|
|
2803
|
-
options
|
|
2804
|
-
});
|
|
2805
|
-
return {
|
|
2806
|
-
success: true,
|
|
2807
|
-
message: "Mock scoped recipe execution successful"
|
|
2808
|
-
};
|
|
2809
|
-
}
|
|
2810
|
-
async getActiveRunsAsync(options) {
|
|
2811
|
-
this.log("getActiveRunsAsync called:", options);
|
|
2812
|
-
const appIdentifier = this.appId;
|
|
2813
|
-
let state = this.mockSimulationStates.get(appIdentifier);
|
|
2814
|
-
if (!state) {
|
|
2815
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
2816
|
-
}
|
|
2817
|
-
return state.activeRuns || [];
|
|
2818
|
-
}
|
|
2819
|
-
async getAvailableRecipesAsync(options) {
|
|
2820
|
-
this.log("getAvailableRecipesAsync called:", options);
|
|
2821
|
-
const baseRecipes = [
|
|
2822
|
-
{ id: "collect_resources", scope: "player", clientViewable: true },
|
|
2823
|
-
{ id: "upgrade_equipment", scope: "player", clientViewable: true }
|
|
2824
|
-
];
|
|
2825
|
-
if (options?.roomId) {
|
|
2826
|
-
baseRecipes.push(
|
|
2827
|
-
{ id: "room_upgrade", scope: "room", clientViewable: true },
|
|
2828
|
-
{ id: "cooperative_project", scope: "room", clientViewable: true }
|
|
2829
|
-
);
|
|
3110
|
+
handleSimulationUpdate(notification) {
|
|
3111
|
+
if (!notification || !notification.subscriptionId) {
|
|
3112
|
+
console.warn("[Venus SDK] Received malformed simulation update");
|
|
3113
|
+
return;
|
|
2830
3114
|
}
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
3115
|
+
const callback = this.subscriptionCallbacks.get(notification.subscriptionId);
|
|
3116
|
+
if (!callback) {
|
|
3117
|
+
console.warn(
|
|
3118
|
+
"[Venus SDK] Received update for unknown subscription:",
|
|
3119
|
+
notification.subscriptionId
|
|
2835
3120
|
);
|
|
3121
|
+
return;
|
|
2836
3122
|
}
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
count: recipes?.length
|
|
2842
|
-
});
|
|
2843
|
-
const results = (recipes || []).map((q) => ({
|
|
2844
|
-
recipeId: q.recipeId,
|
|
2845
|
-
entity: q.entity || null,
|
|
2846
|
-
amount: q.batchAmount || 1,
|
|
2847
|
-
inputs: { cash: "BE:0" },
|
|
2848
|
-
canAfford: true,
|
|
2849
|
-
disabled: false
|
|
2850
|
-
}));
|
|
2851
|
-
return { success: true, results };
|
|
2852
|
-
}
|
|
2853
|
-
async getRecipeRequirementsAsync(recipe) {
|
|
2854
|
-
this.log("getRecipeRequirementsAsync called:", recipe);
|
|
2855
|
-
return {
|
|
2856
|
-
recipeId: recipe.recipeId,
|
|
2857
|
-
entity: recipe.entity || null,
|
|
2858
|
-
amount: recipe.batchAmount,
|
|
2859
|
-
inputs: { cash: "BE:0" },
|
|
2860
|
-
canAfford: true,
|
|
2861
|
-
disabled: false
|
|
2862
|
-
};
|
|
2863
|
-
}
|
|
2864
|
-
async triggerRecipeChainAsync(recipeId, options) {
|
|
2865
|
-
this.log("triggerRecipeChainAsync called:", { recipeId, ...options });
|
|
2866
|
-
return {
|
|
2867
|
-
success: true,
|
|
2868
|
-
message: "Mock recipe chain triggered successfully"
|
|
2869
|
-
};
|
|
2870
|
-
}
|
|
2871
|
-
log(message, ...args) {
|
|
2872
|
-
console.log(`[Venus Sim Mock] ${message}`, args);
|
|
2873
|
-
}
|
|
2874
|
-
async executeRecipe(appIdentifier, recipeId, inputs) {
|
|
2875
|
-
this.log(`Executing recipe ${recipeId} for ${appIdentifier}`, inputs);
|
|
2876
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
2877
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
2878
|
-
let config = mockSimulationConfigs.get(appIdentifier);
|
|
2879
|
-
let state = mockSimulationStates.get(appIdentifier);
|
|
2880
|
-
if (!config || !state) {
|
|
2881
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
2882
|
-
config = mockSimulationConfigs.get(appIdentifier);
|
|
2883
|
-
if (!config) {
|
|
2884
|
-
throw new Error("Failed to initialize simulation config");
|
|
2885
|
-
}
|
|
2886
|
-
}
|
|
2887
|
-
const recipe = config.recipes?.[recipeId];
|
|
2888
|
-
if (!recipe) {
|
|
2889
|
-
throw new Error(`Recipe ${recipeId} not found`);
|
|
2890
|
-
}
|
|
2891
|
-
if (state.disabledRecipes?.includes(recipeId)) {
|
|
2892
|
-
throw new Error(`Recipe ${recipeId} is disabled`);
|
|
2893
|
-
}
|
|
2894
|
-
if (recipe.inputs) {
|
|
2895
|
-
for (const [entityId, required] of Object.entries(recipe.inputs)) {
|
|
2896
|
-
const available = state.inventory[entityId] || 0;
|
|
2897
|
-
if (available < required) {
|
|
2898
|
-
throw new Error(
|
|
2899
|
-
`Insufficient ${entityId}: required ${required}, available ${available}`
|
|
2900
|
-
);
|
|
2901
|
-
}
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
if (recipe.inputs) {
|
|
2905
|
-
for (const [entityId, input] of Object.entries(recipe.inputs)) {
|
|
2906
|
-
const inventoryValue = state.inventory[entityId] || 0;
|
|
2907
|
-
if (typeof input === "number" && typeof inventoryValue === "number") {
|
|
2908
|
-
state.inventory[entityId] = inventoryValue - input;
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
if (recipe.beginEffects) {
|
|
2913
|
-
this.applyEffects(state, recipe.beginEffects);
|
|
2914
|
-
}
|
|
2915
|
-
const runId = this.generateRunId();
|
|
2916
|
-
const now = Date.now();
|
|
2917
|
-
const expiresAt = now + (recipe.duration || 0);
|
|
2918
|
-
const run = {
|
|
2919
|
-
id: runId,
|
|
2920
|
-
recipeId,
|
|
2921
|
-
status: "running",
|
|
2922
|
-
startTime: now,
|
|
2923
|
-
expiresAt,
|
|
2924
|
-
inputs: recipe.inputs || {}
|
|
2925
|
-
};
|
|
2926
|
-
state.activeRuns.push(run);
|
|
2927
|
-
if (recipe.duration === 0) {
|
|
2928
|
-
this.completeRun(appIdentifier, runId);
|
|
2929
|
-
return { status: "completed", runId };
|
|
2930
|
-
} else {
|
|
2931
|
-
const mockActiveTimers = this.mockActiveTimers;
|
|
2932
|
-
const timer = setTimeout(() => {
|
|
2933
|
-
this.completeRun(appIdentifier, runId);
|
|
2934
|
-
}, recipe.duration);
|
|
2935
|
-
const timers = mockActiveTimers.get(appIdentifier) || [];
|
|
2936
|
-
timers.push(timer);
|
|
2937
|
-
mockActiveTimers.set(appIdentifier, timers);
|
|
2938
|
-
return {
|
|
2939
|
-
status: "running",
|
|
2940
|
-
runId,
|
|
2941
|
-
expiresAt: new Date(expiresAt).toISOString()
|
|
2942
|
-
};
|
|
3123
|
+
try {
|
|
3124
|
+
callback(notification.updates);
|
|
3125
|
+
} catch (error) {
|
|
3126
|
+
console.error("[Venus SDK] Error in simulation subscription callback", error);
|
|
2943
3127
|
}
|
|
2944
3128
|
}
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
2949
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
2950
|
-
const mockActiveTimers = this.mockActiveTimers;
|
|
2951
|
-
const config = providedSimulationConfig || {
|
|
2952
|
-
version: "1.0",
|
|
2953
|
-
entities: {},
|
|
2954
|
-
recipes: {}
|
|
2955
|
-
};
|
|
2956
|
-
mockSimulationConfigs.set(appIdentifier, config);
|
|
2957
|
-
const initialInventory = {};
|
|
2958
|
-
if (providedSimulationConfig && config.entities) {
|
|
2959
|
-
Object.keys(config.entities).forEach((entityId) => {
|
|
2960
|
-
initialInventory[entityId] = 0;
|
|
2961
|
-
});
|
|
2962
|
-
}
|
|
2963
|
-
const state = {
|
|
2964
|
-
inventory: initialInventory,
|
|
2965
|
-
activeRuns: [],
|
|
2966
|
-
disabledRecipes: new Array()
|
|
2967
|
-
};
|
|
2968
|
-
if (config.recipes) {
|
|
2969
|
-
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
2970
|
-
if (recipe.metadata?.startsDisabled) {
|
|
2971
|
-
state.disabledRecipes.push(recipeId);
|
|
2972
|
-
}
|
|
2973
|
-
});
|
|
2974
|
-
}
|
|
2975
|
-
mockSimulationStates.set(appIdentifier, state);
|
|
2976
|
-
mockActiveTimers.set(appIdentifier, []);
|
|
2977
|
-
console.log(
|
|
2978
|
-
`[Venus Simulation Mock] Initialized state for ${appIdentifier}:`,
|
|
2979
|
-
state
|
|
2980
|
-
);
|
|
2981
|
-
if (config.recipes) {
|
|
2982
|
-
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
2983
|
-
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
2984
|
-
if (isAutoRestart && recipe.outputs) {
|
|
2985
|
-
this.log(`Found auto-restart recipe: ${recipeId}`, {
|
|
2986
|
-
topLevelAutoRestart: recipe.autoRestart,
|
|
2987
|
-
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
2988
|
-
hasOutputs: !!recipe.outputs,
|
|
2989
|
-
duration: recipe.duration
|
|
2990
|
-
});
|
|
2991
|
-
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
2992
|
-
if (condition && condition.entity) {
|
|
2993
|
-
const currentAmount = initialInventory[condition.entity] || 0;
|
|
2994
|
-
if (currentAmount < condition.maxValue) {
|
|
2995
|
-
console.log(
|
|
2996
|
-
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization`,
|
|
2997
|
-
{
|
|
2998
|
-
currentAmount,
|
|
2999
|
-
maxValue: condition.maxValue,
|
|
3000
|
-
entity: condition.entity
|
|
3001
|
-
}
|
|
3002
|
-
);
|
|
3003
|
-
setTimeout(() => {
|
|
3004
|
-
this.executeRecipe(appIdentifier, recipeId, {});
|
|
3005
|
-
}, 1e3);
|
|
3006
|
-
}
|
|
3007
|
-
} else {
|
|
3008
|
-
console.log(
|
|
3009
|
-
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization (no condition)`
|
|
3010
|
-
);
|
|
3011
|
-
setTimeout(() => {
|
|
3012
|
-
this.executeRecipe(appIdentifier, recipeId, {});
|
|
3013
|
-
}, 1e3);
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
});
|
|
3017
|
-
}
|
|
3018
|
-
return state;
|
|
3019
|
-
}
|
|
3020
|
-
generateRunId() {
|
|
3021
|
-
return "run_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3022
|
-
}
|
|
3023
|
-
completeRun(appIdentifier, runId) {
|
|
3024
|
-
this.log(`Completing run ${runId} for ${appIdentifier}`);
|
|
3025
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
3026
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
3027
|
-
const config = mockSimulationConfigs.get(appIdentifier);
|
|
3028
|
-
const state = mockSimulationStates.get(appIdentifier);
|
|
3029
|
-
if (!config || !state) return;
|
|
3030
|
-
const runIndex = state.activeRuns.findIndex((r) => r.id === runId);
|
|
3031
|
-
if (runIndex === -1) return;
|
|
3032
|
-
const run = state.activeRuns[runIndex];
|
|
3033
|
-
const recipe = config.recipes?.[run.recipeId];
|
|
3034
|
-
if (!recipe) return;
|
|
3035
|
-
const outputs = {};
|
|
3036
|
-
const rng = this.createSeededRandom(runId);
|
|
3037
|
-
if (recipe.outputs) {
|
|
3038
|
-
for (const [entityId, value] of Object.entries(recipe.outputs)) {
|
|
3039
|
-
if (typeof value === "number") {
|
|
3040
|
-
outputs[entityId] = value;
|
|
3041
|
-
} else if (typeof value === "object" && value != null && "min" in value && "max" in value && typeof value.min == "number" && typeof value.max === "number") {
|
|
3042
|
-
outputs[entityId] = Math.floor(rng() * (value.max - value.min + 1)) + value.min;
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3129
|
+
ensureValidSubscribeOptions(options) {
|
|
3130
|
+
if (typeof options !== "object" || options === null) {
|
|
3131
|
+
throw new Error("Simulation subscribe requires an options object");
|
|
3045
3132
|
}
|
|
3046
|
-
|
|
3047
|
-
|
|
3133
|
+
const opts = options;
|
|
3134
|
+
if (typeof opts.onUpdate !== "function") {
|
|
3135
|
+
throw new Error("Simulation subscribe requires an onUpdate callback");
|
|
3048
3136
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
run.outputs = outputs;
|
|
3054
|
-
state.activeRuns.splice(runIndex, 1);
|
|
3055
|
-
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
3056
|
-
if (isAutoRestart) {
|
|
3057
|
-
console.log(
|
|
3058
|
-
`[Venus Simulation Mock] Checking auto-restart for ${run.recipeId}`,
|
|
3059
|
-
{
|
|
3060
|
-
topLevelAutoRestart: recipe.autoRestart,
|
|
3061
|
-
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
3062
|
-
hasCondition: !!(recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition)
|
|
3063
|
-
}
|
|
3137
|
+
const hasFilter = Array.isArray(opts.entities) && opts.entities.length > 0 || Array.isArray(opts.tags) && opts.tags.length > 0 || Boolean(opts.activeRuns);
|
|
3138
|
+
if (!hasFilter) {
|
|
3139
|
+
throw new Error(
|
|
3140
|
+
"Simulation subscribe requires at least one filter (entities, tags, activeRuns)"
|
|
3064
3141
|
);
|
|
3065
|
-
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
3066
|
-
if (condition) {
|
|
3067
|
-
const currentAmount = state.inventory[condition.entity] || 0;
|
|
3068
|
-
if (currentAmount < condition.maxValue) {
|
|
3069
|
-
console.log(
|
|
3070
|
-
`[Venus Simulation Mock] Auto-restarting ${run.recipeId}`,
|
|
3071
|
-
{
|
|
3072
|
-
currentAmount,
|
|
3073
|
-
maxValue: condition.maxValue,
|
|
3074
|
-
entity: condition.entity
|
|
3075
|
-
}
|
|
3076
|
-
);
|
|
3077
|
-
setTimeout(() => {
|
|
3078
|
-
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
3079
|
-
}, 1e3);
|
|
3080
|
-
}
|
|
3081
|
-
} else {
|
|
3082
|
-
console.log(
|
|
3083
|
-
`[Venus Simulation Mock] Auto-restarting ${run.recipeId} (no condition)`
|
|
3084
|
-
);
|
|
3085
|
-
setTimeout(() => {
|
|
3086
|
-
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
3087
|
-
}, 1e3);
|
|
3088
|
-
}
|
|
3089
|
-
}
|
|
3090
|
-
console.log(
|
|
3091
|
-
`[Venus Simulation Mock] Completed run ${runId}, outputs:`,
|
|
3092
|
-
outputs
|
|
3093
|
-
);
|
|
3094
|
-
}
|
|
3095
|
-
createSeededRandom(seed) {
|
|
3096
|
-
let hash = 0;
|
|
3097
|
-
for (let i = 0; i < seed.length; i++) {
|
|
3098
|
-
const char = seed.charCodeAt(i);
|
|
3099
|
-
hash = (hash << 5) - hash + char;
|
|
3100
|
-
hash = hash & hash;
|
|
3101
|
-
}
|
|
3102
|
-
return () => {
|
|
3103
|
-
hash = (hash * 9301 + 49297) % 233280;
|
|
3104
|
-
return hash / 233280;
|
|
3105
|
-
};
|
|
3106
|
-
}
|
|
3107
|
-
applyEffects(state, effects) {
|
|
3108
|
-
if (!effects || !Array.isArray(effects)) return;
|
|
3109
|
-
for (const effect of effects) {
|
|
3110
|
-
switch (effect.type) {
|
|
3111
|
-
case "set":
|
|
3112
|
-
state.inventory[effect.target] = effect.value;
|
|
3113
|
-
console.log(
|
|
3114
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} = ${effect.value}`
|
|
3115
|
-
);
|
|
3116
|
-
break;
|
|
3117
|
-
case "add":
|
|
3118
|
-
state.inventory[effect.target] = (state.inventory[effect.target] || 0) + effect.value;
|
|
3119
|
-
console.log(
|
|
3120
|
-
`[Venus Simulation Mock] Effect: Add ${effect.value} to ${effect.target} (new value: ${state.inventory[effect.target]})`
|
|
3121
|
-
);
|
|
3122
|
-
break;
|
|
3123
|
-
case "multiply":
|
|
3124
|
-
state.inventory[effect.target] = (state.inventory[effect.target] || 0) * effect.value;
|
|
3125
|
-
console.log(
|
|
3126
|
-
`[Venus Simulation Mock] Effect: Multiply ${effect.target} by ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
3127
|
-
);
|
|
3128
|
-
break;
|
|
3129
|
-
case "min":
|
|
3130
|
-
state.inventory[effect.target] = Math.max(
|
|
3131
|
-
state.inventory[effect.target] || 0,
|
|
3132
|
-
effect.value
|
|
3133
|
-
);
|
|
3134
|
-
console.log(
|
|
3135
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} min ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
3136
|
-
);
|
|
3137
|
-
break;
|
|
3138
|
-
case "max":
|
|
3139
|
-
state.inventory[effect.target] = Math.min(
|
|
3140
|
-
state.inventory[effect.target] || 0,
|
|
3141
|
-
effect.value
|
|
3142
|
-
);
|
|
3143
|
-
console.log(
|
|
3144
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} max ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
3145
|
-
);
|
|
3146
|
-
break;
|
|
3147
|
-
case "enable_recipe":
|
|
3148
|
-
if (state.disabledRecipes?.includes(effect.target)) {
|
|
3149
|
-
state.disabledRecipes = state.disabledRecipes.filter(
|
|
3150
|
-
(r) => r !== effect.target
|
|
3151
|
-
);
|
|
3152
|
-
console.log(
|
|
3153
|
-
`[Venus Simulation Mock] Effect: Enabled recipe ${effect.target}`
|
|
3154
|
-
);
|
|
3155
|
-
}
|
|
3156
|
-
break;
|
|
3157
|
-
case "disable_recipe":
|
|
3158
|
-
if (!state.disabledRecipes) state.disabledRecipes = [];
|
|
3159
|
-
if (!state.disabledRecipes.includes(effect.target)) {
|
|
3160
|
-
state.disabledRecipes.push(effect.target);
|
|
3161
|
-
console.log(
|
|
3162
|
-
`[Venus Simulation Mock] Effect: Disabled recipe ${effect.target}`
|
|
3163
|
-
);
|
|
3164
|
-
}
|
|
3165
|
-
break;
|
|
3166
|
-
case "trigger_recipe":
|
|
3167
|
-
console.log(
|
|
3168
|
-
`[Venus Simulation Mock] Effect: Trigger recipe ${effect.target} (not implemented)`
|
|
3169
|
-
);
|
|
3170
|
-
break;
|
|
3171
|
-
default:
|
|
3172
|
-
console.warn(
|
|
3173
|
-
`[Venus Simulation Mock] Unknown effect type: ${effect.type}`
|
|
3174
|
-
);
|
|
3175
|
-
}
|
|
3176
3142
|
}
|
|
3177
3143
|
}
|
|
3178
|
-
async getConfigAsync() {
|
|
3179
|
-
console.log("[Venus Simulation Mock] getConfigAsync called");
|
|
3180
|
-
const appIdentifier = this.appId;
|
|
3181
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
3182
|
-
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
3183
|
-
version: "1.0",
|
|
3184
|
-
entities: {},
|
|
3185
|
-
recipes: {}
|
|
3186
|
-
};
|
|
3187
|
-
return config;
|
|
3188
|
-
}
|
|
3189
|
-
async getStateAsync(roomId) {
|
|
3190
|
-
this.log("getStateAsync called:", roomId);
|
|
3191
|
-
const appIdentifier = this.appId;
|
|
3192
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
3193
|
-
let state = mockSimulationStates.get(appIdentifier);
|
|
3194
|
-
if (!state) {
|
|
3195
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
3196
|
-
}
|
|
3197
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
3198
|
-
return {
|
|
3199
|
-
...state,
|
|
3200
|
-
roomId,
|
|
3201
|
-
configuration: mockSimulationConfigs.get(appIdentifier)
|
|
3202
|
-
};
|
|
3203
|
-
}
|
|
3204
|
-
async assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
3205
|
-
this.log("assignItemToSlotAsync called:", {
|
|
3206
|
-
containerId,
|
|
3207
|
-
slotId,
|
|
3208
|
-
itemId
|
|
3209
|
-
});
|
|
3210
|
-
return { success: true, message: "Mock assignment successful" };
|
|
3211
|
-
}
|
|
3212
|
-
async removeItemFromSlotAsync(containerId, slotId) {
|
|
3213
|
-
this.log("removeItemFromSlotAsync called:", {
|
|
3214
|
-
containerId,
|
|
3215
|
-
slotId
|
|
3216
|
-
});
|
|
3217
|
-
return { success: true, message: "Mock removal successful" };
|
|
3218
|
-
}
|
|
3219
3144
|
};
|
|
3220
3145
|
|
|
3221
3146
|
// src/simulation/index.ts
|
|
3222
3147
|
function initializeSimulation(venusApi, host) {
|
|
3223
|
-
console.log("[Venus SDK] Initializing new Simulation Api");
|
|
3224
3148
|
venusApi.simulation = {
|
|
3225
3149
|
isEnabled: () => true
|
|
3226
3150
|
};
|
|
3227
3151
|
venusApi.simulation.getConfigAsync = () => {
|
|
3228
3152
|
return host.simulation.getConfigAsync();
|
|
3229
3153
|
};
|
|
3230
|
-
venusApi.simulation.getStateAsync = (
|
|
3231
|
-
return host.simulation.getStateAsync(
|
|
3154
|
+
venusApi.simulation.getStateAsync = (roomId) => {
|
|
3155
|
+
return host.simulation.getStateAsync(roomId);
|
|
3232
3156
|
};
|
|
3233
3157
|
venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
|
|
3234
3158
|
return host.simulation.executeRecipeAsync(recipeId, inputs, options);
|
|
@@ -3239,31 +3163,17 @@ function initializeSimulation(venusApi, host) {
|
|
|
3239
3163
|
venusApi.simulation.collectRecipeAsync = (runId) => {
|
|
3240
3164
|
return host.simulation.collectRecipeAsync(runId);
|
|
3241
3165
|
};
|
|
3242
|
-
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs,
|
|
3243
|
-
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs,
|
|
3244
|
-
roomId,
|
|
3245
|
-
...options
|
|
3246
|
-
});
|
|
3166
|
+
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, options) => {
|
|
3167
|
+
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, options);
|
|
3247
3168
|
};
|
|
3248
|
-
venusApi.simulation.triggerRecipeChainAsync = (recipeId,
|
|
3249
|
-
return host.simulation.triggerRecipeChainAsync(recipeId,
|
|
3250
|
-
context,
|
|
3251
|
-
roomId
|
|
3252
|
-
});
|
|
3169
|
+
venusApi.simulation.triggerRecipeChainAsync = (recipeId, options) => {
|
|
3170
|
+
return host.simulation.triggerRecipeChainAsync(recipeId, options);
|
|
3253
3171
|
};
|
|
3254
|
-
venusApi.simulation.getAvailableRecipesAsync = async (
|
|
3255
|
-
|
|
3256
|
-
roomId,
|
|
3257
|
-
includeActorRecipes
|
|
3258
|
-
});
|
|
3259
|
-
return result.recipes;
|
|
3172
|
+
venusApi.simulation.getAvailableRecipesAsync = async (options) => {
|
|
3173
|
+
return host.simulation.getAvailableRecipesAsync(options);
|
|
3260
3174
|
};
|
|
3261
|
-
venusApi.simulation.getRecipeRequirementsAsync = (
|
|
3262
|
-
return host.simulation.getRecipeRequirementsAsync(
|
|
3263
|
-
recipeId,
|
|
3264
|
-
entity,
|
|
3265
|
-
batchAmount: amount
|
|
3266
|
-
});
|
|
3175
|
+
venusApi.simulation.getRecipeRequirementsAsync = (recipe) => {
|
|
3176
|
+
return host.simulation.getRecipeRequirementsAsync(recipe);
|
|
3267
3177
|
};
|
|
3268
3178
|
venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
|
|
3269
3179
|
return host.simulation.getBatchRecipeRequirementsAsync(recipes);
|
|
@@ -3306,9 +3216,6 @@ function initializeSimulation(venusApi, host) {
|
|
|
3306
3216
|
itemId
|
|
3307
3217
|
);
|
|
3308
3218
|
};
|
|
3309
|
-
venusApi.simulation.sumContributions = (contributions) => {
|
|
3310
|
-
return host.simulation.sumContributions(contributions);
|
|
3311
|
-
};
|
|
3312
3219
|
}
|
|
3313
3220
|
|
|
3314
3221
|
// src/time/utils.ts
|
|
@@ -3423,7 +3330,6 @@ var MockTimeApi = class {
|
|
|
3423
3330
|
maximumFractionDigits: options?.maximumFractionDigits || 2,
|
|
3424
3331
|
...options
|
|
3425
3332
|
};
|
|
3426
|
-
console.log(`[Venus Mock] Formatting number ${value} with locale ${locale}`);
|
|
3427
3333
|
return value.toLocaleString(locale, numberOptions);
|
|
3428
3334
|
}
|
|
3429
3335
|
formatTime(timestamp, options) {
|
|
@@ -3435,13 +3341,9 @@ var MockTimeApi = class {
|
|
|
3435
3341
|
hour12: options.hour12 !== void 0 ? options.hour12 : true,
|
|
3436
3342
|
...options
|
|
3437
3343
|
};
|
|
3438
|
-
console.log(
|
|
3439
|
-
`[Venus Mock] Formatting time ${timestamp} with locale ${locale}`
|
|
3440
|
-
);
|
|
3441
3344
|
return date.toLocaleString(locale, dateTimeOptions);
|
|
3442
3345
|
}
|
|
3443
3346
|
async getFutureTimeAsync(options) {
|
|
3444
|
-
console.log("[Venus Mock] Getting future time with options:", options);
|
|
3445
3347
|
const timeInfo = await this.requestTimeAsync();
|
|
3446
3348
|
const serverTime = new Date(timeInfo.serverTime);
|
|
3447
3349
|
const result = new Date(serverTime);
|
|
@@ -3486,7 +3388,6 @@ var MockTimeApi = class {
|
|
|
3486
3388
|
return result.getTime();
|
|
3487
3389
|
}
|
|
3488
3390
|
async requestTimeAsync() {
|
|
3489
|
-
console.log("[Venus Mock] Requesting time");
|
|
3490
3391
|
await createMockDelay(MOCK_DELAYS.short);
|
|
3491
3392
|
const venusApi = this.venusApi;
|
|
3492
3393
|
const mockOffset = venusApi._mock.serverTimeOffset || 2500;
|
|
@@ -3500,11 +3401,6 @@ var MockTimeApi = class {
|
|
|
3500
3401
|
formattedTime: new Date(localTime).toISOString(),
|
|
3501
3402
|
locale: venusApi._mock.user?.locale || "en-US"
|
|
3502
3403
|
};
|
|
3503
|
-
console.log("[Venus Mock] Time response:", {
|
|
3504
|
-
serverTime: new Date(timeInfo.serverTime).toISOString(),
|
|
3505
|
-
localTime: new Date(timeInfo.localTime).toISOString(),
|
|
3506
|
-
timezoneOffset: timeInfo.timezoneOffset
|
|
3507
|
-
});
|
|
3508
3404
|
return timeInfo;
|
|
3509
3405
|
}
|
|
3510
3406
|
};
|
|
@@ -3526,7 +3422,7 @@ function initializeTime(venusApi, host) {
|
|
|
3526
3422
|
}
|
|
3527
3423
|
|
|
3528
3424
|
// src/version.ts
|
|
3529
|
-
var SDK_VERSION = "3.1.
|
|
3425
|
+
var SDK_VERSION = "3.1.1";
|
|
3530
3426
|
|
|
3531
3427
|
// src/shared-assets/embeddedLibrariesManifest.ts
|
|
3532
3428
|
var DEFAULT_SHARED_LIB_CDN_BASE = "https://venus-static-01293ak.web.app/libs";
|
|
@@ -4177,117 +4073,28 @@ var MockPreloaderApi = class {
|
|
|
4177
4073
|
};
|
|
4178
4074
|
|
|
4179
4075
|
// src/game-preloader/RpcPreloaderApi.ts
|
|
4180
|
-
var RpcPreloaderApi = class {
|
|
4181
|
-
constructor(rpcClient) {
|
|
4182
|
-
__publicField(this, "rpcClient");
|
|
4183
|
-
this.rpcClient = rpcClient;
|
|
4184
|
-
}
|
|
4185
|
-
async showLoadScreen() {
|
|
4186
|
-
await this.rpcClient.call("H5_SHOW_LOAD_SCREEN" /* H5_SHOW_LOAD_SCREEN */);
|
|
4187
|
-
}
|
|
4188
|
-
async hideLoadScreen() {
|
|
4189
|
-
await this.rpcClient.call("H5_HIDE_LOAD_SCREEN" /* H5_HIDE_LOAD_SCREEN */);
|
|
4190
|
-
}
|
|
4191
|
-
async setLoaderText(text) {
|
|
4192
|
-
await this.rpcClient.call("H5_SET_LOADER_TEXT" /* H5_SET_LOADER_TEXT */, { text });
|
|
4193
|
-
}
|
|
4194
|
-
async setLoaderProgress(progress) {
|
|
4195
|
-
await this.rpcClient.call("H5_SET_LOADER_PROGRESS" /* H5_SET_LOADER_PROGRESS */, { progress });
|
|
4196
|
-
}
|
|
4197
|
-
};
|
|
4198
|
-
|
|
4199
|
-
// src/game-preloader/index.ts
|
|
4200
|
-
function initializePreloader(venusApi, host) {
|
|
4201
|
-
venusApi.preloader = host.preloader;
|
|
4202
|
-
}
|
|
4203
|
-
|
|
4204
|
-
// src/post/MockPostApi.ts
|
|
4205
|
-
var MockPostApi = class {
|
|
4206
|
-
constructor(venusApi) {
|
|
4207
|
-
__publicField(this, "venusApi");
|
|
4208
|
-
this.venusApi = venusApi;
|
|
4209
|
-
}
|
|
4210
|
-
async getPostInfo() {
|
|
4211
|
-
const venusApi = this.venusApi;
|
|
4212
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
4213
|
-
return venusApi._mock.currentPostInteractions;
|
|
4214
|
-
}
|
|
4215
|
-
async openCommentsAsync() {
|
|
4216
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
4217
|
-
return {
|
|
4218
|
-
opened: true,
|
|
4219
|
-
commentsCount: 0
|
|
4220
|
-
};
|
|
4221
|
-
}
|
|
4222
|
-
async toggleFollowAsync() {
|
|
4223
|
-
const venusApi = this.venusApi;
|
|
4224
|
-
console.log("[Venus Mock] *Toggling follow status");
|
|
4225
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
4226
|
-
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
4227
|
-
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
4228
|
-
return {
|
|
4229
|
-
isFollowing,
|
|
4230
|
-
action: isFollowing ? "followed" : "unfollowed"
|
|
4231
|
-
};
|
|
4232
|
-
}
|
|
4233
|
-
async toggleLikeAsync() {
|
|
4234
|
-
const venusApi = this.venusApi;
|
|
4235
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
4236
|
-
venusApi._mock.currentPostInteractions.isLiked = !venusApi._mock.currentPostInteractions.isLiked;
|
|
4237
|
-
const isLiked = venusApi._mock.currentPostInteractions.isLiked;
|
|
4238
|
-
if (isLiked) {
|
|
4239
|
-
venusApi._mock.currentPostInteractions.likesCount++;
|
|
4240
|
-
} else {
|
|
4241
|
-
venusApi._mock.currentPostInteractions.likesCount = Math.max(
|
|
4242
|
-
0,
|
|
4243
|
-
venusApi._mock.currentPostInteractions.likesCount - 1
|
|
4244
|
-
);
|
|
4245
|
-
}
|
|
4246
|
-
return {
|
|
4247
|
-
isLiked,
|
|
4248
|
-
likesCount: venusApi._mock.currentPostInteractions.likesCount,
|
|
4249
|
-
action: isLiked ? "liked" : "unliked"
|
|
4250
|
-
};
|
|
4251
|
-
}
|
|
4252
|
-
};
|
|
4253
|
-
|
|
4254
|
-
// src/post/RpcPostApi.ts
|
|
4255
|
-
var RpcPostApi = class {
|
|
4076
|
+
var RpcPreloaderApi = class {
|
|
4256
4077
|
constructor(rpcClient) {
|
|
4257
4078
|
__publicField(this, "rpcClient");
|
|
4258
4079
|
this.rpcClient = rpcClient;
|
|
4259
4080
|
}
|
|
4260
|
-
|
|
4261
|
-
|
|
4081
|
+
async showLoadScreen() {
|
|
4082
|
+
await this.rpcClient.call("H5_SHOW_LOAD_SCREEN" /* H5_SHOW_LOAD_SCREEN */);
|
|
4262
4083
|
}
|
|
4263
|
-
|
|
4264
|
-
|
|
4084
|
+
async hideLoadScreen() {
|
|
4085
|
+
await this.rpcClient.call("H5_HIDE_LOAD_SCREEN" /* H5_HIDE_LOAD_SCREEN */);
|
|
4265
4086
|
}
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
"H5_TOGGLE_FOLLOW" /* TOGGLE_FOLLOW */,
|
|
4269
|
-
{}
|
|
4270
|
-
);
|
|
4087
|
+
async setLoaderText(text) {
|
|
4088
|
+
await this.rpcClient.call("H5_SET_LOADER_TEXT" /* H5_SET_LOADER_TEXT */, { text });
|
|
4271
4089
|
}
|
|
4272
|
-
|
|
4273
|
-
|
|
4090
|
+
async setLoaderProgress(progress) {
|
|
4091
|
+
await this.rpcClient.call("H5_SET_LOADER_PROGRESS" /* H5_SET_LOADER_PROGRESS */, { progress });
|
|
4274
4092
|
}
|
|
4275
4093
|
};
|
|
4276
4094
|
|
|
4277
|
-
// src/
|
|
4278
|
-
function
|
|
4279
|
-
venusApi.
|
|
4280
|
-
return host.post.getPostInfo();
|
|
4281
|
-
};
|
|
4282
|
-
venusApi.toggleFollowAsync = () => {
|
|
4283
|
-
return host.post.toggleFollowAsync();
|
|
4284
|
-
};
|
|
4285
|
-
venusApi.toggleLikeAsync = () => {
|
|
4286
|
-
return host.post.toggleLikeAsync();
|
|
4287
|
-
};
|
|
4288
|
-
venusApi.openCommentsAsync = async () => {
|
|
4289
|
-
await host.post.openCommentsAsync();
|
|
4290
|
-
};
|
|
4095
|
+
// src/game-preloader/index.ts
|
|
4096
|
+
function initializePreloader(venusApi, host) {
|
|
4097
|
+
venusApi.preloader = host.preloader;
|
|
4291
4098
|
}
|
|
4292
4099
|
|
|
4293
4100
|
// src/social/MockSocialApi.ts
|
|
@@ -4392,6 +4199,16 @@ var VenusTransport = class {
|
|
|
4392
4199
|
this.isProcessingMessage = false;
|
|
4393
4200
|
return;
|
|
4394
4201
|
}
|
|
4202
|
+
if (message.type === "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */) {
|
|
4203
|
+
const notification = {
|
|
4204
|
+
type: "rpc-notification",
|
|
4205
|
+
id: message.type,
|
|
4206
|
+
payload: message.data
|
|
4207
|
+
};
|
|
4208
|
+
this.handleNotification(notification);
|
|
4209
|
+
this.isProcessingMessage = false;
|
|
4210
|
+
return;
|
|
4211
|
+
}
|
|
4395
4212
|
const requestId = messageData.requestId;
|
|
4396
4213
|
if (!requestId) {
|
|
4397
4214
|
this.logWarn("No requestId. Ignoring message...");
|
|
@@ -4558,294 +4375,6 @@ var VenusTransport = class {
|
|
|
4558
4375
|
}
|
|
4559
4376
|
};
|
|
4560
4377
|
|
|
4561
|
-
// src/RemoteHost.ts
|
|
4562
|
-
init_rooms();
|
|
4563
|
-
|
|
4564
|
-
// src/rooms/RpcRoomsApi.ts
|
|
4565
|
-
init_VenusRoom();
|
|
4566
|
-
var RpcRoomsApi = class {
|
|
4567
|
-
constructor(rpcClient) {
|
|
4568
|
-
__publicField(this, "rpcClient");
|
|
4569
|
-
__publicField(this, "subscriptions");
|
|
4570
|
-
__publicField(this, "transportSubscription", null);
|
|
4571
|
-
this.rpcClient = rpcClient;
|
|
4572
|
-
this.subscriptions = {
|
|
4573
|
-
data: {},
|
|
4574
|
-
messages: {},
|
|
4575
|
-
gameEvents: {},
|
|
4576
|
-
allEvents: {}
|
|
4577
|
-
};
|
|
4578
|
-
}
|
|
4579
|
-
/**
|
|
4580
|
-
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
4581
|
-
*/
|
|
4582
|
-
getSubscriptions() {
|
|
4583
|
-
return this.subscriptions;
|
|
4584
|
-
}
|
|
4585
|
-
/**
|
|
4586
|
-
* Set up room notification routing from the transport
|
|
4587
|
-
*/
|
|
4588
|
-
setupNotifications(transport) {
|
|
4589
|
-
const { setupRoomNotifications: setupRoomNotifications2 } = (init_rooms(), __toCommonJS(rooms_exports));
|
|
4590
|
-
this.transportSubscription = setupRoomNotifications2(
|
|
4591
|
-
transport,
|
|
4592
|
-
() => this.getSubscriptions()
|
|
4593
|
-
);
|
|
4594
|
-
}
|
|
4595
|
-
/**
|
|
4596
|
-
* Clean up subscriptions and resources
|
|
4597
|
-
*/
|
|
4598
|
-
dispose() {
|
|
4599
|
-
if (this.transportSubscription) {
|
|
4600
|
-
this.transportSubscription.unsubscribe();
|
|
4601
|
-
this.transportSubscription = null;
|
|
4602
|
-
console.log("[Venus Rooms] Cleaned up room notification subscription");
|
|
4603
|
-
}
|
|
4604
|
-
}
|
|
4605
|
-
async createRoom(options) {
|
|
4606
|
-
const response = await this.rpcClient.call(
|
|
4607
|
-
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
4608
|
-
{
|
|
4609
|
-
options
|
|
4610
|
-
}
|
|
4611
|
-
);
|
|
4612
|
-
if (response.success === false) {
|
|
4613
|
-
throw new Error(response.error || "Failed to create room");
|
|
4614
|
-
}
|
|
4615
|
-
const roomData = response.roomData || response;
|
|
4616
|
-
const room = new VenusRoom(roomData);
|
|
4617
|
-
return room;
|
|
4618
|
-
}
|
|
4619
|
-
async joinOrCreateRoom(options) {
|
|
4620
|
-
const response = await this.rpcClient.call(
|
|
4621
|
-
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
4622
|
-
{
|
|
4623
|
-
options
|
|
4624
|
-
}
|
|
4625
|
-
);
|
|
4626
|
-
if (response.success === false) {
|
|
4627
|
-
throw new Error(response.error || "Failed to join or create room");
|
|
4628
|
-
}
|
|
4629
|
-
const data = response.value || response;
|
|
4630
|
-
const room = new VenusRoom(data.roomData);
|
|
4631
|
-
return {
|
|
4632
|
-
action: data.action,
|
|
4633
|
-
room,
|
|
4634
|
-
playersJoined: data.playersJoined
|
|
4635
|
-
};
|
|
4636
|
-
}
|
|
4637
|
-
async joinRoomByCode(roomCode) {
|
|
4638
|
-
const response = await this.rpcClient.call(
|
|
4639
|
-
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
4640
|
-
{
|
|
4641
|
-
roomCode
|
|
4642
|
-
}
|
|
4643
|
-
);
|
|
4644
|
-
if (response?.success === false) {
|
|
4645
|
-
throw new Error(response.error || "Failed to join room by code");
|
|
4646
|
-
}
|
|
4647
|
-
const roomData = response.roomData || response;
|
|
4648
|
-
const room = new VenusRoom(roomData);
|
|
4649
|
-
return room;
|
|
4650
|
-
}
|
|
4651
|
-
// Get user's rooms with optional filtering
|
|
4652
|
-
async getUserRooms(includeArchived = false) {
|
|
4653
|
-
const response = await this.rpcClient.call(
|
|
4654
|
-
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
4655
|
-
{
|
|
4656
|
-
includeArchived
|
|
4657
|
-
}
|
|
4658
|
-
);
|
|
4659
|
-
if (response?.success === false) {
|
|
4660
|
-
throw new Error(response.error || "Failed to get user rooms");
|
|
4661
|
-
}
|
|
4662
|
-
const rawRooms = response.rooms || [];
|
|
4663
|
-
const venusRooms = [];
|
|
4664
|
-
for (const roomData of rawRooms) {
|
|
4665
|
-
if (!roomData.id) {
|
|
4666
|
-
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
4667
|
-
continue;
|
|
4668
|
-
}
|
|
4669
|
-
try {
|
|
4670
|
-
const venusRoom = new VenusRoom(roomData);
|
|
4671
|
-
venusRooms.push(venusRoom);
|
|
4672
|
-
} catch (error) {
|
|
4673
|
-
console.warn(
|
|
4674
|
-
"getUserRooms: Failed to create VenusRoom object:",
|
|
4675
|
-
error,
|
|
4676
|
-
roomData
|
|
4677
|
-
);
|
|
4678
|
-
}
|
|
4679
|
-
}
|
|
4680
|
-
return venusRooms;
|
|
4681
|
-
}
|
|
4682
|
-
async updateData(room, updates, merge = true) {
|
|
4683
|
-
const response = await this.rpcClient.call(
|
|
4684
|
-
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
4685
|
-
{
|
|
4686
|
-
roomId: room.id,
|
|
4687
|
-
updates,
|
|
4688
|
-
merge
|
|
4689
|
-
}
|
|
4690
|
-
);
|
|
4691
|
-
if (response?.success === false) {
|
|
4692
|
-
throw new Error(response.error || "Failed to update room data");
|
|
4693
|
-
}
|
|
4694
|
-
return response.data;
|
|
4695
|
-
}
|
|
4696
|
-
async getData(room) {
|
|
4697
|
-
const response = await this.rpcClient.call(
|
|
4698
|
-
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
4699
|
-
{
|
|
4700
|
-
roomId: room.id
|
|
4701
|
-
}
|
|
4702
|
-
);
|
|
4703
|
-
if (response?.success === false) {
|
|
4704
|
-
throw new Error(response.error || "Failed to get room data");
|
|
4705
|
-
}
|
|
4706
|
-
return response.data;
|
|
4707
|
-
}
|
|
4708
|
-
async sendMessage(venusRoom, messageData) {
|
|
4709
|
-
const response = await this.rpcClient.call(
|
|
4710
|
-
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
4711
|
-
{
|
|
4712
|
-
roomId: venusRoom.id,
|
|
4713
|
-
message: messageData
|
|
4714
|
-
}
|
|
4715
|
-
);
|
|
4716
|
-
if (response?.success === false) {
|
|
4717
|
-
throw new Error(response.error || "Failed to send message");
|
|
4718
|
-
}
|
|
4719
|
-
return response.messageId;
|
|
4720
|
-
}
|
|
4721
|
-
async leave(room) {
|
|
4722
|
-
const response = await this.rpcClient.call(
|
|
4723
|
-
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
4724
|
-
{
|
|
4725
|
-
roomId: room.id
|
|
4726
|
-
}
|
|
4727
|
-
);
|
|
4728
|
-
if (response?.success === false) {
|
|
4729
|
-
throw new Error(response.error || "Failed to leave room");
|
|
4730
|
-
}
|
|
4731
|
-
return response;
|
|
4732
|
-
}
|
|
4733
|
-
async startGame(room, gameConfig = {}, turnOrder = null) {
|
|
4734
|
-
const response = await this.rpcClient.call(
|
|
4735
|
-
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
4736
|
-
{
|
|
4737
|
-
roomId: room.id,
|
|
4738
|
-
gameConfig,
|
|
4739
|
-
turnOrder
|
|
4740
|
-
}
|
|
4741
|
-
);
|
|
4742
|
-
if (response?.success === false) {
|
|
4743
|
-
throw new Error(response.error || "Failed to start game");
|
|
4744
|
-
}
|
|
4745
|
-
return response.data;
|
|
4746
|
-
}
|
|
4747
|
-
async proposeMove(room, proposalPayload) {
|
|
4748
|
-
const response = await this.rpcClient.call(
|
|
4749
|
-
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
4750
|
-
{
|
|
4751
|
-
roomId: room.id,
|
|
4752
|
-
gameSpecificState: proposalPayload.gameSpecificState,
|
|
4753
|
-
moveType: proposalPayload.moveType,
|
|
4754
|
-
clientContext: proposalPayload.clientContext,
|
|
4755
|
-
clientProposalId: proposalPayload.clientProposalId
|
|
4756
|
-
}
|
|
4757
|
-
);
|
|
4758
|
-
if (response?.success === false) {
|
|
4759
|
-
throw new Error(response.error || "Failed to propose move");
|
|
4760
|
-
}
|
|
4761
|
-
return response.data;
|
|
4762
|
-
}
|
|
4763
|
-
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
4764
|
-
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
4765
|
-
return { success: true, moveId, isValid, reason };
|
|
4766
|
-
}
|
|
4767
|
-
async roomSubscribeToGameEvents(room, callback) {
|
|
4768
|
-
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4769
|
-
if (!this.subscriptions.gameEvents[room.id]) {
|
|
4770
|
-
this.subscriptions.gameEvents[room.id] = [];
|
|
4771
|
-
}
|
|
4772
|
-
this.subscriptions.gameEvents[room.id].push(callback);
|
|
4773
|
-
}
|
|
4774
|
-
subscribe(room, options = {}) {
|
|
4775
|
-
const subscriptionIds = [];
|
|
4776
|
-
const roomId = room.id;
|
|
4777
|
-
if (options.onData) {
|
|
4778
|
-
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4779
|
-
if (!this.subscriptions.data[roomId]) {
|
|
4780
|
-
this.subscriptions.data[roomId] = [];
|
|
4781
|
-
}
|
|
4782
|
-
this.subscriptions.data[roomId].push(options.onData);
|
|
4783
|
-
subscriptionIds.push({
|
|
4784
|
-
type: "data",
|
|
4785
|
-
id: dataSubId,
|
|
4786
|
-
callback: options.onData
|
|
4787
|
-
});
|
|
4788
|
-
}
|
|
4789
|
-
if (options.onMessages) {
|
|
4790
|
-
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4791
|
-
if (!this.subscriptions.messages[roomId]) {
|
|
4792
|
-
this.subscriptions.messages[roomId] = [];
|
|
4793
|
-
}
|
|
4794
|
-
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
4795
|
-
subscriptionIds.push({
|
|
4796
|
-
type: "messages",
|
|
4797
|
-
id: msgSubId,
|
|
4798
|
-
callback: options.onMessages
|
|
4799
|
-
});
|
|
4800
|
-
}
|
|
4801
|
-
if (options.onMoves || options.onGameEvents) {
|
|
4802
|
-
const handler = options.onMoves || options.onGameEvents;
|
|
4803
|
-
if (handler) {
|
|
4804
|
-
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4805
|
-
if (!this.subscriptions.gameEvents[roomId]) {
|
|
4806
|
-
this.subscriptions.gameEvents[roomId] = [];
|
|
4807
|
-
}
|
|
4808
|
-
this.subscriptions.gameEvents[roomId].push(handler);
|
|
4809
|
-
subscriptionIds.push({
|
|
4810
|
-
type: "gameEvents",
|
|
4811
|
-
id: gameSubId,
|
|
4812
|
-
callback: handler
|
|
4813
|
-
});
|
|
4814
|
-
}
|
|
4815
|
-
}
|
|
4816
|
-
const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
|
|
4817
|
-
if (needsSubscription) {
|
|
4818
|
-
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
4819
|
-
roomId,
|
|
4820
|
-
subscribeToData: !!options.onData,
|
|
4821
|
-
subscribeToMessages: !!options.onMessages,
|
|
4822
|
-
subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
|
|
4823
|
-
}).catch((error) => {
|
|
4824
|
-
console.error("Failed to set up room subscription:", error);
|
|
4825
|
-
});
|
|
4826
|
-
}
|
|
4827
|
-
let called = false;
|
|
4828
|
-
return () => {
|
|
4829
|
-
if (called) return;
|
|
4830
|
-
called = true;
|
|
4831
|
-
subscriptionIds.forEach((sub) => {
|
|
4832
|
-
const bucket = this.subscriptions[sub.type];
|
|
4833
|
-
const callbacks = bucket && bucket[roomId] || [];
|
|
4834
|
-
const index = callbacks.indexOf(sub.callback);
|
|
4835
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
4836
|
-
});
|
|
4837
|
-
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
4838
|
-
if (hasNoCallbacks) {
|
|
4839
|
-
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
4840
|
-
roomId
|
|
4841
|
-
}).catch((error) => {
|
|
4842
|
-
console.error("Failed to clean up room subscription:", error);
|
|
4843
|
-
});
|
|
4844
|
-
}
|
|
4845
|
-
};
|
|
4846
|
-
}
|
|
4847
|
-
};
|
|
4848
|
-
|
|
4849
4378
|
// src/RemoteHost.ts
|
|
4850
4379
|
var getCdnBaseUrl = () => {
|
|
4851
4380
|
return "https://venus-static-01293ak.web.app/";
|
|
@@ -4862,9 +4391,9 @@ var RemoteHost = class {
|
|
|
4862
4391
|
__publicField(this, "notifications");
|
|
4863
4392
|
__publicField(this, "popups");
|
|
4864
4393
|
__publicField(this, "profile");
|
|
4394
|
+
__publicField(this, "system");
|
|
4865
4395
|
__publicField(this, "cdn");
|
|
4866
4396
|
__publicField(this, "time");
|
|
4867
|
-
__publicField(this, "post");
|
|
4868
4397
|
__publicField(this, "ai");
|
|
4869
4398
|
__publicField(this, "haptics");
|
|
4870
4399
|
__publicField(this, "features");
|
|
@@ -4918,10 +4447,12 @@ var RemoteHost = class {
|
|
|
4918
4447
|
this.navigation = new RpcNavigationApi(rpcClient, venusApi);
|
|
4919
4448
|
this.notifications = new RpcNotificationsApi(rpcClient);
|
|
4920
4449
|
this.popups = new RpcPopupsApi(rpcClient);
|
|
4921
|
-
this.profile = new HostProfileApi();
|
|
4450
|
+
this.profile = new HostProfileApi(venusApi);
|
|
4451
|
+
const deviceApi = new HostDeviceApi(venusApi);
|
|
4452
|
+
const environmentApi = new HostEnvironmentApi(venusApi);
|
|
4453
|
+
this.system = new HostSystemApi(deviceApi, environmentApi, venusApi);
|
|
4922
4454
|
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
4923
4455
|
this.time = new HostTimeApi(rpcClient, venusApi);
|
|
4924
|
-
this.post = new RpcPostApi(rpcClient);
|
|
4925
4456
|
this.ai = new RpcAiApi(rpcClient);
|
|
4926
4457
|
this.haptics = new RpcHapticsApi(rpcClient);
|
|
4927
4458
|
this.features = new RpcFeaturesApi(rpcClient);
|
|
@@ -4936,7 +4467,6 @@ var RemoteHost = class {
|
|
|
4936
4467
|
venusApi.isMock = () => false;
|
|
4937
4468
|
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
4938
4469
|
initializeRoomsApi(this.venusApi, this);
|
|
4939
|
-
console.log("[Venus SDK] Remote host created");
|
|
4940
4470
|
}
|
|
4941
4471
|
get isInitialized() {
|
|
4942
4472
|
return this._isInitialized;
|
|
@@ -4955,35 +4485,27 @@ var RemoteHost = class {
|
|
|
4955
4485
|
);
|
|
4956
4486
|
transport.instanceId = response.instanceId;
|
|
4957
4487
|
this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
if (venus._config) {
|
|
4971
|
-
venus._config.profile = sanitizedProfile;
|
|
4972
|
-
}
|
|
4973
|
-
if (venus.config) {
|
|
4974
|
-
venus.config.profile = sanitizedProfile;
|
|
4975
|
-
}
|
|
4976
|
-
}
|
|
4977
|
-
}
|
|
4488
|
+
const profile = response.profile;
|
|
4489
|
+
const sanitizedProfile = {
|
|
4490
|
+
id: profile.id,
|
|
4491
|
+
username: profile.username,
|
|
4492
|
+
avatarUrl: profile.avatarUrl ?? null,
|
|
4493
|
+
isAnonymous: Boolean(profile.isAnonymous)
|
|
4494
|
+
};
|
|
4495
|
+
this.venusApi._profileData = sanitizedProfile;
|
|
4496
|
+
this.venusApi._deviceData = response.device;
|
|
4497
|
+
this.venusApi._environmentData = response.environment;
|
|
4498
|
+
this.venusApi._localeData = response.locale;
|
|
4499
|
+
this.venusApi._languageCodeData = response.languageCode;
|
|
4978
4500
|
this._isInitialized = true;
|
|
4979
|
-
this.venusApi.launchParams = response.launchParams
|
|
4501
|
+
this.venusApi.launchParams = response.launchParams;
|
|
4980
4502
|
await this.rpcClient.call("READY" /* READY */, {});
|
|
4981
|
-
const
|
|
4982
|
-
if (
|
|
4983
|
-
this.venusApi.
|
|
4503
|
+
const safeArea = response.safeArea;
|
|
4504
|
+
if (safeArea) {
|
|
4505
|
+
this.venusApi._safeAreaData = safeArea;
|
|
4984
4506
|
}
|
|
4985
4507
|
return {
|
|
4986
|
-
|
|
4508
|
+
safeArea,
|
|
4987
4509
|
initializeAsleep: response.initializeAsleep
|
|
4988
4510
|
};
|
|
4989
4511
|
}
|
|
@@ -4993,49 +4515,120 @@ var RemoteHost = class {
|
|
|
4993
4515
|
};
|
|
4994
4516
|
|
|
4995
4517
|
// src/MockHost.ts
|
|
4996
|
-
init_rooms();
|
|
4997
4518
|
var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
|
|
4998
4519
|
function createUnavailableRoomsApi() {
|
|
4999
4520
|
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
5000
4521
|
return {
|
|
5001
|
-
async
|
|
4522
|
+
async createRoomAsync() {
|
|
5002
4523
|
throw roomsUnavailableError();
|
|
5003
4524
|
},
|
|
5004
|
-
async
|
|
4525
|
+
async joinOrCreateRoomAsync() {
|
|
5005
4526
|
throw roomsUnavailableError();
|
|
5006
4527
|
},
|
|
5007
|
-
async
|
|
4528
|
+
async joinRoomByCodeAsync() {
|
|
5008
4529
|
throw roomsUnavailableError();
|
|
5009
4530
|
},
|
|
5010
|
-
async
|
|
4531
|
+
async getUserRoomsAsync() {
|
|
5011
4532
|
throw roomsUnavailableError();
|
|
5012
4533
|
},
|
|
5013
|
-
|
|
4534
|
+
async subscribeAsync() {
|
|
5014
4535
|
throw roomsUnavailableError();
|
|
5015
4536
|
},
|
|
5016
|
-
async
|
|
4537
|
+
async updateRoomDataAsync() {
|
|
5017
4538
|
throw roomsUnavailableError();
|
|
5018
4539
|
},
|
|
5019
|
-
async
|
|
4540
|
+
async getRoomDataAsync() {
|
|
5020
4541
|
throw roomsUnavailableError();
|
|
5021
4542
|
},
|
|
5022
|
-
async
|
|
4543
|
+
async sendRoomMessageAsync() {
|
|
5023
4544
|
throw roomsUnavailableError();
|
|
5024
4545
|
},
|
|
5025
|
-
async
|
|
4546
|
+
async leaveRoomAsync() {
|
|
5026
4547
|
throw roomsUnavailableError();
|
|
5027
4548
|
},
|
|
5028
|
-
async
|
|
4549
|
+
async startRoomGameAsync() {
|
|
5029
4550
|
throw roomsUnavailableError();
|
|
5030
4551
|
},
|
|
5031
|
-
async
|
|
4552
|
+
async proposeMoveAsync() {
|
|
5032
4553
|
throw roomsUnavailableError();
|
|
5033
4554
|
},
|
|
5034
|
-
async
|
|
4555
|
+
async validateMoveAsync() {
|
|
5035
4556
|
throw roomsUnavailableError();
|
|
5036
4557
|
}
|
|
5037
4558
|
};
|
|
5038
4559
|
}
|
|
4560
|
+
var SIMULATION_UNAVAILABLE_MESSAGE = "[Venus SDK] Simulation API is only available when running inside the Venus host environment.";
|
|
4561
|
+
function createUnavailableSimulationApi() {
|
|
4562
|
+
const simulationUnavailableError = () => new Error(SIMULATION_UNAVAILABLE_MESSAGE);
|
|
4563
|
+
return {
|
|
4564
|
+
isEnabled() {
|
|
4565
|
+
return false;
|
|
4566
|
+
},
|
|
4567
|
+
async getStateAsync() {
|
|
4568
|
+
throw simulationUnavailableError();
|
|
4569
|
+
},
|
|
4570
|
+
async getConfigAsync() {
|
|
4571
|
+
throw simulationUnavailableError();
|
|
4572
|
+
},
|
|
4573
|
+
async executeRecipeAsync() {
|
|
4574
|
+
throw simulationUnavailableError();
|
|
4575
|
+
},
|
|
4576
|
+
async getActiveRunsAsync() {
|
|
4577
|
+
throw simulationUnavailableError();
|
|
4578
|
+
},
|
|
4579
|
+
async collectRecipeAsync() {
|
|
4580
|
+
throw simulationUnavailableError();
|
|
4581
|
+
},
|
|
4582
|
+
async executeScopedRecipeAsync() {
|
|
4583
|
+
throw simulationUnavailableError();
|
|
4584
|
+
},
|
|
4585
|
+
async triggerRecipeChainAsync() {
|
|
4586
|
+
throw simulationUnavailableError();
|
|
4587
|
+
},
|
|
4588
|
+
async getAvailableRecipesAsync() {
|
|
4589
|
+
throw simulationUnavailableError();
|
|
4590
|
+
},
|
|
4591
|
+
async getRecipeRequirementsAsync() {
|
|
4592
|
+
throw simulationUnavailableError();
|
|
4593
|
+
},
|
|
4594
|
+
async getBatchRecipeRequirementsAsync() {
|
|
4595
|
+
throw simulationUnavailableError();
|
|
4596
|
+
},
|
|
4597
|
+
async resolveFieldValueAsync() {
|
|
4598
|
+
throw simulationUnavailableError();
|
|
4599
|
+
},
|
|
4600
|
+
async getEntityMetadataAsync() {
|
|
4601
|
+
throw simulationUnavailableError();
|
|
4602
|
+
},
|
|
4603
|
+
async getSlotContainersAsync() {
|
|
4604
|
+
throw simulationUnavailableError();
|
|
4605
|
+
},
|
|
4606
|
+
async getSlotAssignmentsAsync() {
|
|
4607
|
+
throw simulationUnavailableError();
|
|
4608
|
+
},
|
|
4609
|
+
async assignItemToSlotAsync() {
|
|
4610
|
+
throw simulationUnavailableError();
|
|
4611
|
+
},
|
|
4612
|
+
async removeItemFromSlotAsync() {
|
|
4613
|
+
throw simulationUnavailableError();
|
|
4614
|
+
},
|
|
4615
|
+
async getAvailableItemsAsync() {
|
|
4616
|
+
throw simulationUnavailableError();
|
|
4617
|
+
},
|
|
4618
|
+
async calculatePowerPreviewAsync() {
|
|
4619
|
+
throw simulationUnavailableError();
|
|
4620
|
+
},
|
|
4621
|
+
async validateSlotAssignmentAsync() {
|
|
4622
|
+
throw simulationUnavailableError();
|
|
4623
|
+
},
|
|
4624
|
+
async executeBatchOperationsAsync() {
|
|
4625
|
+
throw simulationUnavailableError();
|
|
4626
|
+
},
|
|
4627
|
+
async subscribeAsync() {
|
|
4628
|
+
throw simulationUnavailableError();
|
|
4629
|
+
}
|
|
4630
|
+
};
|
|
4631
|
+
}
|
|
5039
4632
|
var MockHost = class {
|
|
5040
4633
|
constructor(venusApi) {
|
|
5041
4634
|
__publicField(this, "ads");
|
|
@@ -5048,9 +4641,9 @@ var MockHost = class {
|
|
|
5048
4641
|
__publicField(this, "notifications");
|
|
5049
4642
|
__publicField(this, "popups");
|
|
5050
4643
|
__publicField(this, "profile");
|
|
4644
|
+
__publicField(this, "system");
|
|
5051
4645
|
__publicField(this, "cdn");
|
|
5052
4646
|
__publicField(this, "time");
|
|
5053
|
-
__publicField(this, "post");
|
|
5054
4647
|
__publicField(this, "ai");
|
|
5055
4648
|
__publicField(this, "haptics");
|
|
5056
4649
|
__publicField(this, "features");
|
|
@@ -5082,15 +4675,17 @@ var MockHost = class {
|
|
|
5082
4675
|
this.navigation = new MockNavigationApi(venusApi);
|
|
5083
4676
|
this.notifications = new MockNotificationsApi(venusApi);
|
|
5084
4677
|
this.popups = new MockPopupsApi(this._overlay);
|
|
5085
|
-
this.profile = new MockProfileApi();
|
|
5086
|
-
|
|
4678
|
+
this.profile = new MockProfileApi(venusApi);
|
|
4679
|
+
const deviceApi = new MockDeviceApi(venusApi);
|
|
4680
|
+
const environmentApi = new MockEnvironmentApi(venusApi);
|
|
4681
|
+
this.system = new MockSystemApi(deviceApi, environmentApi, venusApi);
|
|
4682
|
+
this.cdn = new MockCdnApi(venusApi);
|
|
5087
4683
|
this.time = new MockTimeApi(venusApi);
|
|
5088
|
-
this.post = new MockPostApi(venusApi);
|
|
5089
4684
|
this.ai = new MockAiApi();
|
|
5090
4685
|
this.haptics = new MockHapticsApi(venusApi);
|
|
5091
4686
|
this.features = new MockFeaturesApi();
|
|
5092
4687
|
this.lifecycle = this._mockLifecyclesApi;
|
|
5093
|
-
this.simulation =
|
|
4688
|
+
this.simulation = createUnavailableSimulationApi();
|
|
5094
4689
|
this.rooms = createUnavailableRoomsApi();
|
|
5095
4690
|
this.logging = new MockLoggingApi();
|
|
5096
4691
|
this.iap = new MockIapApi();
|
|
@@ -5106,40 +4701,17 @@ var MockHost = class {
|
|
|
5106
4701
|
}
|
|
5107
4702
|
initialize(options) {
|
|
5108
4703
|
this._isInitialized = true;
|
|
5109
|
-
|
|
4704
|
+
this.venusApi._profileData = this.profile.getCurrentProfile();
|
|
4705
|
+
this.venusApi._deviceData = this.system.getDevice();
|
|
4706
|
+
this.venusApi._environmentData = this.system.getEnvironment();
|
|
4707
|
+
this.venusApi._localeData = this.venusApi._mock?.locale || "en-US";
|
|
4708
|
+
this.venusApi._languageCodeData = this.venusApi._mock?.languageCode || "en";
|
|
5110
4709
|
return Promise.resolve({
|
|
5111
4710
|
initializeAsleep: false,
|
|
5112
|
-
|
|
5113
|
-
top: controls.feedHeader.height,
|
|
5114
|
-
bottom: 0,
|
|
5115
|
-
left: 0,
|
|
5116
|
-
right: 0
|
|
5117
|
-
}
|
|
4711
|
+
safeArea: this.venusApi._safeAreaData
|
|
5118
4712
|
});
|
|
5119
4713
|
}
|
|
5120
|
-
updateUiControls() {
|
|
5121
|
-
const controls = {
|
|
5122
|
-
closeButton: { x: 16, y: 16, width: 32, height: 32 },
|
|
5123
|
-
menuButton: {
|
|
5124
|
-
x: window.innerWidth - 48,
|
|
5125
|
-
y: 16,
|
|
5126
|
-
width: 32,
|
|
5127
|
-
height: 32
|
|
5128
|
-
},
|
|
5129
|
-
feedHeader: { x: 0, y: 0, width: window.innerWidth, height: 56 },
|
|
5130
|
-
playButton: {
|
|
5131
|
-
x: 0,
|
|
5132
|
-
y: window.innerHeight - 60,
|
|
5133
|
-
width: window.innerWidth,
|
|
5134
|
-
height: 60
|
|
5135
|
-
}
|
|
5136
|
-
};
|
|
5137
|
-
return controls;
|
|
5138
|
-
}
|
|
5139
4714
|
createOverlay() {
|
|
5140
|
-
const venusApi = this.venusApi;
|
|
5141
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
5142
|
-
const uiControls = venusApi.config.ui.controls;
|
|
5143
4715
|
const overlayContainer = document.createElement("div");
|
|
5144
4716
|
overlayContainer.id = "venus-mock-overlay";
|
|
5145
4717
|
overlayContainer.style.cssText = `
|
|
@@ -5155,7 +4727,7 @@ var MockHost = class {
|
|
|
5155
4727
|
const menuButton = this.createOverlayButton(
|
|
5156
4728
|
"close",
|
|
5157
4729
|
"Menu",
|
|
5158
|
-
|
|
4730
|
+
{ x: window.innerWidth - 48, y: 16, width: 32, height: 32 },
|
|
5159
4731
|
() => {
|
|
5160
4732
|
this.handleMenuButtonClicked();
|
|
5161
4733
|
},
|
|
@@ -5384,17 +4956,13 @@ var MockHost = class {
|
|
|
5384
4956
|
return button;
|
|
5385
4957
|
}
|
|
5386
4958
|
updateOverlayLayout() {
|
|
5387
|
-
const venusApi = this.venusApi;
|
|
5388
4959
|
const overlay = this._overlay;
|
|
5389
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
5390
|
-
const uiControls = venusApi.config.ui.controls;
|
|
5391
4960
|
const menuBtn = overlay.elements.menuButton;
|
|
5392
|
-
|
|
5393
|
-
menuBtn.style.
|
|
5394
|
-
menuBtn.style.
|
|
5395
|
-
menuBtn.style.
|
|
5396
|
-
menuBtn.style.
|
|
5397
|
-
menuBtn.style.height = `${menuPos.height}px`;
|
|
4961
|
+
menuBtn.style.left = `${window.innerWidth - 48}px`;
|
|
4962
|
+
menuBtn.style.top = "16px";
|
|
4963
|
+
menuBtn.style.width = "32px";
|
|
4964
|
+
menuBtn.style.minWidth = "32px";
|
|
4965
|
+
menuBtn.style.height = "32px";
|
|
5398
4966
|
}
|
|
5399
4967
|
triggerLifecycleEvent(name) {
|
|
5400
4968
|
console.log("Trigger Lifecycle Event: ", name);
|
|
@@ -5585,10 +5153,8 @@ var MockHost = class {
|
|
|
5585
5153
|
// src/Host.ts
|
|
5586
5154
|
function createHost(venusApi, isMock) {
|
|
5587
5155
|
if (isMock) {
|
|
5588
|
-
console.log("[Venus SDK] Creating Local Host");
|
|
5589
5156
|
return new MockHost(venusApi);
|
|
5590
5157
|
} else {
|
|
5591
|
-
console.log("[Venus SDK] Creating Remote Host");
|
|
5592
5158
|
return new RemoteHost(venusApi);
|
|
5593
5159
|
}
|
|
5594
5160
|
}
|
|
@@ -5601,6 +5167,6 @@ function initializeSocial(venusApi, host) {
|
|
|
5601
5167
|
};
|
|
5602
5168
|
}
|
|
5603
5169
|
|
|
5604
|
-
export { DEFAULT_SHARED_LIB_CDN_BASE, EMBEDDED_LIBRARIES, EMBEDDED_LIBRARY_BY_KEY, HASH_ALGORITHM_NODE, HASH_ALGORITHM_WEB_CRYPTO, HapticFeedbackStyle, HostCdnApi, HostProfileApi, HostTimeApi, MODULE_TO_LIBRARY_SPECIFIERS, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLeaderboardApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi,
|
|
5605
|
-
//# sourceMappingURL=chunk-
|
|
5606
|
-
//# sourceMappingURL=chunk-
|
|
5170
|
+
export { DEFAULT_SHARED_LIB_CDN_BASE, EMBEDDED_LIBRARIES, EMBEDDED_LIBRARY_BY_KEY, HASH_ALGORITHM_NODE, HASH_ALGORITHM_WEB_CRYPTO, HapticFeedbackStyle, HostCdnApi, HostDeviceApi, HostEnvironmentApi, HostProfileApi, HostSystemApi, HostTimeApi, MODULE_TO_LIBRARY_SPECIFIERS, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockDeviceApi, MockEnvironmentApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLeaderboardApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi, MockSocialApi, MockStorageApi, MockSystemApi, MockTimeApi, RemoteHost, RpcAdsApi, RpcAiApi, RpcAnalyticsApi, RpcAvatarApi, RpcClient, RpcFeaturesApi, RpcHapticsApi, RpcIapApi, RpcLeaderboardApi, RpcLifecycleApi, RpcLoggingApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, RpcPreloaderApi, RpcRoomsApi, RpcSharedAssetsApi, RpcSimulationApi, RpcSocialApi, RpcStorageApi, SDK_VERSION, VenusMessageId, VenusRoom, base64ToArrayBuffer, base64ToUtf8, computeScoreHash, createHost, createMockStorageApi, getLibraryDefinition, initializeAds, initializeAi, initializeAnalytics, initializeAvatar3d, initializeCdn, initializeFeaturesApi, initializeHaptics, initializeIap, initializeLeaderboard, initializeLifecycleApi, initializeLocalNotifications, initializeLoggingApi, initializePopups, initializePreloader, initializeProfile, initializeRoomsApi, initializeSimulation, initializeSocial, initializeStackNavigation, initializeStorage, initializeSystem, initializeTime, isPacificDaylightTime, setupRoomNotifications };
|
|
5171
|
+
//# sourceMappingURL=chunk-FTIFUYDL.mjs.map
|
|
5172
|
+
//# sourceMappingURL=chunk-FTIFUYDL.mjs.map
|