@series-inc/venus-sdk 3.0.3 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -979
- package/dist/{AdsApi-CNGRf6j0.d.mts → AdsApi-CIXV8I_p.d.mts} +389 -186
- package/dist/{AdsApi-CNGRf6j0.d.ts → AdsApi-CIXV8I_p.d.ts} +389 -186
- package/dist/{chunk-JO6V5EXF.mjs → chunk-LBJFUHOH.mjs} +951 -1372
- package/dist/chunk-LBJFUHOH.mjs.map +1 -0
- package/dist/{chunk-W7IPHM67.mjs → chunk-MWUS3A7C.mjs} +3 -22
- package/dist/chunk-MWUS3A7C.mjs.map +1 -0
- package/dist/core-RDMPQV6U.mjs +3 -0
- package/dist/{core-R3FHW62G.mjs.map → core-RDMPQV6U.mjs.map} +1 -1
- package/dist/index.cjs +947 -1388
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +142 -79
- package/dist/index.d.ts +142 -79
- package/dist/index.mjs +2 -6
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +1014 -1720
- 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 +43 -308
- package/dist/venus-api/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-JO6V5EXF.mjs.map +0 -1
- package/dist/chunk-W7IPHM67.mjs.map +0 -1
- package/dist/core-R3FHW62G.mjs +0 -3
package/dist/venus-api/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
6
|
var __esm = (fn, res) => function __init() {
|
|
9
7
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
@@ -12,15 +10,6 @@ var __export = (target, all) => {
|
|
|
12
10
|
for (var name in all)
|
|
13
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
12
|
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
13
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
14
|
|
|
26
15
|
// src/venus-api/systems/core.js
|
|
@@ -111,221 +100,6 @@ var init_core = __esm({
|
|
|
111
100
|
}
|
|
112
101
|
});
|
|
113
102
|
|
|
114
|
-
// src/rooms/RoomsApi.ts
|
|
115
|
-
var init_RoomsApi = __esm({
|
|
116
|
-
"src/rooms/RoomsApi.ts"() {
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// src/rooms/VenusRoom.ts
|
|
121
|
-
var VenusRoom;
|
|
122
|
-
var init_VenusRoom = __esm({
|
|
123
|
-
"src/rooms/VenusRoom.ts"() {
|
|
124
|
-
VenusRoom = class {
|
|
125
|
-
constructor(roomData) {
|
|
126
|
-
__publicField(this, "id");
|
|
127
|
-
__publicField(this, "name");
|
|
128
|
-
__publicField(this, "players");
|
|
129
|
-
__publicField(this, "maxPlayers");
|
|
130
|
-
__publicField(this, "gameType");
|
|
131
|
-
__publicField(this, "appId");
|
|
132
|
-
__publicField(this, "type");
|
|
133
|
-
__publicField(this, "createdBy");
|
|
134
|
-
__publicField(this, "createdAt");
|
|
135
|
-
__publicField(this, "updatedAt");
|
|
136
|
-
__publicField(this, "isPrivate");
|
|
137
|
-
__publicField(this, "currentPlayers");
|
|
138
|
-
__publicField(this, "status");
|
|
139
|
-
__publicField(this, "customMetadata");
|
|
140
|
-
__publicField(this, "admins");
|
|
141
|
-
__publicField(this, "roomCode");
|
|
142
|
-
__publicField(this, "description");
|
|
143
|
-
__publicField(this, "data");
|
|
144
|
-
__publicField(this, "version");
|
|
145
|
-
__publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
146
|
-
this.id = roomData.id;
|
|
147
|
-
this.name = roomData.name;
|
|
148
|
-
this.players = roomData.currentPlayers || [];
|
|
149
|
-
this.maxPlayers = roomData.maxPlayers;
|
|
150
|
-
this.gameType = roomData.gameType;
|
|
151
|
-
this.appId = roomData.appId;
|
|
152
|
-
this.type = roomData.type;
|
|
153
|
-
this.createdBy = roomData.createdBy;
|
|
154
|
-
this.createdAt = roomData.createdAt;
|
|
155
|
-
this.updatedAt = roomData.updatedAt;
|
|
156
|
-
this.isPrivate = roomData.isPrivate;
|
|
157
|
-
this.currentPlayers = roomData.currentPlayers || [];
|
|
158
|
-
this.status = roomData.status;
|
|
159
|
-
this.customMetadata = roomData.customMetadata || {};
|
|
160
|
-
this.admins = roomData.admins || [];
|
|
161
|
-
this.roomCode = roomData.roomCode;
|
|
162
|
-
this.description = roomData.description;
|
|
163
|
-
this.data = roomData.data || {};
|
|
164
|
-
this.version = roomData.version;
|
|
165
|
-
console.log(`VenusRoom: Created room object for ${this.id}`, {
|
|
166
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
167
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
168
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
169
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
updateFromRoomData(newRoomData) {
|
|
173
|
-
if (newRoomData.id === this.id) {
|
|
174
|
-
this.name = newRoomData.name || this.name;
|
|
175
|
-
this.players = newRoomData.currentPlayers || this.players;
|
|
176
|
-
this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
|
|
177
|
-
this.gameType = newRoomData.gameType || this.gameType;
|
|
178
|
-
this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
|
|
179
|
-
this.customMetadata = newRoomData.customMetadata || this.customMetadata;
|
|
180
|
-
this.data = newRoomData.data || this.data;
|
|
181
|
-
this.status = newRoomData.status || this.status;
|
|
182
|
-
this.updatedAt = newRoomData.updatedAt || this.updatedAt;
|
|
183
|
-
console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
|
|
184
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
185
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
186
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
187
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// src/rooms/index.ts
|
|
196
|
-
var rooms_exports = {};
|
|
197
|
-
__export(rooms_exports, {
|
|
198
|
-
VenusRoom: () => VenusRoom,
|
|
199
|
-
initializeRoomsApi: () => initializeRoomsApi,
|
|
200
|
-
setupRoomNotifications: () => setupRoomNotifications
|
|
201
|
-
});
|
|
202
|
-
function bindMethod(target, targetKey, source, sourceKey) {
|
|
203
|
-
const key = sourceKey ?? targetKey;
|
|
204
|
-
const fn = source?.[key];
|
|
205
|
-
if (typeof fn === "function") {
|
|
206
|
-
target[targetKey] = fn.bind(source);
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
function setupRoomNotifications(transport, getSubscriptions) {
|
|
212
|
-
console.log("[Venus Rooms] Setting up room notification listeners");
|
|
213
|
-
return transport.onVenusMessage((message) => {
|
|
214
|
-
const subscriptions = getSubscriptions();
|
|
215
|
-
if (!subscriptions) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (message.type === "H5_ROOM_DATA_UPDATED") {
|
|
219
|
-
const messageData = message.data;
|
|
220
|
-
const { roomId, roomData } = messageData;
|
|
221
|
-
if (!roomId) return;
|
|
222
|
-
const callbacks = subscriptions.data?.[roomId] || [];
|
|
223
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
224
|
-
console.log(`[Venus Rooms] \u{1F514} Room data updated for ${roomId}, notifying ${callbacks.length} callbacks`, roomData);
|
|
225
|
-
callbacks.forEach((callback) => {
|
|
226
|
-
try {
|
|
227
|
-
callback(roomData);
|
|
228
|
-
} catch (error) {
|
|
229
|
-
console.error("[Venus Rooms] Error in room data callback:", error);
|
|
230
|
-
throw error;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
allEventsCallbacks.forEach((callback) => {
|
|
234
|
-
try {
|
|
235
|
-
callback({ type: message.type, ...messageData });
|
|
236
|
-
} catch (error) {
|
|
237
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
|
|
243
|
-
const messageData = message.data;
|
|
244
|
-
const { roomId } = messageData;
|
|
245
|
-
if (!roomId) return;
|
|
246
|
-
const callbacks = subscriptions.messages?.[roomId] || [];
|
|
247
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
248
|
-
console.log(`[Venus Rooms] \u{1F514} Room message event for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
249
|
-
callbacks.forEach((callback) => {
|
|
250
|
-
try {
|
|
251
|
-
callback(messageData);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
console.error("[Venus Rooms] Error in room message callback:", error);
|
|
254
|
-
throw error;
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
allEventsCallbacks.forEach((callback) => {
|
|
258
|
-
try {
|
|
259
|
-
callback({ type: message.type, ...messageData });
|
|
260
|
-
} catch (error) {
|
|
261
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
262
|
-
throw error;
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
if (message.type === "app:h5:proposedMoveValidationUpdated") {
|
|
267
|
-
const messageData = message.data;
|
|
268
|
-
const { roomId } = messageData;
|
|
269
|
-
if (!roomId) return;
|
|
270
|
-
const callbacks = subscriptions.gameEvents?.[roomId] || [];
|
|
271
|
-
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
272
|
-
console.log(`[Venus Rooms] \u{1F514} Proposed move validation updated for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
273
|
-
callbacks.forEach((callback) => {
|
|
274
|
-
try {
|
|
275
|
-
callback(messageData);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error("[Venus Rooms] Error in game event callback:", error);
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
allEventsCallbacks.forEach((callback) => {
|
|
282
|
-
try {
|
|
283
|
-
callback({ type: message.type, ...messageData });
|
|
284
|
-
} catch (error) {
|
|
285
|
-
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function initializeRoomsApi(venusApi, host) {
|
|
293
|
-
const roomsApi = host?.rooms;
|
|
294
|
-
if (!roomsApi) {
|
|
295
|
-
console.warn(
|
|
296
|
-
"[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
|
|
297
|
-
);
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
const venus = venusApi;
|
|
301
|
-
const existingNamespace = venus.rooms || {};
|
|
302
|
-
const roomsNamespace = Object.assign({}, existingNamespace);
|
|
303
|
-
const namespaceBindings = [
|
|
304
|
-
["create", "createRoom"],
|
|
305
|
-
["joinOrCreate", "joinOrCreateRoom"],
|
|
306
|
-
["joinByCode", "joinRoomByCode"],
|
|
307
|
-
["list", "getUserRooms"],
|
|
308
|
-
["subscribeToRoom", "subscribe"],
|
|
309
|
-
["updateRoomData", "updateData"],
|
|
310
|
-
["getRoomData", "getData"],
|
|
311
|
-
["sendRoomMessage", "sendMessage"],
|
|
312
|
-
["leaveRoom", "leave"],
|
|
313
|
-
["startRoomGame", "startGame"],
|
|
314
|
-
["proposeMove"],
|
|
315
|
-
["validateMove"]
|
|
316
|
-
];
|
|
317
|
-
namespaceBindings.forEach(([targetKey, sourceKey]) => {
|
|
318
|
-
bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
|
|
319
|
-
});
|
|
320
|
-
venus.rooms = roomsNamespace;
|
|
321
|
-
}
|
|
322
|
-
var init_rooms = __esm({
|
|
323
|
-
"src/rooms/index.ts"() {
|
|
324
|
-
init_RoomsApi();
|
|
325
|
-
init_VenusRoom();
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
103
|
// src/storage/MockStorageApi.ts
|
|
330
104
|
function createMockStorageApi(storageType, appUrl) {
|
|
331
105
|
const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
|
|
@@ -635,190 +409,6 @@ function initializeAds(venusApiInstance, host) {
|
|
|
635
409
|
venusApiInstance.ads = host.ads;
|
|
636
410
|
}
|
|
637
411
|
|
|
638
|
-
// src/venus-api/systems/theme.js
|
|
639
|
-
init_core();
|
|
640
|
-
var DEFAULT_TYPOGRAPHY = {
|
|
641
|
-
fontFamily: {
|
|
642
|
-
base: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
643
|
-
heading: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
644
|
-
mono: "monospace"
|
|
645
|
-
},
|
|
646
|
-
fontSize: {
|
|
647
|
-
"2xs": "10px",
|
|
648
|
-
xs: "12px",
|
|
649
|
-
sm: "14px",
|
|
650
|
-
md: "16px",
|
|
651
|
-
lg: "18px",
|
|
652
|
-
xl: "20px",
|
|
653
|
-
"2xl": "24px",
|
|
654
|
-
"3xl": "30px",
|
|
655
|
-
"4xl": "36px",
|
|
656
|
-
"5xl": "48px",
|
|
657
|
-
"6xl": "60px"
|
|
658
|
-
},
|
|
659
|
-
fontWeight: {
|
|
660
|
-
thin: "100",
|
|
661
|
-
extralight: "200",
|
|
662
|
-
light: "300",
|
|
663
|
-
regular: "400",
|
|
664
|
-
medium: "500",
|
|
665
|
-
semibold: "600",
|
|
666
|
-
bold: "700",
|
|
667
|
-
extrabold: "800",
|
|
668
|
-
black: "900",
|
|
669
|
-
extrablack: "950"
|
|
670
|
-
},
|
|
671
|
-
lineHeight: {
|
|
672
|
-
none: "1",
|
|
673
|
-
tight: "1.25",
|
|
674
|
-
snug: "1.375",
|
|
675
|
-
normal: "1.5",
|
|
676
|
-
relaxed: "1.625",
|
|
677
|
-
loose: "2"
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
var DEFAULT_THEME = {
|
|
681
|
-
background: {
|
|
682
|
-
default: "#131419",
|
|
683
|
-
// Dark background
|
|
684
|
-
muted: "#1b1d25",
|
|
685
|
-
// Mid-dark background
|
|
686
|
-
dark: "#0d0e11"
|
|
687
|
-
// Darker background
|
|
688
|
-
},
|
|
689
|
-
text: {
|
|
690
|
-
primary: "#ffffff",
|
|
691
|
-
// White
|
|
692
|
-
muted: "#808080",
|
|
693
|
-
// Gray
|
|
694
|
-
inverted: "#000000"
|
|
695
|
-
// Black
|
|
696
|
-
},
|
|
697
|
-
theme: {
|
|
698
|
-
primary: "#f6c833",
|
|
699
|
-
// Different yellow for testing (slightly lighter)
|
|
700
|
-
secondary: "#6366f1",
|
|
701
|
-
// Different secondary for testing (purple)
|
|
702
|
-
background: "#131419",
|
|
703
|
-
// Dark background
|
|
704
|
-
border: "#262626",
|
|
705
|
-
// Dark border
|
|
706
|
-
card: "#1b1d25",
|
|
707
|
-
// Dark card
|
|
708
|
-
"card-glass": "rgba(27, 29, 37, 0.8)"
|
|
709
|
-
// Translucent dark card
|
|
710
|
-
},
|
|
711
|
-
typography: DEFAULT_TYPOGRAPHY
|
|
712
|
-
};
|
|
713
|
-
function initializeTheme(venusApiInstance) {
|
|
714
|
-
if (!venusApiInstance._mock.theme) {
|
|
715
|
-
venusApiInstance._mock.theme = DEFAULT_THEME;
|
|
716
|
-
}
|
|
717
|
-
if (!venusApiInstance._mock.typography) {
|
|
718
|
-
venusApiInstance._mock.typography = DEFAULT_TYPOGRAPHY;
|
|
719
|
-
}
|
|
720
|
-
if (!venusApiInstance._mock.safeArea) {
|
|
721
|
-
venusApiInstance._mock.safeArea = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
722
|
-
}
|
|
723
|
-
venusApiInstance.applyVenusThemeToCSS = function(theme) {
|
|
724
|
-
if (!theme) return;
|
|
725
|
-
const root = document.documentElement;
|
|
726
|
-
if (theme.background) {
|
|
727
|
-
if (theme.background.default)
|
|
728
|
-
root.style.setProperty("--color-background", theme.background.default);
|
|
729
|
-
if (theme.background.muted)
|
|
730
|
-
root.style.setProperty(
|
|
731
|
-
"--color-background-muted",
|
|
732
|
-
theme.background.muted
|
|
733
|
-
);
|
|
734
|
-
if (theme.background.dark)
|
|
735
|
-
root.style.setProperty(
|
|
736
|
-
"--color-background-dark",
|
|
737
|
-
theme.background.dark
|
|
738
|
-
);
|
|
739
|
-
}
|
|
740
|
-
if (theme.text) {
|
|
741
|
-
if (theme.text.primary)
|
|
742
|
-
root.style.setProperty("--color-text-primary", theme.text.primary);
|
|
743
|
-
if (theme.text.muted)
|
|
744
|
-
root.style.setProperty("--color-text-muted", theme.text.muted);
|
|
745
|
-
}
|
|
746
|
-
if (theme.theme) {
|
|
747
|
-
if (theme.theme.primary)
|
|
748
|
-
root.style.setProperty("--color-primary", theme.theme.primary);
|
|
749
|
-
if (theme.theme.secondary)
|
|
750
|
-
root.style.setProperty("--color-secondary", theme.theme.secondary);
|
|
751
|
-
if (theme.theme.border)
|
|
752
|
-
root.style.setProperty("--color-border", theme.theme.border);
|
|
753
|
-
}
|
|
754
|
-
if (theme.typography && theme.typography.fontFamily) {
|
|
755
|
-
if (theme.typography.fontFamily.base) {
|
|
756
|
-
root.style.setProperty(
|
|
757
|
-
"--font-family",
|
|
758
|
-
theme.typography.fontFamily.base
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
document.body.style.backgroundColor = root.style.getPropertyValue(
|
|
763
|
-
"--color-background-dark"
|
|
764
|
-
);
|
|
765
|
-
};
|
|
766
|
-
venusApiInstance.applyTheme = createProxiedMethod("applyTheme", function() {
|
|
767
|
-
let apiTheme = null;
|
|
768
|
-
apiTheme = this.config.theme;
|
|
769
|
-
if (apiTheme) {
|
|
770
|
-
this.applyVenusThemeToCSS(apiTheme);
|
|
771
|
-
this.colors = {
|
|
772
|
-
primary: apiTheme.theme?.primary || "#FF2877",
|
|
773
|
-
secondary: apiTheme.theme?.secondary || "#4755FF",
|
|
774
|
-
dark: apiTheme.background?.dark || "#0D0E11",
|
|
775
|
-
darkLight: apiTheme.background?.muted || "#1B1D25",
|
|
776
|
-
darkLighter: apiTheme.background?.default || "#23252F",
|
|
777
|
-
textPrimary: apiTheme.text?.primary || "#FFFFFF",
|
|
778
|
-
textMuted: apiTheme.text?.muted || "#808080",
|
|
779
|
-
border: apiTheme.theme?.border || "#262626"
|
|
780
|
-
};
|
|
781
|
-
} else {
|
|
782
|
-
this.colors = {
|
|
783
|
-
primary: "#FF2877",
|
|
784
|
-
secondary: "#4755FF",
|
|
785
|
-
dark: "#0D0E11",
|
|
786
|
-
darkLight: "#1B1D25",
|
|
787
|
-
darkLighter: "#23252F",
|
|
788
|
-
textPrimary: "#FFFFFF",
|
|
789
|
-
textMuted: "#808080",
|
|
790
|
-
border: "#262626"
|
|
791
|
-
};
|
|
792
|
-
}
|
|
793
|
-
this.log("Theme applied successfully");
|
|
794
|
-
});
|
|
795
|
-
venusApiInstance.applySafeArea = createProxiedMethod("applySafeArea", function() {
|
|
796
|
-
try {
|
|
797
|
-
const safeArea = this.config.ui.safeArea;
|
|
798
|
-
if (safeArea) {
|
|
799
|
-
this.log("Applying safe area insets: " + JSON.stringify(safeArea));
|
|
800
|
-
if (this.tapToStartScreen) {
|
|
801
|
-
this.tapToStartScreen.style.marginTop = `${safeArea.top}px`;
|
|
802
|
-
this.tapToStartScreen.style.marginBottom = `${safeArea.bottom}px`;
|
|
803
|
-
}
|
|
804
|
-
if (this.gameOverScreen) {
|
|
805
|
-
this.gameOverScreen.style.marginTop = `${safeArea.top}px`;
|
|
806
|
-
this.gameOverScreen.style.marginBottom = `${safeArea.bottom}px`;
|
|
807
|
-
}
|
|
808
|
-
if (this.maxScoreContainer) {
|
|
809
|
-
this.maxScoreContainer.style.marginTop = `${safeArea.top}px`;
|
|
810
|
-
this.maxScoreContainer.style.marginRight = `${safeArea.right}px`;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
} catch (error) {
|
|
814
|
-
this.error("Error applying safe area: " + error.message);
|
|
815
|
-
console.error("Error applying safe area:", error);
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
venusApiInstance.DEFAULT_THEME = DEFAULT_THEME;
|
|
819
|
-
venusApiInstance.DEFAULT_TYPOGRAPHY = DEFAULT_TYPOGRAPHY;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
412
|
// src/popups/RpcPopupsApi.ts
|
|
823
413
|
var RpcPopupsApi = class {
|
|
824
414
|
constructor(rpcClient) {
|
|
@@ -971,13 +561,8 @@ var MockNotificationsApi = class {
|
|
|
971
561
|
async cancelNotification(notificationId) {
|
|
972
562
|
const venusApi = this.venusApi;
|
|
973
563
|
if (isWebPlatform()) {
|
|
974
|
-
console.log(
|
|
975
|
-
"[Venus Mock] Cancel notification on web platform (simulated):",
|
|
976
|
-
notificationId
|
|
977
|
-
);
|
|
978
564
|
return true;
|
|
979
565
|
}
|
|
980
|
-
console.log("[Venus Mock] Cancel local notification:", notificationId);
|
|
981
566
|
await createMockDelay(MOCK_DELAYS.short);
|
|
982
567
|
if (venusApi._mock.scheduledNotifications && venusApi._mock.scheduledNotifications[notificationId]) {
|
|
983
568
|
delete venusApi._mock.scheduledNotifications[notificationId];
|
|
@@ -987,12 +572,8 @@ var MockNotificationsApi = class {
|
|
|
987
572
|
}
|
|
988
573
|
async getAllScheduledLocalNotifications() {
|
|
989
574
|
if (isWebPlatform()) {
|
|
990
|
-
console.log(
|
|
991
|
-
"[Venus Mock] Get notifications on web platform (returning empty list)"
|
|
992
|
-
);
|
|
993
575
|
return [];
|
|
994
576
|
}
|
|
995
|
-
console.log("[Venus Mock] Get all scheduled local notifications");
|
|
996
577
|
await createMockDelay(MOCK_DELAYS.short);
|
|
997
578
|
const venusApi = this.venusApi;
|
|
998
579
|
const notifications = venusApi._mock.scheduledNotifications || {};
|
|
@@ -1000,10 +581,8 @@ var MockNotificationsApi = class {
|
|
|
1000
581
|
}
|
|
1001
582
|
async isLocalNotificationsEnabled() {
|
|
1002
583
|
if (isWebPlatform()) {
|
|
1003
|
-
console.log("[Venus Mock] Notifications not available on web platform");
|
|
1004
584
|
return false;
|
|
1005
585
|
}
|
|
1006
|
-
console.log("[Venus Mock] Check if local notifications are enabled");
|
|
1007
586
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1008
587
|
const venusApi = this.venusApi;
|
|
1009
588
|
const isEnabled = venusApi._mock.notificationsEnabled !== false;
|
|
@@ -1012,9 +591,6 @@ var MockNotificationsApi = class {
|
|
|
1012
591
|
async scheduleAsync(title, body, seconds, notificationId, options) {
|
|
1013
592
|
const { priority = 50, groupId, payload } = options || {};
|
|
1014
593
|
if (isWebPlatform()) {
|
|
1015
|
-
console.log(
|
|
1016
|
-
"[Venus Mock] Notifications not supported on web platform, simulating success"
|
|
1017
|
-
);
|
|
1018
594
|
console.info(
|
|
1019
595
|
"\u{1F514} [Venus Mock] Notification would be scheduled:",
|
|
1020
596
|
title || "Untitled",
|
|
@@ -1025,14 +601,11 @@ var MockNotificationsApi = class {
|
|
|
1025
601
|
const mockId = `mock-web-notification-${Date.now()}`;
|
|
1026
602
|
return mockId;
|
|
1027
603
|
}
|
|
1028
|
-
console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
|
|
1029
604
|
const venusApi = this.venusApi;
|
|
1030
605
|
if (!venusApi._mock.pendingRequests) {
|
|
1031
|
-
console.log("[Venus Mock] Initializing pendingRequests");
|
|
1032
606
|
venusApi._mock.pendingRequests = {};
|
|
1033
607
|
}
|
|
1034
608
|
const requestId = Date.now().toString();
|
|
1035
|
-
console.log("[Venus Mock] Creating request with ID:", requestId);
|
|
1036
609
|
return new Promise((resolve) => {
|
|
1037
610
|
venusApi._mock.pendingRequests[requestId] = { resolve };
|
|
1038
611
|
const id = notificationId || `mock-notification-${Date.now()}`;
|
|
@@ -1054,13 +627,8 @@ var MockNotificationsApi = class {
|
|
|
1054
627
|
async setLocalNotificationsEnabled(enabled) {
|
|
1055
628
|
const venusApi = this.venusApi;
|
|
1056
629
|
if (isWebPlatform()) {
|
|
1057
|
-
console.log(
|
|
1058
|
-
"[Venus Mock] Set notifications enabled on web platform (simulated):",
|
|
1059
|
-
enabled
|
|
1060
|
-
);
|
|
1061
630
|
return true;
|
|
1062
631
|
}
|
|
1063
|
-
console.log("[Venus Mock] Set local notifications enabled:", enabled);
|
|
1064
632
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1065
633
|
venusApi._mock.notificationsEnabled = enabled;
|
|
1066
634
|
return enabled;
|
|
@@ -1157,9 +725,11 @@ function isPacificDaylightTime(date) {
|
|
|
1157
725
|
|
|
1158
726
|
// src/time/HostTimeApi.ts
|
|
1159
727
|
var HostTimeApi = class {
|
|
1160
|
-
constructor(rpcClient) {
|
|
728
|
+
constructor(rpcClient, venusApi) {
|
|
1161
729
|
__publicField(this, "rpcClient");
|
|
730
|
+
__publicField(this, "venusApi");
|
|
1162
731
|
this.rpcClient = rpcClient;
|
|
732
|
+
this.venusApi = venusApi;
|
|
1163
733
|
}
|
|
1164
734
|
async requestTimeAsync() {
|
|
1165
735
|
const response = await this.rpcClient.call(
|
|
@@ -1169,13 +739,7 @@ var HostTimeApi = class {
|
|
|
1169
739
|
return response;
|
|
1170
740
|
}
|
|
1171
741
|
formatTime(timestamp, options) {
|
|
1172
|
-
|
|
1173
|
-
const windowVenus = window.venus;
|
|
1174
|
-
if (windowVenus._config.locale) {
|
|
1175
|
-
locale = windowVenus._config.locale;
|
|
1176
|
-
} else if (windowVenus._config.environment && windowVenus._config.environment.browserInfo && windowVenus._config.environment.browserInfo.language) {
|
|
1177
|
-
locale = windowVenus._config.environment.browserInfo.language;
|
|
1178
|
-
}
|
|
742
|
+
const locale = this.venusApi.getLocale();
|
|
1179
743
|
const date = new Date(timestamp);
|
|
1180
744
|
const dateTimeOptions = {
|
|
1181
745
|
dateStyle: options.dateStyle || "medium",
|
|
@@ -1187,13 +751,7 @@ var HostTimeApi = class {
|
|
|
1187
751
|
}
|
|
1188
752
|
formatNumber(value, options) {
|
|
1189
753
|
try {
|
|
1190
|
-
|
|
1191
|
-
const windowVenus = window.venus;
|
|
1192
|
-
if (windowVenus._config.locale) {
|
|
1193
|
-
locale = windowVenus._config.locale;
|
|
1194
|
-
} else if (windowVenus._config.environment && windowVenus._config.environment.browserInfo && windowVenus._config.environment.browserInfo.language) {
|
|
1195
|
-
locale = windowVenus._config.environment.browserInfo.language;
|
|
1196
|
-
}
|
|
754
|
+
const locale = this.venusApi.getLocale();
|
|
1197
755
|
const numberOptions = {
|
|
1198
756
|
style: options?.style || "decimal",
|
|
1199
757
|
minimumFractionDigits: options?.minimumFractionDigits || 0,
|
|
@@ -1257,18 +815,17 @@ var MockTimeApi = class {
|
|
|
1257
815
|
this.venusApi = venusApi;
|
|
1258
816
|
}
|
|
1259
817
|
formatNumber(value, options) {
|
|
1260
|
-
const locale = this.getLocale();
|
|
818
|
+
const locale = this.venusApi.getLocale();
|
|
1261
819
|
const numberOptions = {
|
|
1262
820
|
style: options?.style || "decimal",
|
|
1263
821
|
minimumFractionDigits: options?.minimumFractionDigits || 0,
|
|
1264
822
|
maximumFractionDigits: options?.maximumFractionDigits || 2,
|
|
1265
823
|
...options
|
|
1266
824
|
};
|
|
1267
|
-
console.log(`[Venus Mock] Formatting number ${value} with locale ${locale}`);
|
|
1268
825
|
return value.toLocaleString(locale, numberOptions);
|
|
1269
826
|
}
|
|
1270
827
|
formatTime(timestamp, options) {
|
|
1271
|
-
const locale = this.getLocale();
|
|
828
|
+
const locale = this.venusApi.getLocale();
|
|
1272
829
|
const date = new Date(timestamp);
|
|
1273
830
|
const dateTimeOptions = {
|
|
1274
831
|
dateStyle: options.dateStyle || "medium",
|
|
@@ -1276,13 +833,9 @@ var MockTimeApi = class {
|
|
|
1276
833
|
hour12: options.hour12 !== void 0 ? options.hour12 : true,
|
|
1277
834
|
...options
|
|
1278
835
|
};
|
|
1279
|
-
console.log(
|
|
1280
|
-
`[Venus Mock] Formatting time ${timestamp} with locale ${locale}`
|
|
1281
|
-
);
|
|
1282
836
|
return date.toLocaleString(locale, dateTimeOptions);
|
|
1283
837
|
}
|
|
1284
838
|
async getFutureTimeAsync(options) {
|
|
1285
|
-
console.log("[Venus Mock] Getting future time with options:", options);
|
|
1286
839
|
const timeInfo = await this.requestTimeAsync();
|
|
1287
840
|
const serverTime = new Date(timeInfo.serverTime);
|
|
1288
841
|
const result = new Date(serverTime);
|
|
@@ -1327,7 +880,6 @@ var MockTimeApi = class {
|
|
|
1327
880
|
return result.getTime();
|
|
1328
881
|
}
|
|
1329
882
|
async requestTimeAsync() {
|
|
1330
|
-
console.log("[Venus Mock] Requesting time");
|
|
1331
883
|
await createMockDelay(MOCK_DELAYS.short);
|
|
1332
884
|
const venusApi = this.venusApi;
|
|
1333
885
|
const mockOffset = venusApi._mock.serverTimeOffset || 2500;
|
|
@@ -1341,23 +893,8 @@ var MockTimeApi = class {
|
|
|
1341
893
|
formattedTime: new Date(localTime).toISOString(),
|
|
1342
894
|
locale: venusApi._mock.user?.locale || "en-US"
|
|
1343
895
|
};
|
|
1344
|
-
console.log("[Venus Mock] Time response:", {
|
|
1345
|
-
serverTime: new Date(timeInfo.serverTime).toISOString(),
|
|
1346
|
-
localTime: new Date(timeInfo.localTime).toISOString(),
|
|
1347
|
-
timezoneOffset: timeInfo.timezoneOffset
|
|
1348
|
-
});
|
|
1349
896
|
return timeInfo;
|
|
1350
897
|
}
|
|
1351
|
-
getLocale() {
|
|
1352
|
-
const venusApi = this.venusApi;
|
|
1353
|
-
let locale = "en-US";
|
|
1354
|
-
if (venusApi._mock.user && venusApi._mock.user.locale) {
|
|
1355
|
-
locale = venusApi._mock.user.locale;
|
|
1356
|
-
} else if (venusApi._mock.environment && venusApi._mock.environment.browserInfo.language) {
|
|
1357
|
-
locale = venusApi._mock.environment.browserInfo.language;
|
|
1358
|
-
}
|
|
1359
|
-
return locale;
|
|
1360
|
-
}
|
|
1361
898
|
};
|
|
1362
899
|
|
|
1363
900
|
// src/time/index.ts
|
|
@@ -2206,14 +1743,11 @@ var VenusAssetLoader = class {
|
|
|
2206
1743
|
}, 1e4);
|
|
2207
1744
|
if (type === "image") {
|
|
2208
1745
|
const img = new Image();
|
|
2209
|
-
console.log(`\u{1F5BC}\uFE0F [Asset Verification] Verifying image: ${url}`);
|
|
2210
1746
|
img.onload = () => {
|
|
2211
|
-
console.log(`\u2705 [Asset Verification] Image verified successfully: ${url}`);
|
|
2212
1747
|
clearTimeout(timeout);
|
|
2213
1748
|
resolve();
|
|
2214
1749
|
};
|
|
2215
1750
|
img.onerror = (error) => {
|
|
2216
|
-
console.log(`\u274C [Asset Verification] Image verification failed: ${url}`, error);
|
|
2217
1751
|
clearTimeout(timeout);
|
|
2218
1752
|
reject(new Error("Failed to load image"));
|
|
2219
1753
|
};
|
|
@@ -2265,7 +1799,6 @@ var VenusAssetLoader = class {
|
|
|
2265
1799
|
const CDN_BASE_URL = "https://venus-static-01293ak.web.app/";
|
|
2266
1800
|
const cleanUrl = url.startsWith("/") ? url.slice(1) : url;
|
|
2267
1801
|
const fullUrl = CDN_BASE_URL + cleanUrl;
|
|
2268
|
-
console.log(`\u{1F310} [Asset Loader] Force remote CDN: ${url} -> ${fullUrl}`);
|
|
2269
1802
|
return fullUrl;
|
|
2270
1803
|
}
|
|
2271
1804
|
if (this.venusAPI && this.venusAPI.isMock && this.venusAPI.isMock()) {
|
|
@@ -3976,47 +3509,105 @@ function initializeIap(venusApiInstance, host) {
|
|
|
3976
3509
|
venusApiInstance.iap = host.iap;
|
|
3977
3510
|
}
|
|
3978
3511
|
|
|
3512
|
+
// src/leaderboard/utils.ts
|
|
3513
|
+
var HASH_ALGORITHM_WEB_CRYPTO = "SHA-256";
|
|
3514
|
+
async function computeScoreHash(score, duration, token, sealingNonce, sealingSecret) {
|
|
3515
|
+
const payload = `score:${score}|duration:${duration}|token:${token}`;
|
|
3516
|
+
const fullPayload = `${payload}|nonce:${sealingNonce}`;
|
|
3517
|
+
const encoder = new TextEncoder();
|
|
3518
|
+
const keyData = encoder.encode(sealingSecret);
|
|
3519
|
+
const messageData = encoder.encode(fullPayload);
|
|
3520
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
3521
|
+
"raw",
|
|
3522
|
+
keyData,
|
|
3523
|
+
{ name: "HMAC", hash: HASH_ALGORITHM_WEB_CRYPTO },
|
|
3524
|
+
false,
|
|
3525
|
+
["sign"]
|
|
3526
|
+
);
|
|
3527
|
+
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
3528
|
+
return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3529
|
+
}
|
|
3530
|
+
|
|
3979
3531
|
// src/leaderboard/RpcLeaderboardApi.ts
|
|
3980
3532
|
var RpcLeaderboardApi = class {
|
|
3981
3533
|
constructor(rpcClient) {
|
|
3982
3534
|
__publicField(this, "rpcClient");
|
|
3535
|
+
/** Cache of score tokens for automatic hash computation */
|
|
3536
|
+
__publicField(this, "tokenCache", /* @__PURE__ */ new Map());
|
|
3983
3537
|
this.rpcClient = rpcClient;
|
|
3984
3538
|
}
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3539
|
+
/**
|
|
3540
|
+
* Create a score token for submitting a score.
|
|
3541
|
+
* Token is cached for automatic hash computation if score sealing is enabled.
|
|
3542
|
+
*
|
|
3543
|
+
* @param mode - Optional game mode
|
|
3544
|
+
* @returns Score token with sealing data if enabled
|
|
3545
|
+
*/
|
|
3546
|
+
async createScoreToken(mode) {
|
|
3547
|
+
const token = await this.rpcClient.call(
|
|
3548
|
+
"H5_LEADERBOARD_CREATE_SCORE_TOKEN" /* H5_LEADERBOARD_CREATE_SCORE_TOKEN */,
|
|
3988
3549
|
mode ? { mode } : {}
|
|
3989
3550
|
);
|
|
3551
|
+
this.tokenCache.set(token.token, token);
|
|
3552
|
+
return token;
|
|
3990
3553
|
}
|
|
3991
|
-
|
|
3554
|
+
/**
|
|
3555
|
+
* Submit a score to the leaderboard.
|
|
3556
|
+
* Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
|
|
3557
|
+
*
|
|
3558
|
+
* @param params - Score submission parameters
|
|
3559
|
+
* @returns Submission result with acceptance status and rank
|
|
3560
|
+
* @throws Error if token not found in cache
|
|
3561
|
+
*/
|
|
3562
|
+
async submitScore(params) {
|
|
3563
|
+
let hash;
|
|
3564
|
+
if (params.token) {
|
|
3565
|
+
const cachedToken = this.tokenCache.get(params.token);
|
|
3566
|
+
if (!cachedToken) {
|
|
3567
|
+
throw new Error(
|
|
3568
|
+
"Invalid token: not found in cache. Did you call createScoreToken() first?"
|
|
3569
|
+
);
|
|
3570
|
+
}
|
|
3571
|
+
if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
|
|
3572
|
+
hash = await computeScoreHash(
|
|
3573
|
+
params.score,
|
|
3574
|
+
params.duration,
|
|
3575
|
+
params.token,
|
|
3576
|
+
cachedToken.sealingNonce,
|
|
3577
|
+
cachedToken.sealingSecret
|
|
3578
|
+
);
|
|
3579
|
+
}
|
|
3580
|
+
this.tokenCache.delete(params.token);
|
|
3581
|
+
}
|
|
3992
3582
|
return this.rpcClient.call(
|
|
3993
3583
|
"H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
|
|
3994
3584
|
{
|
|
3995
|
-
|
|
3996
|
-
score,
|
|
3997
|
-
|
|
3998
|
-
mode:
|
|
3999
|
-
telemetry:
|
|
4000
|
-
metadata:
|
|
4001
|
-
hash
|
|
3585
|
+
token: params.token,
|
|
3586
|
+
score: params.score,
|
|
3587
|
+
duration: params.duration,
|
|
3588
|
+
mode: params.mode,
|
|
3589
|
+
telemetry: params.telemetry,
|
|
3590
|
+
metadata: params.metadata,
|
|
3591
|
+
hash
|
|
3592
|
+
// undefined if no sealing, computed if sealing enabled
|
|
4002
3593
|
}
|
|
4003
3594
|
);
|
|
4004
3595
|
}
|
|
4005
|
-
|
|
3596
|
+
getPagedScores(options) {
|
|
4006
3597
|
return this.rpcClient.call(
|
|
4007
|
-
"
|
|
3598
|
+
"H5_LEADERBOARD_GET_PAGED_SCORES" /* H5_LEADERBOARD_GET_PAGED_SCORES */,
|
|
4008
3599
|
options ?? {}
|
|
4009
3600
|
);
|
|
4010
3601
|
}
|
|
4011
|
-
|
|
3602
|
+
getMyRank(options) {
|
|
4012
3603
|
return this.rpcClient.call(
|
|
4013
|
-
"
|
|
3604
|
+
"H5_LEADERBOARD_GET_MY_RANK" /* H5_LEADERBOARD_GET_MY_RANK */,
|
|
4014
3605
|
options ?? {}
|
|
4015
3606
|
);
|
|
4016
3607
|
}
|
|
4017
|
-
|
|
3608
|
+
getPodiumScores(options) {
|
|
4018
3609
|
return this.rpcClient.call(
|
|
4019
|
-
"
|
|
3610
|
+
"H5_LEADERBOARD_GET_PODIUM_SCORES" /* H5_LEADERBOARD_GET_PODIUM_SCORES */,
|
|
4020
3611
|
options ?? {}
|
|
4021
3612
|
);
|
|
4022
3613
|
}
|
|
@@ -4025,17 +3616,31 @@ var RpcLeaderboardApi = class {
|
|
|
4025
3616
|
// src/leaderboard/MockLeaderboardApi.ts
|
|
4026
3617
|
var MockLeaderboardApi = class {
|
|
4027
3618
|
constructor(options) {
|
|
4028
|
-
__publicField(this, "
|
|
3619
|
+
__publicField(this, "tokens", /* @__PURE__ */ new Map());
|
|
3620
|
+
/** Cache of score tokens for automatic hash computation */
|
|
3621
|
+
__publicField(this, "tokenCache", /* @__PURE__ */ new Map());
|
|
4029
3622
|
__publicField(this, "entriesByMode", /* @__PURE__ */ new Map());
|
|
4030
|
-
__publicField(this, "
|
|
4031
|
-
__publicField(this, "
|
|
4032
|
-
|
|
4033
|
-
|
|
3623
|
+
__publicField(this, "tokenCounter", 0);
|
|
3624
|
+
__publicField(this, "enableScoreSealing", false);
|
|
3625
|
+
__publicField(this, "scoreSealingSecret", "mock-leaderboard-secret-key");
|
|
3626
|
+
if (options?.enableScoreSealing) {
|
|
3627
|
+
this.enableScoreSealing = true;
|
|
3628
|
+
}
|
|
3629
|
+
if (options?.scoreSealingSecret) {
|
|
3630
|
+
this.scoreSealingSecret = options.scoreSealingSecret;
|
|
4034
3631
|
}
|
|
4035
3632
|
}
|
|
3633
|
+
/**
|
|
3634
|
+
* Configure mock leaderboard settings
|
|
3635
|
+
*
|
|
3636
|
+
* @param options - Configuration options
|
|
3637
|
+
*/
|
|
4036
3638
|
configure(options) {
|
|
4037
|
-
if (typeof options.
|
|
4038
|
-
this.
|
|
3639
|
+
if (typeof options.enableScoreSealing === "boolean") {
|
|
3640
|
+
this.enableScoreSealing = options.enableScoreSealing;
|
|
3641
|
+
}
|
|
3642
|
+
if (options.scoreSealingSecret) {
|
|
3643
|
+
this.scoreSealingSecret = options.scoreSealingSecret;
|
|
4039
3644
|
}
|
|
4040
3645
|
}
|
|
4041
3646
|
generateNonce() {
|
|
@@ -4052,83 +3657,149 @@ var MockLeaderboardApi = class {
|
|
|
4052
3657
|
}
|
|
4053
3658
|
return this.entriesByMode.get(key);
|
|
4054
3659
|
}
|
|
4055
|
-
|
|
4056
|
-
|
|
3660
|
+
/**
|
|
3661
|
+
* Create a mock score token for testing.
|
|
3662
|
+
* Token is cached for automatic hash computation if score sealing is enabled.
|
|
3663
|
+
*
|
|
3664
|
+
* @param mode - Optional game mode
|
|
3665
|
+
* @returns Score token with sealing data if enabled
|
|
3666
|
+
*/
|
|
3667
|
+
async createScoreToken(mode) {
|
|
3668
|
+
const token = `mock_token_${++this.tokenCounter}`;
|
|
4057
3669
|
const startTime = Date.now();
|
|
4058
3670
|
const expiresAt = startTime + 36e5;
|
|
4059
3671
|
const resolvedMode = mode || "default";
|
|
4060
|
-
const
|
|
4061
|
-
this.
|
|
4062
|
-
|
|
3672
|
+
const sealingNonce = this.enableScoreSealing ? this.generateNonce() : null;
|
|
3673
|
+
const sealingSecret = this.enableScoreSealing ? this.scoreSealingSecret : null;
|
|
3674
|
+
this.tokens.set(token, {
|
|
3675
|
+
id: token,
|
|
4063
3676
|
expiresAt,
|
|
4064
3677
|
mode: resolvedMode,
|
|
4065
|
-
|
|
3678
|
+
sealingNonce,
|
|
4066
3679
|
used: false
|
|
4067
3680
|
});
|
|
4068
|
-
|
|
4069
|
-
|
|
3681
|
+
const result = {
|
|
3682
|
+
token,
|
|
4070
3683
|
startTime,
|
|
4071
3684
|
expiresAt,
|
|
4072
|
-
|
|
3685
|
+
sealingNonce,
|
|
3686
|
+
sealingSecret,
|
|
4073
3687
|
mode: resolvedMode
|
|
4074
3688
|
};
|
|
3689
|
+
this.tokenCache.set(token, result);
|
|
3690
|
+
return result;
|
|
4075
3691
|
}
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
3692
|
+
/**
|
|
3693
|
+
* Submit a mock score to the leaderboard.
|
|
3694
|
+
* Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
|
|
3695
|
+
*
|
|
3696
|
+
* @param params - Score submission parameters
|
|
3697
|
+
* @returns Submission result with acceptance status and rank
|
|
3698
|
+
* @throws Error if token not found in cache or validation fails
|
|
3699
|
+
*/
|
|
3700
|
+
async submitScore(params) {
|
|
3701
|
+
let hash;
|
|
3702
|
+
if (params.token) {
|
|
3703
|
+
const cachedToken = this.tokenCache.get(params.token);
|
|
3704
|
+
if (!cachedToken) {
|
|
3705
|
+
throw new Error(
|
|
3706
|
+
"Invalid token: not found in cache. Did you call createScoreToken() first?"
|
|
3707
|
+
);
|
|
3708
|
+
}
|
|
3709
|
+
if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
|
|
3710
|
+
hash = await computeScoreHash(
|
|
3711
|
+
params.score,
|
|
3712
|
+
params.duration,
|
|
3713
|
+
params.token,
|
|
3714
|
+
cachedToken.sealingNonce,
|
|
3715
|
+
cachedToken.sealingSecret
|
|
3716
|
+
);
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
if (!params.token) {
|
|
3720
|
+
const mode = params.mode || "default";
|
|
3721
|
+
const submittedAt2 = Date.now();
|
|
3722
|
+
const entry2 = {
|
|
3723
|
+
profileId: `mock_profile`,
|
|
3724
|
+
username: "Mock Player",
|
|
3725
|
+
avatarUrl: null,
|
|
3726
|
+
score: params.score,
|
|
3727
|
+
duration: params.duration,
|
|
3728
|
+
submittedAt: submittedAt2,
|
|
3729
|
+
token: "simple-mode",
|
|
3730
|
+
rank: null,
|
|
3731
|
+
zScore: null,
|
|
3732
|
+
isAnomaly: false,
|
|
3733
|
+
trustScore: 50,
|
|
3734
|
+
metadata: params.metadata ?? null,
|
|
3735
|
+
isSeed: false
|
|
3736
|
+
};
|
|
3737
|
+
const modeEntries2 = this.getEntriesForMode(mode);
|
|
3738
|
+
modeEntries2.push(entry2);
|
|
3739
|
+
modeEntries2.sort((a, b) => {
|
|
3740
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
3741
|
+
return a.submittedAt - b.submittedAt;
|
|
3742
|
+
});
|
|
3743
|
+
modeEntries2.forEach((e, index) => {
|
|
3744
|
+
modeEntries2[index] = { ...e, rank: index + 1 };
|
|
3745
|
+
});
|
|
3746
|
+
const inserted2 = modeEntries2.find((e) => e.submittedAt === submittedAt2);
|
|
3747
|
+
return {
|
|
3748
|
+
accepted: true,
|
|
3749
|
+
rank: inserted2?.rank ?? null
|
|
3750
|
+
};
|
|
3751
|
+
}
|
|
3752
|
+
const scoreToken = this.tokens.get(params.token);
|
|
3753
|
+
if (!scoreToken) {
|
|
3754
|
+
throw new Error("Invalid score token");
|
|
4080
3755
|
}
|
|
4081
|
-
if (
|
|
4082
|
-
throw new Error("Invalid or expired
|
|
3756
|
+
if (scoreToken.expiresAt < Date.now()) {
|
|
3757
|
+
throw new Error("Invalid or expired score token");
|
|
4083
3758
|
}
|
|
4084
|
-
if (
|
|
4085
|
-
throw new Error("
|
|
3759
|
+
if (scoreToken.used) {
|
|
3760
|
+
throw new Error("Score token already used");
|
|
4086
3761
|
}
|
|
4087
|
-
if (
|
|
4088
|
-
throw new Error("Submission mode does not match
|
|
3762
|
+
if (params.mode && params.mode !== scoreToken.mode) {
|
|
3763
|
+
throw new Error("Submission mode does not match token mode");
|
|
4089
3764
|
}
|
|
4090
|
-
if (
|
|
4091
|
-
throw new Error("Score hash
|
|
3765
|
+
if (scoreToken.sealingNonce && !hash) {
|
|
3766
|
+
throw new Error("Score hash required when score sealing is enabled");
|
|
4092
3767
|
}
|
|
4093
3768
|
const submittedAt = Date.now();
|
|
4094
3769
|
const entry = {
|
|
4095
3770
|
profileId: `mock_profile`,
|
|
4096
3771
|
username: "Mock Player",
|
|
4097
3772
|
avatarUrl: null,
|
|
4098
|
-
score,
|
|
4099
|
-
|
|
3773
|
+
score: params.score,
|
|
3774
|
+
duration: params.duration,
|
|
4100
3775
|
submittedAt,
|
|
4101
|
-
|
|
3776
|
+
token: params.token,
|
|
4102
3777
|
rank: null,
|
|
4103
3778
|
zScore: null,
|
|
4104
3779
|
isAnomaly: false,
|
|
4105
3780
|
trustScore: 50,
|
|
4106
|
-
metadata:
|
|
3781
|
+
metadata: params.metadata ?? null,
|
|
4107
3782
|
isSeed: false
|
|
4108
3783
|
};
|
|
4109
|
-
const modeEntries = this.getEntriesForMode(
|
|
3784
|
+
const modeEntries = this.getEntriesForMode(scoreToken.mode);
|
|
4110
3785
|
modeEntries.push(entry);
|
|
4111
3786
|
modeEntries.sort((a, b) => {
|
|
4112
|
-
if (b.score !== a.score)
|
|
4113
|
-
return b.score - a.score;
|
|
4114
|
-
}
|
|
3787
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
4115
3788
|
return a.submittedAt - b.submittedAt;
|
|
4116
3789
|
});
|
|
4117
3790
|
modeEntries.forEach((e, index) => {
|
|
4118
|
-
modeEntries[index] = {
|
|
4119
|
-
...e,
|
|
4120
|
-
rank: index + 1
|
|
4121
|
-
};
|
|
3791
|
+
modeEntries[index] = { ...e, rank: index + 1 };
|
|
4122
3792
|
});
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
3793
|
+
scoreToken.used = true;
|
|
3794
|
+
scoreToken.sealingNonce = null;
|
|
3795
|
+
this.tokenCache.delete(params.token);
|
|
3796
|
+
const inserted = modeEntries.find((e) => e.token === params.token && e.submittedAt === submittedAt);
|
|
4126
3797
|
return {
|
|
4127
3798
|
accepted: true,
|
|
4128
3799
|
rank: inserted?.rank ?? null
|
|
4129
3800
|
};
|
|
4130
3801
|
}
|
|
4131
|
-
async
|
|
3802
|
+
async getPagedScores(options) {
|
|
4132
3803
|
const limit = options?.limit ?? 10;
|
|
4133
3804
|
const mode = options?.mode ?? "default";
|
|
4134
3805
|
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
@@ -4144,7 +3815,7 @@ var MockLeaderboardApi = class {
|
|
|
4144
3815
|
periodInstance: options?.period ?? "alltime"
|
|
4145
3816
|
};
|
|
4146
3817
|
}
|
|
4147
|
-
async
|
|
3818
|
+
async getMyRank(_options) {
|
|
4148
3819
|
const mode = _options?.mode ?? "default";
|
|
4149
3820
|
const modeEntries = this.getEntriesForMode(mode);
|
|
4150
3821
|
const playerEntry = modeEntries[0] ?? null;
|
|
@@ -4157,7 +3828,7 @@ var MockLeaderboardApi = class {
|
|
|
4157
3828
|
periodInstance: _options?.period ?? "alltime"
|
|
4158
3829
|
};
|
|
4159
3830
|
}
|
|
4160
|
-
async
|
|
3831
|
+
async getPodiumScores(options) {
|
|
4161
3832
|
const mode = options?.mode ?? "default";
|
|
4162
3833
|
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
4163
3834
|
const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
|
|
@@ -4366,7 +4037,8 @@ var MockCdnApi = class {
|
|
|
4366
4037
|
return index === pathParts.length - 1 ? encodeURIComponent(part) : part;
|
|
4367
4038
|
});
|
|
4368
4039
|
const encodedSubPath = encodedParts.join("/");
|
|
4369
|
-
const
|
|
4040
|
+
const cacheBust = Date.now();
|
|
4041
|
+
const fullUrl = `${this.baseUrl}${encodedSubPath}?cacheBust=${cacheBust}`;
|
|
4370
4042
|
return fullUrl;
|
|
4371
4043
|
}
|
|
4372
4044
|
resolveAvatarAssetUrl(subPath) {
|
|
@@ -4502,7 +4174,6 @@ var MockPostApi = class {
|
|
|
4502
4174
|
}
|
|
4503
4175
|
async toggleFollowAsync() {
|
|
4504
4176
|
const venusApi = this.venusApi;
|
|
4505
|
-
console.log("[Venus Mock] *Toggling follow status");
|
|
4506
4177
|
await createMockDelay(MOCK_DELAYS.short);
|
|
4507
4178
|
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
4508
4179
|
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
@@ -4761,878 +4432,433 @@ function initializeLifecycleApi(venusApi, host) {
|
|
|
4761
4432
|
venusApi.lifecycles = host.lifecycle;
|
|
4762
4433
|
}
|
|
4763
4434
|
|
|
4764
|
-
// src/
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4435
|
+
// src/rooms/VenusRoom.ts
|
|
4436
|
+
var VenusRoom = class {
|
|
4437
|
+
constructor(roomData) {
|
|
4438
|
+
__publicField(this, "id");
|
|
4439
|
+
__publicField(this, "name");
|
|
4440
|
+
__publicField(this, "players");
|
|
4441
|
+
__publicField(this, "maxPlayers");
|
|
4442
|
+
__publicField(this, "gameType");
|
|
4443
|
+
__publicField(this, "appId");
|
|
4444
|
+
__publicField(this, "type");
|
|
4445
|
+
__publicField(this, "createdBy");
|
|
4446
|
+
__publicField(this, "createdAt");
|
|
4447
|
+
__publicField(this, "updatedAt");
|
|
4448
|
+
__publicField(this, "isPrivate");
|
|
4449
|
+
__publicField(this, "status");
|
|
4450
|
+
__publicField(this, "customMetadata");
|
|
4451
|
+
__publicField(this, "admins");
|
|
4452
|
+
__publicField(this, "roomCode");
|
|
4453
|
+
__publicField(this, "description");
|
|
4454
|
+
__publicField(this, "data");
|
|
4455
|
+
__publicField(this, "version");
|
|
4456
|
+
this.id = roomData.id;
|
|
4457
|
+
this.name = roomData.name;
|
|
4458
|
+
this.players = Array.isArray(roomData.currentPlayers) ? [...roomData.currentPlayers] : [];
|
|
4459
|
+
this.maxPlayers = roomData.maxPlayers;
|
|
4460
|
+
this.gameType = roomData.gameType;
|
|
4461
|
+
this.appId = roomData.appId;
|
|
4462
|
+
this.type = roomData.type;
|
|
4463
|
+
this.createdBy = roomData.createdBy;
|
|
4464
|
+
this.createdAt = roomData.createdAt;
|
|
4465
|
+
this.updatedAt = roomData.updatedAt;
|
|
4466
|
+
this.isPrivate = roomData.isPrivate;
|
|
4467
|
+
this.status = roomData.status;
|
|
4468
|
+
this.customMetadata = roomData.customMetadata || {};
|
|
4469
|
+
this.admins = Array.isArray(roomData.admins) ? [...roomData.admins] : [];
|
|
4470
|
+
this.roomCode = roomData.roomCode;
|
|
4471
|
+
this.description = roomData.description;
|
|
4472
|
+
this.data = roomData.data || {};
|
|
4473
|
+
this.version = roomData.version;
|
|
4772
4474
|
}
|
|
4773
|
-
|
|
4475
|
+
};
|
|
4476
|
+
|
|
4477
|
+
// src/rooms/setupRoomNotifications.ts
|
|
4478
|
+
function invokeCallbacks(callbacks, event, context) {
|
|
4479
|
+
callbacks.forEach((callback) => {
|
|
4480
|
+
try {
|
|
4481
|
+
callback(event);
|
|
4482
|
+
} catch (error) {
|
|
4483
|
+
console.error(`[Venus SDK] Error in ${context} callback:`, error);
|
|
4484
|
+
throw error;
|
|
4485
|
+
}
|
|
4486
|
+
});
|
|
4487
|
+
}
|
|
4488
|
+
function setupRoomNotifications(transport, getSubscriptions) {
|
|
4489
|
+
return transport.onVenusMessage((message) => {
|
|
4490
|
+
const subscriptions = getSubscriptions();
|
|
4491
|
+
if (!subscriptions) {
|
|
4492
|
+
return;
|
|
4493
|
+
}
|
|
4494
|
+
if (message.type === "H5_ROOM_DATA_UPDATED") {
|
|
4495
|
+
const messageData = message.data;
|
|
4496
|
+
const { roomId, roomData } = messageData;
|
|
4497
|
+
if (!roomId) return;
|
|
4498
|
+
const callbacks = subscriptions.data[roomId] || [];
|
|
4499
|
+
const event = {
|
|
4500
|
+
type: "H5_ROOM_DATA_UPDATED",
|
|
4501
|
+
roomId,
|
|
4502
|
+
roomData,
|
|
4503
|
+
timestamp: messageData.timestamp
|
|
4504
|
+
};
|
|
4505
|
+
invokeCallbacks(callbacks, event, "room data");
|
|
4506
|
+
}
|
|
4507
|
+
if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
|
|
4508
|
+
const messageData = message.data;
|
|
4509
|
+
const { roomId } = messageData;
|
|
4510
|
+
if (!roomId) return;
|
|
4511
|
+
const callbacks = subscriptions.messages[roomId] || [];
|
|
4512
|
+
const event = {
|
|
4513
|
+
type: message.type,
|
|
4514
|
+
roomId,
|
|
4515
|
+
message: messageData.message,
|
|
4516
|
+
timestamp: messageData.timestamp
|
|
4517
|
+
};
|
|
4518
|
+
invokeCallbacks(callbacks, event, "room message");
|
|
4519
|
+
}
|
|
4520
|
+
if (message.type === "app:h5:proposedMoveValidationUpdated") {
|
|
4521
|
+
const messageData = message.data;
|
|
4522
|
+
const { roomId } = messageData;
|
|
4523
|
+
if (!roomId) return;
|
|
4524
|
+
const callbacks = subscriptions.gameEvents[roomId] || [];
|
|
4525
|
+
const event = {
|
|
4526
|
+
type: "app:h5:proposedMoveValidationUpdated",
|
|
4527
|
+
roomId,
|
|
4528
|
+
proposedMoveData: messageData.proposedMoveData,
|
|
4529
|
+
proposedMoveId: messageData.proposedMoveId,
|
|
4530
|
+
changeType: messageData.changeType,
|
|
4531
|
+
timestamp: messageData.timestamp
|
|
4532
|
+
};
|
|
4533
|
+
invokeCallbacks(callbacks, event, "game event");
|
|
4534
|
+
}
|
|
4535
|
+
});
|
|
4774
4536
|
}
|
|
4775
4537
|
|
|
4776
|
-
// src/
|
|
4777
|
-
var
|
|
4538
|
+
// src/rooms/RpcRoomsApi.ts
|
|
4539
|
+
var RpcRoomsApi = class {
|
|
4778
4540
|
constructor(rpcClient) {
|
|
4779
4541
|
__publicField(this, "rpcClient");
|
|
4780
|
-
__publicField(this, "
|
|
4542
|
+
__publicField(this, "subscriptions");
|
|
4781
4543
|
this.rpcClient = rpcClient;
|
|
4544
|
+
this.subscriptions = {
|
|
4545
|
+
data: {},
|
|
4546
|
+
messages: {},
|
|
4547
|
+
gameEvents: {}
|
|
4548
|
+
};
|
|
4782
4549
|
}
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
slotId,
|
|
4789
|
-
itemId
|
|
4790
|
-
}
|
|
4791
|
-
);
|
|
4792
|
-
}
|
|
4793
|
-
sumContributions(contributions) {
|
|
4794
|
-
return sumContributions(contributions);
|
|
4550
|
+
/**
|
|
4551
|
+
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
4552
|
+
*/
|
|
4553
|
+
getSubscriptions() {
|
|
4554
|
+
return this.subscriptions;
|
|
4795
4555
|
}
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4556
|
+
/**
|
|
4557
|
+
* Set up room notification routing from the transport
|
|
4558
|
+
*/
|
|
4559
|
+
setupNotifications(transport) {
|
|
4560
|
+
setupRoomNotifications(transport, () => this.getSubscriptions());
|
|
4801
4561
|
}
|
|
4802
|
-
async
|
|
4562
|
+
async createRoomAsync(options) {
|
|
4803
4563
|
const response = await this.rpcClient.call(
|
|
4804
|
-
"
|
|
4564
|
+
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
4805
4565
|
{
|
|
4806
|
-
|
|
4807
|
-
slotId
|
|
4566
|
+
options
|
|
4808
4567
|
}
|
|
4809
4568
|
);
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
containerId,
|
|
4817
|
-
slotId,
|
|
4818
|
-
candidateItemId
|
|
4819
|
-
}
|
|
4820
|
-
);
|
|
4821
|
-
}
|
|
4822
|
-
assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
4823
|
-
return this.rpcClient.call("H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */, {
|
|
4824
|
-
containerId,
|
|
4825
|
-
slotId,
|
|
4826
|
-
itemId
|
|
4827
|
-
});
|
|
4828
|
-
}
|
|
4829
|
-
removeItemFromSlotAsync(containerId, slotId) {
|
|
4830
|
-
return this.rpcClient.call("H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */, {
|
|
4831
|
-
containerId,
|
|
4832
|
-
slotId
|
|
4833
|
-
});
|
|
4834
|
-
}
|
|
4835
|
-
async getSlotContainersAsync() {
|
|
4836
|
-
const response = await this.rpcClient.call(
|
|
4837
|
-
"H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
|
|
4838
|
-
{}
|
|
4839
|
-
);
|
|
4840
|
-
return response.containers || [];
|
|
4569
|
+
if (response.success === false) {
|
|
4570
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to create room";
|
|
4571
|
+
throw new Error(errorMessage);
|
|
4572
|
+
}
|
|
4573
|
+
const room = new VenusRoom(response.roomData);
|
|
4574
|
+
return room;
|
|
4841
4575
|
}
|
|
4842
|
-
async
|
|
4576
|
+
async joinOrCreateRoomAsync(options) {
|
|
4843
4577
|
const response = await this.rpcClient.call(
|
|
4844
|
-
"
|
|
4578
|
+
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
4845
4579
|
{
|
|
4846
|
-
|
|
4580
|
+
options
|
|
4847
4581
|
}
|
|
4848
4582
|
);
|
|
4849
|
-
|
|
4583
|
+
if (response.success === false) {
|
|
4584
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to join or create room";
|
|
4585
|
+
throw new Error(errorMessage);
|
|
4586
|
+
}
|
|
4587
|
+
const room = new VenusRoom(response.value.roomData);
|
|
4588
|
+
return {
|
|
4589
|
+
action: response.value.action,
|
|
4590
|
+
room,
|
|
4591
|
+
playersJoined: response.value.playersJoined
|
|
4592
|
+
};
|
|
4850
4593
|
}
|
|
4851
|
-
async
|
|
4594
|
+
async joinRoomByCodeAsync(roomCode) {
|
|
4852
4595
|
const response = await this.rpcClient.call(
|
|
4853
|
-
"
|
|
4596
|
+
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
4854
4597
|
{
|
|
4855
|
-
|
|
4598
|
+
roomCode
|
|
4856
4599
|
}
|
|
4857
4600
|
);
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
}
|
|
4862
|
-
return response;
|
|
4863
|
-
}
|
|
4864
|
-
async getConfigAsync(roomId) {
|
|
4865
|
-
if (this._simulationConfig) {
|
|
4866
|
-
return this._simulationConfig;
|
|
4867
|
-
}
|
|
4868
|
-
const config = await this.rpcClient.call(
|
|
4869
|
-
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
4870
|
-
{}
|
|
4871
|
-
);
|
|
4872
|
-
console.log("[Venus SDK] getConfigAsync", config);
|
|
4873
|
-
if (config) {
|
|
4874
|
-
this._simulationConfig = config;
|
|
4875
|
-
return config;
|
|
4601
|
+
if (response?.success === false) {
|
|
4602
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to join room by code";
|
|
4603
|
+
throw new Error(errorMessage);
|
|
4876
4604
|
}
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
executeRecipeAsync(recipeId, inputs, options) {
|
|
4880
|
-
return this.rpcClient.call("H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */, {
|
|
4881
|
-
recipeId,
|
|
4882
|
-
inputs,
|
|
4883
|
-
roomId: options?.roomId,
|
|
4884
|
-
batchAmount: options?.batchAmount,
|
|
4885
|
-
allowPartialBatch: options?.allowPartialBatch,
|
|
4886
|
-
entity: options?.entity
|
|
4887
|
-
});
|
|
4888
|
-
}
|
|
4889
|
-
collectRecipeAsync(runId) {
|
|
4890
|
-
return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
|
|
4891
|
-
runId
|
|
4892
|
-
});
|
|
4893
|
-
}
|
|
4894
|
-
getActiveRunsAsync(options) {
|
|
4895
|
-
return this.rpcClient.call("H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */, {
|
|
4896
|
-
roomId: options?.roomId
|
|
4897
|
-
});
|
|
4605
|
+
const room = new VenusRoom(response.roomData);
|
|
4606
|
+
return room;
|
|
4898
4607
|
}
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4608
|
+
// Get user's rooms with optional filtering
|
|
4609
|
+
async getUserRoomsAsync(options = {}) {
|
|
4610
|
+
const response = await this.rpcClient.call(
|
|
4611
|
+
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
4902
4612
|
{
|
|
4903
|
-
|
|
4904
|
-
entity,
|
|
4905
|
-
inputs,
|
|
4906
|
-
roomId: options?.roomId ?? null,
|
|
4907
|
-
options
|
|
4613
|
+
includeArchived: options.includeArchived ?? false
|
|
4908
4614
|
}
|
|
4909
4615
|
);
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4616
|
+
if (response?.success === false) {
|
|
4617
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to get user rooms";
|
|
4618
|
+
throw new Error(errorMessage);
|
|
4619
|
+
}
|
|
4620
|
+
const venusRooms = [];
|
|
4621
|
+
for (const roomData of response.rooms) {
|
|
4622
|
+
if (!roomData.id) {
|
|
4623
|
+
console.warn("[Venus SDK] getUserRooms: Skipping room with missing ID:", roomData);
|
|
4624
|
+
continue;
|
|
4917
4625
|
}
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4626
|
+
try {
|
|
4627
|
+
const venusRoom = new VenusRoom(roomData);
|
|
4628
|
+
venusRooms.push(venusRoom);
|
|
4629
|
+
} catch (error) {
|
|
4630
|
+
console.warn(
|
|
4631
|
+
"[Venus SDK] getUserRooms: Failed to create VenusRoom object:",
|
|
4632
|
+
error,
|
|
4633
|
+
roomData
|
|
4634
|
+
);
|
|
4927
4635
|
}
|
|
4928
|
-
|
|
4636
|
+
}
|
|
4637
|
+
return venusRooms;
|
|
4929
4638
|
}
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
"
|
|
4639
|
+
async updateRoomDataAsync(room, updates, options = {}) {
|
|
4640
|
+
const response = await this.rpcClient.call(
|
|
4641
|
+
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
4933
4642
|
{
|
|
4934
|
-
|
|
4643
|
+
roomId: room.id,
|
|
4644
|
+
updates,
|
|
4645
|
+
merge: options.merge ?? true
|
|
4935
4646
|
}
|
|
4936
4647
|
);
|
|
4648
|
+
if (response?.success === false) {
|
|
4649
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to update room data";
|
|
4650
|
+
throw new Error(errorMessage);
|
|
4651
|
+
}
|
|
4937
4652
|
}
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
"
|
|
4653
|
+
async getRoomDataAsync(room) {
|
|
4654
|
+
const response = await this.rpcClient.call(
|
|
4655
|
+
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
4941
4656
|
{
|
|
4942
|
-
|
|
4943
|
-
context: options?.context,
|
|
4944
|
-
roomId: options?.roomId
|
|
4657
|
+
roomId: room.id
|
|
4945
4658
|
}
|
|
4946
4659
|
);
|
|
4660
|
+
if (response?.success === false) {
|
|
4661
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to get room data";
|
|
4662
|
+
throw new Error(errorMessage);
|
|
4663
|
+
}
|
|
4664
|
+
return response.data;
|
|
4947
4665
|
}
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
"
|
|
4666
|
+
async sendRoomMessageAsync(venusRoom, request) {
|
|
4667
|
+
const response = await this.rpcClient.call(
|
|
4668
|
+
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
4951
4669
|
{
|
|
4952
|
-
|
|
4670
|
+
roomId: venusRoom.id,
|
|
4671
|
+
message: request.message,
|
|
4672
|
+
metadata: request.metadata
|
|
4953
4673
|
}
|
|
4954
4674
|
);
|
|
4675
|
+
if (response?.success === false) {
|
|
4676
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to send message";
|
|
4677
|
+
throw new Error(errorMessage);
|
|
4678
|
+
}
|
|
4679
|
+
return response.messageId;
|
|
4955
4680
|
}
|
|
4956
|
-
async
|
|
4681
|
+
async leaveRoomAsync(room) {
|
|
4957
4682
|
const response = await this.rpcClient.call(
|
|
4958
|
-
"
|
|
4683
|
+
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
4959
4684
|
{
|
|
4960
|
-
|
|
4961
|
-
fieldPath,
|
|
4962
|
-
entity
|
|
4685
|
+
roomId: room.id
|
|
4963
4686
|
}
|
|
4964
4687
|
);
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
// src/simulation/MockSimulationApi.ts
|
|
4970
|
-
function generateAppIdentifier2() {
|
|
4971
|
-
if (typeof window === "undefined") return "unknown-app";
|
|
4972
|
-
const url = window.location.href;
|
|
4973
|
-
const match = url.match(/\/H5\/([^\/]+)/);
|
|
4974
|
-
return match ? match[1] : "unknown-app";
|
|
4975
|
-
}
|
|
4976
|
-
var MockSimulationApi = class {
|
|
4977
|
-
constructor(simulationConfig = null) {
|
|
4978
|
-
__publicField(this, "mockSimulationConfigs", /* @__PURE__ */ new Map());
|
|
4979
|
-
// appIdentifier -> config
|
|
4980
|
-
__publicField(this, "mockSimulationStates", /* @__PURE__ */ new Map());
|
|
4981
|
-
// appIdentifier -> config
|
|
4982
|
-
__publicField(this, "mockActiveTimers", /* @__PURE__ */ new Map());
|
|
4983
|
-
// appIdentifier -> timers[]
|
|
4984
|
-
__publicField(this, "appId");
|
|
4985
|
-
__publicField(this, "providedSimulationConfig");
|
|
4986
|
-
this.appId = generateAppIdentifier2();
|
|
4987
|
-
this.providedSimulationConfig = simulationConfig;
|
|
4988
|
-
}
|
|
4989
|
-
sumContributions(contributions) {
|
|
4990
|
-
return sumContributions(contributions);
|
|
4991
|
-
}
|
|
4992
|
-
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
4993
|
-
this.log("validateSlotAssignmentAsync called:", {
|
|
4994
|
-
containerId,
|
|
4995
|
-
slotId,
|
|
4996
|
-
itemId
|
|
4997
|
-
});
|
|
4998
|
-
return { valid: true, message: "Mock validation successful" };
|
|
4999
|
-
}
|
|
5000
|
-
async executeBatchOperationsAsync(operations, validateOnly) {
|
|
5001
|
-
this.log("executeBatchOperationsAsync called:", {
|
|
5002
|
-
operations,
|
|
5003
|
-
validateOnly
|
|
5004
|
-
});
|
|
5005
|
-
return {
|
|
5006
|
-
success: true,
|
|
5007
|
-
results: operations.map(() => ({ success: true }))
|
|
5008
|
-
};
|
|
5009
|
-
}
|
|
5010
|
-
async getAvailableItemsAsync(containerId, slotId) {
|
|
5011
|
-
console.log("[Venus Simulation Mock] getAvailableItemsAsync called:", {
|
|
5012
|
-
containerId,
|
|
5013
|
-
slotId
|
|
5014
|
-
});
|
|
5015
|
-
const appIdentifier = generateAppIdentifier2();
|
|
5016
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5017
|
-
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
5018
|
-
entities: {}
|
|
5019
|
-
};
|
|
5020
|
-
const availableItems = Object.entries(config.entities).slice(0, 3).map(([entityId, entity]) => ({
|
|
5021
|
-
entityId,
|
|
5022
|
-
quantity: 1,
|
|
5023
|
-
metadata: entity.metadata,
|
|
5024
|
-
powerPreview: 100
|
|
5025
|
-
// Mock power value
|
|
5026
|
-
}));
|
|
5027
|
-
return availableItems;
|
|
5028
|
-
}
|
|
5029
|
-
async calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
5030
|
-
this.log("calculatePowerPreviewAsync called:", {
|
|
5031
|
-
containerId,
|
|
5032
|
-
slotId,
|
|
5033
|
-
candidateItemId
|
|
5034
|
-
});
|
|
5035
|
-
return {
|
|
5036
|
-
currentPower: 1e3,
|
|
5037
|
-
previewPower: 1200,
|
|
5038
|
-
powerDelta: 200,
|
|
5039
|
-
breakdown: { base: 800, weapon: 200, armor: 200 }
|
|
5040
|
-
};
|
|
5041
|
-
}
|
|
5042
|
-
async getSlotContainersAsync() {
|
|
5043
|
-
this.log("getSlotContainersAsync called");
|
|
5044
|
-
const appIdentifier = this.appId;
|
|
5045
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5046
|
-
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
5047
|
-
entities: {}
|
|
5048
|
-
};
|
|
5049
|
-
const containers = Object.entries(config.entities).filter(([_2, entity]) => entity.metadata?.slots).map(([entityId, entity]) => ({
|
|
5050
|
-
entityId,
|
|
5051
|
-
slots: entity.metadata?.slots,
|
|
5052
|
-
isOwned: true
|
|
5053
|
-
// Mock: assume all containers are owned
|
|
5054
|
-
}));
|
|
5055
|
-
return containers;
|
|
5056
|
-
}
|
|
5057
|
-
async getSlotAssignmentsAsync(containerId) {
|
|
5058
|
-
this.log("getSlotAssignmentsAsync called for:", containerId);
|
|
5059
|
-
return [];
|
|
5060
|
-
}
|
|
5061
|
-
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
5062
|
-
this.log("resolveFieldValueAsync called:", {
|
|
5063
|
-
entityId,
|
|
5064
|
-
fieldPath,
|
|
5065
|
-
entity
|
|
5066
|
-
});
|
|
5067
|
-
const mockValues = {
|
|
5068
|
-
basePower: 850,
|
|
5069
|
-
weaponPower: 300,
|
|
5070
|
-
armorPower: 150,
|
|
5071
|
-
total_power: 1300,
|
|
5072
|
-
total_defense_power: 5e3
|
|
5073
|
-
};
|
|
5074
|
-
return mockValues[fieldPath] || 100;
|
|
5075
|
-
}
|
|
5076
|
-
async getEntityMetadataAsync(entityId) {
|
|
5077
|
-
this.log("getEntityMetadataAsync called for:", entityId);
|
|
5078
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5079
|
-
const appIdentifier = this.appId;
|
|
5080
|
-
const config = mockSimulationConfigs.get(
|
|
5081
|
-
appIdentifier
|
|
5082
|
-
) || {
|
|
5083
|
-
entities: {}};
|
|
5084
|
-
const entity = config.entities[entityId];
|
|
5085
|
-
return entity?.metadata || {};
|
|
5086
|
-
}
|
|
5087
|
-
async collectRecipeAsync(runId) {
|
|
5088
|
-
this.log("collectRecipeAsync called:", { runId });
|
|
5089
|
-
const mockRewards = {
|
|
5090
|
-
cash: Math.floor(Math.random() * 1e3) + 500,
|
|
5091
|
-
experience: Math.floor(Math.random() * 50) + 25
|
|
5092
|
-
};
|
|
5093
|
-
return {
|
|
5094
|
-
success: true,
|
|
5095
|
-
runId,
|
|
5096
|
-
rewards: mockRewards,
|
|
5097
|
-
message: "Rewards collected successfully"
|
|
5098
|
-
};
|
|
5099
|
-
}
|
|
5100
|
-
executeRecipeAsync(recipeId, inputs, options) {
|
|
5101
|
-
this.log("executeRecipeAsync called:", {
|
|
5102
|
-
recipeId,
|
|
5103
|
-
inputs,
|
|
5104
|
-
options
|
|
5105
|
-
});
|
|
5106
|
-
const appIdentifier = this.appId;
|
|
5107
|
-
return this.executeRecipe(appIdentifier, recipeId, inputs);
|
|
5108
|
-
}
|
|
5109
|
-
async executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
5110
|
-
this.log("executeScopedRecipeAsync called:", {
|
|
5111
|
-
recipeId,
|
|
5112
|
-
entity,
|
|
5113
|
-
inputs,
|
|
5114
|
-
roomId: options?.roomId,
|
|
5115
|
-
options
|
|
5116
|
-
});
|
|
5117
|
-
return {
|
|
5118
|
-
success: true,
|
|
5119
|
-
message: "Mock scoped recipe execution successful"
|
|
5120
|
-
};
|
|
5121
|
-
}
|
|
5122
|
-
async getActiveRunsAsync(options) {
|
|
5123
|
-
this.log("getActiveRunsAsync called:", options);
|
|
5124
|
-
const appIdentifier = this.appId;
|
|
5125
|
-
let state = this.mockSimulationStates.get(appIdentifier);
|
|
5126
|
-
if (!state) {
|
|
5127
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
5128
|
-
}
|
|
5129
|
-
return state.activeRuns || [];
|
|
5130
|
-
}
|
|
5131
|
-
async getAvailableRecipesAsync(options) {
|
|
5132
|
-
this.log("getAvailableRecipesAsync called:", options);
|
|
5133
|
-
const baseRecipes = [
|
|
5134
|
-
{ id: "collect_resources", scope: "player", clientViewable: true },
|
|
5135
|
-
{ id: "upgrade_equipment", scope: "player", clientViewable: true }
|
|
5136
|
-
];
|
|
5137
|
-
if (options?.roomId) {
|
|
5138
|
-
baseRecipes.push(
|
|
5139
|
-
{ id: "room_upgrade", scope: "room", clientViewable: true },
|
|
5140
|
-
{ id: "cooperative_project", scope: "room", clientViewable: true }
|
|
5141
|
-
);
|
|
5142
|
-
}
|
|
5143
|
-
if (options?.includeActorRecipes && options?.roomId) {
|
|
5144
|
-
baseRecipes.push(
|
|
5145
|
-
{ id: "trade_with_npc", scope: "actor", clientViewable: true },
|
|
5146
|
-
{ id: "attack_monster", scope: "actor", clientViewable: true }
|
|
5147
|
-
);
|
|
5148
|
-
}
|
|
5149
|
-
return { success: true, recipes: baseRecipes };
|
|
5150
|
-
}
|
|
5151
|
-
async getBatchRecipeRequirementsAsync(recipes) {
|
|
5152
|
-
this.log("getBatchRecipeRequirementsAsync called:", {
|
|
5153
|
-
count: recipes?.length
|
|
5154
|
-
});
|
|
5155
|
-
const results = (recipes || []).map((q) => ({
|
|
5156
|
-
recipeId: q.recipeId,
|
|
5157
|
-
entity: q.entity || null,
|
|
5158
|
-
amount: q.batchAmount || 1,
|
|
5159
|
-
inputs: { cash: "BE:0" },
|
|
5160
|
-
canAfford: true,
|
|
5161
|
-
disabled: false
|
|
5162
|
-
}));
|
|
5163
|
-
return { success: true, results };
|
|
5164
|
-
}
|
|
5165
|
-
async getRecipeRequirementsAsync(recipe) {
|
|
5166
|
-
this.log("getRecipeRequirementsAsync called:", recipe);
|
|
5167
|
-
return {
|
|
5168
|
-
recipeId: recipe.recipeId,
|
|
5169
|
-
entity: recipe.entity || null,
|
|
5170
|
-
amount: recipe.batchAmount,
|
|
5171
|
-
inputs: { cash: "BE:0" },
|
|
5172
|
-
canAfford: true,
|
|
5173
|
-
disabled: false
|
|
5174
|
-
};
|
|
5175
|
-
}
|
|
5176
|
-
async triggerRecipeChainAsync(recipeId, options) {
|
|
5177
|
-
this.log("triggerRecipeChainAsync called:", { recipeId, ...options });
|
|
5178
|
-
return {
|
|
5179
|
-
success: true,
|
|
5180
|
-
message: "Mock recipe chain triggered successfully"
|
|
5181
|
-
};
|
|
5182
|
-
}
|
|
5183
|
-
log(message, ...args) {
|
|
5184
|
-
console.log(`[Venus Sim Mock] ${message}`, args);
|
|
5185
|
-
}
|
|
5186
|
-
async executeRecipe(appIdentifier, recipeId, inputs) {
|
|
5187
|
-
this.log(`Executing recipe ${recipeId} for ${appIdentifier}`, inputs);
|
|
5188
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5189
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
5190
|
-
let config = mockSimulationConfigs.get(appIdentifier);
|
|
5191
|
-
let state = mockSimulationStates.get(appIdentifier);
|
|
5192
|
-
if (!config || !state) {
|
|
5193
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
5194
|
-
config = mockSimulationConfigs.get(appIdentifier);
|
|
5195
|
-
if (!config) {
|
|
5196
|
-
throw new Error("Failed to initialize simulation config");
|
|
5197
|
-
}
|
|
5198
|
-
}
|
|
5199
|
-
const recipe = config.recipes?.[recipeId];
|
|
5200
|
-
if (!recipe) {
|
|
5201
|
-
throw new Error(`Recipe ${recipeId} not found`);
|
|
5202
|
-
}
|
|
5203
|
-
if (state.disabledRecipes?.includes(recipeId)) {
|
|
5204
|
-
throw new Error(`Recipe ${recipeId} is disabled`);
|
|
5205
|
-
}
|
|
5206
|
-
if (recipe.inputs) {
|
|
5207
|
-
for (const [entityId, required] of Object.entries(recipe.inputs)) {
|
|
5208
|
-
const available = state.inventory[entityId] || 0;
|
|
5209
|
-
if (available < required) {
|
|
5210
|
-
throw new Error(
|
|
5211
|
-
`Insufficient ${entityId}: required ${required}, available ${available}`
|
|
5212
|
-
);
|
|
5213
|
-
}
|
|
5214
|
-
}
|
|
5215
|
-
}
|
|
5216
|
-
if (recipe.inputs) {
|
|
5217
|
-
for (const [entityId, input] of Object.entries(recipe.inputs)) {
|
|
5218
|
-
const inventoryValue = state.inventory[entityId] || 0;
|
|
5219
|
-
if (typeof input === "number" && typeof inventoryValue === "number") {
|
|
5220
|
-
state.inventory[entityId] = inventoryValue - input;
|
|
5221
|
-
}
|
|
5222
|
-
}
|
|
5223
|
-
}
|
|
5224
|
-
if (recipe.beginEffects) {
|
|
5225
|
-
this.applyEffects(state, recipe.beginEffects);
|
|
5226
|
-
}
|
|
5227
|
-
const runId = this.generateRunId();
|
|
5228
|
-
const now = Date.now();
|
|
5229
|
-
const expiresAt = now + (recipe.duration || 0);
|
|
5230
|
-
const run = {
|
|
5231
|
-
id: runId,
|
|
5232
|
-
recipeId,
|
|
5233
|
-
status: "running",
|
|
5234
|
-
startTime: now,
|
|
5235
|
-
expiresAt,
|
|
5236
|
-
inputs: recipe.inputs || {}
|
|
5237
|
-
};
|
|
5238
|
-
state.activeRuns.push(run);
|
|
5239
|
-
if (recipe.duration === 0) {
|
|
5240
|
-
this.completeRun(appIdentifier, runId);
|
|
5241
|
-
return { status: "completed", runId };
|
|
5242
|
-
} else {
|
|
5243
|
-
const mockActiveTimers = this.mockActiveTimers;
|
|
5244
|
-
const timer = setTimeout(() => {
|
|
5245
|
-
this.completeRun(appIdentifier, runId);
|
|
5246
|
-
}, recipe.duration);
|
|
5247
|
-
const timers = mockActiveTimers.get(appIdentifier) || [];
|
|
5248
|
-
timers.push(timer);
|
|
5249
|
-
mockActiveTimers.set(appIdentifier, timers);
|
|
5250
|
-
return {
|
|
5251
|
-
status: "running",
|
|
5252
|
-
runId,
|
|
5253
|
-
expiresAt: new Date(expiresAt).toISOString()
|
|
5254
|
-
};
|
|
4688
|
+
if (response?.success === false) {
|
|
4689
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to leave room";
|
|
4690
|
+
throw new Error(errorMessage);
|
|
5255
4691
|
}
|
|
5256
4692
|
}
|
|
5257
|
-
async
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
version: "1.0",
|
|
5265
|
-
entities: {},
|
|
5266
|
-
recipes: {}
|
|
5267
|
-
};
|
|
5268
|
-
mockSimulationConfigs.set(appIdentifier, config);
|
|
5269
|
-
const initialInventory = {};
|
|
5270
|
-
if (providedSimulationConfig && config.entities) {
|
|
5271
|
-
Object.keys(config.entities).forEach((entityId) => {
|
|
5272
|
-
initialInventory[entityId] = 0;
|
|
5273
|
-
});
|
|
5274
|
-
}
|
|
5275
|
-
const state = {
|
|
5276
|
-
inventory: initialInventory,
|
|
5277
|
-
activeRuns: [],
|
|
5278
|
-
disabledRecipes: new Array()
|
|
5279
|
-
};
|
|
5280
|
-
if (config.recipes) {
|
|
5281
|
-
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
5282
|
-
if (recipe.metadata?.startsDisabled) {
|
|
5283
|
-
state.disabledRecipes.push(recipeId);
|
|
5284
|
-
}
|
|
5285
|
-
});
|
|
5286
|
-
}
|
|
5287
|
-
mockSimulationStates.set(appIdentifier, state);
|
|
5288
|
-
mockActiveTimers.set(appIdentifier, []);
|
|
5289
|
-
console.log(
|
|
5290
|
-
`[Venus Simulation Mock] Initialized state for ${appIdentifier}:`,
|
|
5291
|
-
state
|
|
5292
|
-
);
|
|
5293
|
-
if (config.recipes) {
|
|
5294
|
-
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
5295
|
-
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
5296
|
-
if (isAutoRestart && recipe.outputs) {
|
|
5297
|
-
this.log(`Found auto-restart recipe: ${recipeId}`, {
|
|
5298
|
-
topLevelAutoRestart: recipe.autoRestart,
|
|
5299
|
-
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
5300
|
-
hasOutputs: !!recipe.outputs,
|
|
5301
|
-
duration: recipe.duration
|
|
5302
|
-
});
|
|
5303
|
-
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
5304
|
-
if (condition && condition.entity) {
|
|
5305
|
-
const currentAmount = initialInventory[condition.entity] || 0;
|
|
5306
|
-
if (currentAmount < condition.maxValue) {
|
|
5307
|
-
console.log(
|
|
5308
|
-
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization`,
|
|
5309
|
-
{
|
|
5310
|
-
currentAmount,
|
|
5311
|
-
maxValue: condition.maxValue,
|
|
5312
|
-
entity: condition.entity
|
|
5313
|
-
}
|
|
5314
|
-
);
|
|
5315
|
-
setTimeout(() => {
|
|
5316
|
-
this.executeRecipe(appIdentifier, recipeId, {});
|
|
5317
|
-
}, 1e3);
|
|
5318
|
-
}
|
|
5319
|
-
} else {
|
|
5320
|
-
console.log(
|
|
5321
|
-
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization (no condition)`
|
|
5322
|
-
);
|
|
5323
|
-
setTimeout(() => {
|
|
5324
|
-
this.executeRecipe(appIdentifier, recipeId, {});
|
|
5325
|
-
}, 1e3);
|
|
5326
|
-
}
|
|
5327
|
-
}
|
|
5328
|
-
});
|
|
5329
|
-
}
|
|
5330
|
-
return state;
|
|
5331
|
-
}
|
|
5332
|
-
generateRunId() {
|
|
5333
|
-
return "run_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
5334
|
-
}
|
|
5335
|
-
completeRun(appIdentifier, runId) {
|
|
5336
|
-
this.log(`Completing run ${runId} for ${appIdentifier}`);
|
|
5337
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5338
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
5339
|
-
const config = mockSimulationConfigs.get(appIdentifier);
|
|
5340
|
-
const state = mockSimulationStates.get(appIdentifier);
|
|
5341
|
-
if (!config || !state) return;
|
|
5342
|
-
const runIndex = state.activeRuns.findIndex((r2) => r2.id === runId);
|
|
5343
|
-
if (runIndex === -1) return;
|
|
5344
|
-
const run = state.activeRuns[runIndex];
|
|
5345
|
-
const recipe = config.recipes?.[run.recipeId];
|
|
5346
|
-
if (!recipe) return;
|
|
5347
|
-
const outputs = {};
|
|
5348
|
-
const rng = this.createSeededRandom(runId);
|
|
5349
|
-
if (recipe.outputs) {
|
|
5350
|
-
for (const [entityId, value] of Object.entries(recipe.outputs)) {
|
|
5351
|
-
if (typeof value === "number") {
|
|
5352
|
-
outputs[entityId] = value;
|
|
5353
|
-
} else if (typeof value === "object" && value != null && "min" in value && "max" in value && typeof value.min == "number" && typeof value.max === "number") {
|
|
5354
|
-
outputs[entityId] = Math.floor(rng() * (value.max - value.min + 1)) + value.min;
|
|
5355
|
-
}
|
|
5356
|
-
}
|
|
5357
|
-
}
|
|
5358
|
-
for (const [entityId, amount] of Object.entries(outputs)) {
|
|
5359
|
-
state.inventory[entityId] = (state.inventory[entityId] || 0) + amount;
|
|
5360
|
-
}
|
|
5361
|
-
if (recipe.endEffects) {
|
|
5362
|
-
this.applyEffects(state, recipe.endEffects);
|
|
5363
|
-
}
|
|
5364
|
-
run.status = "completed";
|
|
5365
|
-
run.outputs = outputs;
|
|
5366
|
-
state.activeRuns.splice(runIndex, 1);
|
|
5367
|
-
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
5368
|
-
if (isAutoRestart) {
|
|
5369
|
-
console.log(
|
|
5370
|
-
`[Venus Simulation Mock] Checking auto-restart for ${run.recipeId}`,
|
|
5371
|
-
{
|
|
5372
|
-
topLevelAutoRestart: recipe.autoRestart,
|
|
5373
|
-
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
5374
|
-
hasCondition: !!(recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition)
|
|
5375
|
-
}
|
|
5376
|
-
);
|
|
5377
|
-
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
5378
|
-
if (condition) {
|
|
5379
|
-
const currentAmount = state.inventory[condition.entity] || 0;
|
|
5380
|
-
if (currentAmount < condition.maxValue) {
|
|
5381
|
-
console.log(
|
|
5382
|
-
`[Venus Simulation Mock] Auto-restarting ${run.recipeId}`,
|
|
5383
|
-
{
|
|
5384
|
-
currentAmount,
|
|
5385
|
-
maxValue: condition.maxValue,
|
|
5386
|
-
entity: condition.entity
|
|
5387
|
-
}
|
|
5388
|
-
);
|
|
5389
|
-
setTimeout(() => {
|
|
5390
|
-
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
5391
|
-
}, 1e3);
|
|
5392
|
-
}
|
|
5393
|
-
} else {
|
|
5394
|
-
console.log(
|
|
5395
|
-
`[Venus Simulation Mock] Auto-restarting ${run.recipeId} (no condition)`
|
|
5396
|
-
);
|
|
5397
|
-
setTimeout(() => {
|
|
5398
|
-
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
5399
|
-
}, 1e3);
|
|
4693
|
+
async startRoomGameAsync(room, options = {}) {
|
|
4694
|
+
const response = await this.rpcClient.call(
|
|
4695
|
+
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
4696
|
+
{
|
|
4697
|
+
roomId: room.id,
|
|
4698
|
+
gameConfig: options.gameConfig ?? {},
|
|
4699
|
+
turnOrder: options.turnOrder ?? null
|
|
5400
4700
|
}
|
|
5401
|
-
}
|
|
5402
|
-
console.log(
|
|
5403
|
-
`[Venus Simulation Mock] Completed run ${runId}, outputs:`,
|
|
5404
|
-
outputs
|
|
5405
4701
|
);
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
for (let i = 0; i < seed.length; i++) {
|
|
5410
|
-
const char = seed.charCodeAt(i);
|
|
5411
|
-
hash = (hash << 5) - hash + char;
|
|
5412
|
-
hash = hash & hash;
|
|
5413
|
-
}
|
|
5414
|
-
return () => {
|
|
5415
|
-
hash = (hash * 9301 + 49297) % 233280;
|
|
5416
|
-
return hash / 233280;
|
|
5417
|
-
};
|
|
5418
|
-
}
|
|
5419
|
-
applyEffects(state, effects) {
|
|
5420
|
-
if (!effects || !Array.isArray(effects)) return;
|
|
5421
|
-
for (const effect of effects) {
|
|
5422
|
-
switch (effect.type) {
|
|
5423
|
-
case "set":
|
|
5424
|
-
state.inventory[effect.target] = effect.value;
|
|
5425
|
-
console.log(
|
|
5426
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} = ${effect.value}`
|
|
5427
|
-
);
|
|
5428
|
-
break;
|
|
5429
|
-
case "add":
|
|
5430
|
-
state.inventory[effect.target] = (state.inventory[effect.target] || 0) + effect.value;
|
|
5431
|
-
console.log(
|
|
5432
|
-
`[Venus Simulation Mock] Effect: Add ${effect.value} to ${effect.target} (new value: ${state.inventory[effect.target]})`
|
|
5433
|
-
);
|
|
5434
|
-
break;
|
|
5435
|
-
case "multiply":
|
|
5436
|
-
state.inventory[effect.target] = (state.inventory[effect.target] || 0) * effect.value;
|
|
5437
|
-
console.log(
|
|
5438
|
-
`[Venus Simulation Mock] Effect: Multiply ${effect.target} by ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5439
|
-
);
|
|
5440
|
-
break;
|
|
5441
|
-
case "min":
|
|
5442
|
-
state.inventory[effect.target] = Math.max(
|
|
5443
|
-
state.inventory[effect.target] || 0,
|
|
5444
|
-
effect.value
|
|
5445
|
-
);
|
|
5446
|
-
console.log(
|
|
5447
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} min ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5448
|
-
);
|
|
5449
|
-
break;
|
|
5450
|
-
case "max":
|
|
5451
|
-
state.inventory[effect.target] = Math.min(
|
|
5452
|
-
state.inventory[effect.target] || 0,
|
|
5453
|
-
effect.value
|
|
5454
|
-
);
|
|
5455
|
-
console.log(
|
|
5456
|
-
`[Venus Simulation Mock] Effect: Set ${effect.target} max ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5457
|
-
);
|
|
5458
|
-
break;
|
|
5459
|
-
case "enable_recipe":
|
|
5460
|
-
if (state.disabledRecipes?.includes(effect.target)) {
|
|
5461
|
-
state.disabledRecipes = state.disabledRecipes.filter(
|
|
5462
|
-
(r2) => r2 !== effect.target
|
|
5463
|
-
);
|
|
5464
|
-
console.log(
|
|
5465
|
-
`[Venus Simulation Mock] Effect: Enabled recipe ${effect.target}`
|
|
5466
|
-
);
|
|
5467
|
-
}
|
|
5468
|
-
break;
|
|
5469
|
-
case "disable_recipe":
|
|
5470
|
-
if (!state.disabledRecipes) state.disabledRecipes = [];
|
|
5471
|
-
if (!state.disabledRecipes.includes(effect.target)) {
|
|
5472
|
-
state.disabledRecipes.push(effect.target);
|
|
5473
|
-
console.log(
|
|
5474
|
-
`[Venus Simulation Mock] Effect: Disabled recipe ${effect.target}`
|
|
5475
|
-
);
|
|
5476
|
-
}
|
|
5477
|
-
break;
|
|
5478
|
-
case "trigger_recipe":
|
|
5479
|
-
console.log(
|
|
5480
|
-
`[Venus Simulation Mock] Effect: Trigger recipe ${effect.target} (not implemented)`
|
|
5481
|
-
);
|
|
5482
|
-
break;
|
|
5483
|
-
default:
|
|
5484
|
-
console.warn(
|
|
5485
|
-
`[Venus Simulation Mock] Unknown effect type: ${effect.type}`
|
|
5486
|
-
);
|
|
5487
|
-
}
|
|
4702
|
+
if (response?.success === false) {
|
|
4703
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to start game";
|
|
4704
|
+
throw new Error(errorMessage);
|
|
5488
4705
|
}
|
|
5489
4706
|
}
|
|
5490
|
-
async
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
}
|
|
5501
|
-
async getStateAsync(roomId) {
|
|
5502
|
-
this.log("getStateAsync called:", roomId);
|
|
5503
|
-
const appIdentifier = this.appId;
|
|
5504
|
-
const mockSimulationStates = this.mockSimulationStates;
|
|
5505
|
-
let state = mockSimulationStates.get(appIdentifier);
|
|
5506
|
-
if (!state) {
|
|
5507
|
-
state = await this.initializeSimulationState(appIdentifier);
|
|
5508
|
-
}
|
|
5509
|
-
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5510
|
-
return {
|
|
5511
|
-
...state,
|
|
5512
|
-
roomId,
|
|
5513
|
-
configuration: mockSimulationConfigs.get(appIdentifier)
|
|
5514
|
-
};
|
|
5515
|
-
}
|
|
5516
|
-
async assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
5517
|
-
this.log("assignItemToSlotAsync called:", {
|
|
5518
|
-
containerId,
|
|
5519
|
-
slotId,
|
|
5520
|
-
itemId
|
|
5521
|
-
});
|
|
5522
|
-
return { success: true, message: "Mock assignment successful" };
|
|
5523
|
-
}
|
|
5524
|
-
async removeItemFromSlotAsync(containerId, slotId) {
|
|
5525
|
-
this.log("removeItemFromSlotAsync called:", {
|
|
5526
|
-
containerId,
|
|
5527
|
-
slotId
|
|
5528
|
-
});
|
|
5529
|
-
return { success: true, message: "Mock removal successful" };
|
|
5530
|
-
}
|
|
5531
|
-
};
|
|
5532
|
-
|
|
5533
|
-
// src/simulation/index.ts
|
|
5534
|
-
function initializeSimulation(venusApi, host) {
|
|
5535
|
-
console.log("[Venus SDK] Initializing new Simulation Api");
|
|
5536
|
-
venusApi.simulation = {
|
|
5537
|
-
isEnabled: () => true
|
|
5538
|
-
};
|
|
5539
|
-
venusApi.simulation.getConfigAsync = () => {
|
|
5540
|
-
return host.simulation.getConfigAsync();
|
|
5541
|
-
};
|
|
5542
|
-
venusApi.simulation.getStateAsync = (options) => {
|
|
5543
|
-
return host.simulation.getStateAsync(options?.roomId);
|
|
5544
|
-
};
|
|
5545
|
-
venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
|
|
5546
|
-
return host.simulation.executeRecipeAsync(recipeId, inputs, options);
|
|
5547
|
-
};
|
|
5548
|
-
venusApi.simulation.getActiveRunsAsync = () => {
|
|
5549
|
-
return host.simulation.getActiveRunsAsync();
|
|
5550
|
-
};
|
|
5551
|
-
venusApi.simulation.collectRecipeAsync = (runId) => {
|
|
5552
|
-
return host.simulation.collectRecipeAsync(runId);
|
|
5553
|
-
};
|
|
5554
|
-
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, roomId, options) => {
|
|
5555
|
-
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, {
|
|
5556
|
-
roomId,
|
|
5557
|
-
...options
|
|
5558
|
-
});
|
|
5559
|
-
};
|
|
5560
|
-
venusApi.simulation.triggerRecipeChainAsync = (recipeId, context, roomId) => {
|
|
5561
|
-
return host.simulation.triggerRecipeChainAsync(recipeId, {
|
|
5562
|
-
context,
|
|
5563
|
-
roomId
|
|
5564
|
-
});
|
|
5565
|
-
};
|
|
5566
|
-
venusApi.simulation.getAvailableRecipesAsync = async (roomId, includeActorRecipes) => {
|
|
5567
|
-
const result = await host.simulation.getAvailableRecipesAsync({
|
|
5568
|
-
roomId,
|
|
5569
|
-
includeActorRecipes
|
|
5570
|
-
});
|
|
5571
|
-
return result.recipes;
|
|
5572
|
-
};
|
|
5573
|
-
venusApi.simulation.getRecipeRequirementsAsync = (recipeId, entity, amount) => {
|
|
5574
|
-
return host.simulation.getRecipeRequirementsAsync({
|
|
5575
|
-
recipeId,
|
|
5576
|
-
entity,
|
|
5577
|
-
batchAmount: amount
|
|
5578
|
-
});
|
|
5579
|
-
};
|
|
5580
|
-
venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
|
|
5581
|
-
return host.simulation.getBatchRecipeRequirementsAsync(recipes);
|
|
5582
|
-
};
|
|
5583
|
-
venusApi.simulation.resolveFieldValueAsync = (entityId, fieldPath, entity) => {
|
|
5584
|
-
return host.simulation.resolveFieldValueAsync(entityId, fieldPath, entity);
|
|
5585
|
-
};
|
|
5586
|
-
venusApi.simulation.getEntityMetadataAsync = (entityId) => {
|
|
5587
|
-
return host.simulation.getEntityMetadataAsync(entityId);
|
|
5588
|
-
};
|
|
5589
|
-
venusApi.simulation.getSlotAssignmentsAsync = (containerId) => {
|
|
5590
|
-
return host.simulation.getSlotAssignmentsAsync(containerId);
|
|
5591
|
-
};
|
|
5592
|
-
venusApi.simulation.getSlotContainersAsync = () => {
|
|
5593
|
-
return host.simulation.getSlotContainersAsync();
|
|
5594
|
-
};
|
|
5595
|
-
venusApi.simulation.assignItemToSlotAsync = (containerId, slotId, itemId) => {
|
|
5596
|
-
return host.simulation.assignItemToSlotAsync(containerId, slotId, itemId);
|
|
5597
|
-
};
|
|
5598
|
-
venusApi.simulation.removeItemFromSlotAsync = (containerId, slotId) => {
|
|
5599
|
-
return host.simulation.removeItemFromSlotAsync(containerId, slotId);
|
|
5600
|
-
};
|
|
5601
|
-
venusApi.simulation.getAvailableItemsAsync = (containerId, slotId) => {
|
|
5602
|
-
return host.simulation.getAvailableItemsAsync(containerId, slotId);
|
|
5603
|
-
};
|
|
5604
|
-
venusApi.simulation.calculatePowerPreviewAsync = (containerId, slotId, candidateItemId) => {
|
|
5605
|
-
return host.simulation.calculatePowerPreviewAsync(
|
|
5606
|
-
containerId,
|
|
5607
|
-
slotId,
|
|
5608
|
-
candidateItemId
|
|
5609
|
-
);
|
|
5610
|
-
};
|
|
5611
|
-
venusApi.simulation.executeBatchOperationsAsync = (operations, validateOnly) => {
|
|
5612
|
-
return host.simulation.executeBatchOperationsAsync(operations, validateOnly);
|
|
5613
|
-
};
|
|
5614
|
-
venusApi.simulation.validateSlotAssignmentAsync = (containerId, slotId, itemId) => {
|
|
5615
|
-
return host.simulation.validateSlotAssignmentAsync(
|
|
5616
|
-
containerId,
|
|
5617
|
-
slotId,
|
|
5618
|
-
itemId
|
|
4707
|
+
async proposeMoveAsync(room, proposalPayload) {
|
|
4708
|
+
const response = await this.rpcClient.call(
|
|
4709
|
+
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
4710
|
+
{
|
|
4711
|
+
roomId: room.id,
|
|
4712
|
+
gameSpecificState: proposalPayload.gameSpecificState,
|
|
4713
|
+
moveType: proposalPayload.moveType,
|
|
4714
|
+
clientContext: proposalPayload.clientContext,
|
|
4715
|
+
clientProposalId: proposalPayload.clientProposalId
|
|
4716
|
+
}
|
|
5619
4717
|
);
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
4718
|
+
if (response?.success === false) {
|
|
4719
|
+
const errorMessage = typeof response.error === "string" ? response.error : "Failed to propose move";
|
|
4720
|
+
throw new Error(errorMessage);
|
|
4721
|
+
}
|
|
4722
|
+
return response.data;
|
|
4723
|
+
}
|
|
4724
|
+
async validateMoveAsync(_room, moveId, verdict) {
|
|
4725
|
+
return {
|
|
4726
|
+
success: true,
|
|
4727
|
+
moveId,
|
|
4728
|
+
isValid: verdict.isValid,
|
|
4729
|
+
reason: verdict.reason
|
|
4730
|
+
};
|
|
4731
|
+
}
|
|
4732
|
+
async subscribeAsync(room, options = {}) {
|
|
4733
|
+
const roomId = room.id;
|
|
4734
|
+
const existingData = this.subscriptions.data[roomId];
|
|
4735
|
+
const existingMessages = this.subscriptions.messages[roomId];
|
|
4736
|
+
const existingGameEvents = this.subscriptions.gameEvents[roomId];
|
|
4737
|
+
const subscribeToData = Boolean(options.onData) && (existingData?.length ?? 0) === 0;
|
|
4738
|
+
const subscribeToMessages = Boolean(options.onMessages) && (existingMessages?.length ?? 0) === 0;
|
|
4739
|
+
const subscribeToProposedMoves = Boolean(options.onGameEvents) && (existingGameEvents?.length ?? 0) === 0;
|
|
4740
|
+
if (subscribeToData || subscribeToMessages || subscribeToProposedMoves) {
|
|
4741
|
+
try {
|
|
4742
|
+
await this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
4743
|
+
roomId,
|
|
4744
|
+
subscribeToData,
|
|
4745
|
+
subscribeToMessages,
|
|
4746
|
+
subscribeToProposedMoves
|
|
4747
|
+
});
|
|
4748
|
+
} catch (error) {
|
|
4749
|
+
console.error("[Venus SDK] Failed to set up room subscription:", error);
|
|
4750
|
+
throw error;
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4753
|
+
if (options.onData) {
|
|
4754
|
+
if (!this.subscriptions.data[roomId]) {
|
|
4755
|
+
this.subscriptions.data[roomId] = [];
|
|
4756
|
+
}
|
|
4757
|
+
this.subscriptions.data[roomId].push(options.onData);
|
|
4758
|
+
}
|
|
4759
|
+
if (options.onMessages) {
|
|
4760
|
+
if (!this.subscriptions.messages[roomId]) {
|
|
4761
|
+
this.subscriptions.messages[roomId] = [];
|
|
4762
|
+
}
|
|
4763
|
+
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
4764
|
+
}
|
|
4765
|
+
if (options.onGameEvents) {
|
|
4766
|
+
if (!this.subscriptions.gameEvents[roomId]) {
|
|
4767
|
+
this.subscriptions.gameEvents[roomId] = [];
|
|
4768
|
+
}
|
|
4769
|
+
this.subscriptions.gameEvents[roomId].push(options.onGameEvents);
|
|
4770
|
+
}
|
|
4771
|
+
let disposed = false;
|
|
4772
|
+
return () => {
|
|
4773
|
+
if (disposed) return;
|
|
4774
|
+
disposed = true;
|
|
4775
|
+
if (options.onData) {
|
|
4776
|
+
const callbacks = this.subscriptions.data[roomId];
|
|
4777
|
+
if (callbacks) {
|
|
4778
|
+
const index = callbacks.indexOf(options.onData);
|
|
4779
|
+
if (index > -1) {
|
|
4780
|
+
callbacks.splice(index, 1);
|
|
4781
|
+
}
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
if (options.onMessages) {
|
|
4785
|
+
const callbacks = this.subscriptions.messages[roomId];
|
|
4786
|
+
if (callbacks) {
|
|
4787
|
+
const index = callbacks.indexOf(options.onMessages);
|
|
4788
|
+
if (index > -1) {
|
|
4789
|
+
callbacks.splice(index, 1);
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
if (options.onGameEvents) {
|
|
4794
|
+
const callbacks = this.subscriptions.gameEvents[roomId];
|
|
4795
|
+
if (callbacks) {
|
|
4796
|
+
const index = callbacks.indexOf(options.onGameEvents);
|
|
4797
|
+
if (index > -1) {
|
|
4798
|
+
callbacks.splice(index, 1);
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4802
|
+
const hasAnySubscriptions = (this.subscriptions.data[roomId]?.length ?? 0) > 0 || (this.subscriptions.messages[roomId]?.length ?? 0) > 0 || (this.subscriptions.gameEvents[roomId]?.length ?? 0) > 0;
|
|
4803
|
+
if (!hasAnySubscriptions) {
|
|
4804
|
+
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
4805
|
+
roomId
|
|
4806
|
+
}).catch((error) => {
|
|
4807
|
+
console.error("[Venus SDK] Failed to clean up room subscription:", error);
|
|
4808
|
+
});
|
|
4809
|
+
}
|
|
4810
|
+
};
|
|
4811
|
+
}
|
|
4812
|
+
};
|
|
5625
4813
|
|
|
5626
|
-
// src/
|
|
5627
|
-
|
|
4814
|
+
// src/rooms/index.ts
|
|
4815
|
+
function bindMethod(target, targetKey, source, sourceKey) {
|
|
4816
|
+
const key = sourceKey ?? targetKey;
|
|
4817
|
+
const fn = source?.[key];
|
|
4818
|
+
if (typeof fn === "function") {
|
|
4819
|
+
target[targetKey] = fn.bind(source);
|
|
4820
|
+
return true;
|
|
4821
|
+
}
|
|
4822
|
+
return false;
|
|
4823
|
+
}
|
|
4824
|
+
function initializeRoomsApi(venusApi, host) {
|
|
4825
|
+
const roomsApi = host?.rooms;
|
|
4826
|
+
if (!roomsApi) {
|
|
4827
|
+
console.warn(
|
|
4828
|
+
"[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
|
|
4829
|
+
);
|
|
4830
|
+
return;
|
|
4831
|
+
}
|
|
4832
|
+
const venus = venusApi;
|
|
4833
|
+
const existingNamespace = venus.rooms || {};
|
|
4834
|
+
const roomsNamespace = Object.assign({}, existingNamespace);
|
|
4835
|
+
const namespaceBindings = [
|
|
4836
|
+
["createRoomAsync"],
|
|
4837
|
+
["joinOrCreateRoomAsync"],
|
|
4838
|
+
["joinRoomByCodeAsync"],
|
|
4839
|
+
["getUserRoomsAsync"],
|
|
4840
|
+
["subscribeAsync"],
|
|
4841
|
+
["updateRoomDataAsync"],
|
|
4842
|
+
["getRoomDataAsync"],
|
|
4843
|
+
["sendRoomMessageAsync"],
|
|
4844
|
+
["leaveRoomAsync"],
|
|
4845
|
+
["startRoomGameAsync"],
|
|
4846
|
+
["proposeMoveAsync"],
|
|
4847
|
+
["validateMoveAsync"]
|
|
4848
|
+
];
|
|
4849
|
+
namespaceBindings.forEach(([targetKey, sourceKey]) => {
|
|
4850
|
+
bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
|
|
4851
|
+
});
|
|
4852
|
+
venus.rooms = roomsNamespace;
|
|
4853
|
+
}
|
|
5628
4854
|
|
|
5629
4855
|
// src/logging/MockLoggingApi.ts
|
|
5630
4856
|
var MockLoggingApi = class {
|
|
5631
4857
|
logDebug(message, ...args) {
|
|
5632
|
-
console.log(`[Venus Mock] ${message}`, args);
|
|
4858
|
+
console.log(`[Venus Mock] ${message}`, ...args);
|
|
5633
4859
|
}
|
|
5634
4860
|
logError(message, ...args) {
|
|
5635
|
-
console.error(`[Venus Mock] ${message}`, args);
|
|
4861
|
+
console.error(`[Venus Mock] ${message}`, ...args);
|
|
5636
4862
|
}
|
|
5637
4863
|
};
|
|
5638
4864
|
|
|
@@ -5847,44 +5073,116 @@ var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when ru
|
|
|
5847
5073
|
function createUnavailableRoomsApi() {
|
|
5848
5074
|
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
5849
5075
|
return {
|
|
5850
|
-
async
|
|
5076
|
+
async createRoomAsync() {
|
|
5851
5077
|
throw roomsUnavailableError();
|
|
5852
5078
|
},
|
|
5853
|
-
async
|
|
5079
|
+
async joinOrCreateRoomAsync() {
|
|
5854
5080
|
throw roomsUnavailableError();
|
|
5855
5081
|
},
|
|
5856
|
-
async
|
|
5082
|
+
async joinRoomByCodeAsync() {
|
|
5857
5083
|
throw roomsUnavailableError();
|
|
5858
5084
|
},
|
|
5859
|
-
async
|
|
5085
|
+
async getUserRoomsAsync() {
|
|
5860
5086
|
throw roomsUnavailableError();
|
|
5861
5087
|
},
|
|
5862
|
-
|
|
5088
|
+
async subscribeAsync() {
|
|
5863
5089
|
throw roomsUnavailableError();
|
|
5864
5090
|
},
|
|
5865
|
-
async
|
|
5091
|
+
async updateRoomDataAsync() {
|
|
5866
5092
|
throw roomsUnavailableError();
|
|
5867
5093
|
},
|
|
5868
|
-
async
|
|
5094
|
+
async getRoomDataAsync() {
|
|
5869
5095
|
throw roomsUnavailableError();
|
|
5870
5096
|
},
|
|
5871
|
-
async
|
|
5097
|
+
async sendRoomMessageAsync() {
|
|
5872
5098
|
throw roomsUnavailableError();
|
|
5873
5099
|
},
|
|
5874
|
-
async
|
|
5100
|
+
async leaveRoomAsync() {
|
|
5875
5101
|
throw roomsUnavailableError();
|
|
5876
5102
|
},
|
|
5877
|
-
async
|
|
5103
|
+
async startRoomGameAsync() {
|
|
5878
5104
|
throw roomsUnavailableError();
|
|
5879
5105
|
},
|
|
5880
|
-
async
|
|
5106
|
+
async proposeMoveAsync() {
|
|
5881
5107
|
throw roomsUnavailableError();
|
|
5882
5108
|
},
|
|
5883
|
-
async
|
|
5109
|
+
async validateMoveAsync() {
|
|
5884
5110
|
throw roomsUnavailableError();
|
|
5885
5111
|
}
|
|
5886
5112
|
};
|
|
5887
5113
|
}
|
|
5114
|
+
var SIMULATION_UNAVAILABLE_MESSAGE = "[Venus SDK] Simulation API is only available when running inside the Venus host environment.";
|
|
5115
|
+
function createUnavailableSimulationApi() {
|
|
5116
|
+
const simulationUnavailableError = () => new Error(SIMULATION_UNAVAILABLE_MESSAGE);
|
|
5117
|
+
return {
|
|
5118
|
+
isEnabled() {
|
|
5119
|
+
return false;
|
|
5120
|
+
},
|
|
5121
|
+
async getStateAsync() {
|
|
5122
|
+
throw simulationUnavailableError();
|
|
5123
|
+
},
|
|
5124
|
+
async getConfigAsync() {
|
|
5125
|
+
throw simulationUnavailableError();
|
|
5126
|
+
},
|
|
5127
|
+
async executeRecipeAsync() {
|
|
5128
|
+
throw simulationUnavailableError();
|
|
5129
|
+
},
|
|
5130
|
+
async getActiveRunsAsync() {
|
|
5131
|
+
throw simulationUnavailableError();
|
|
5132
|
+
},
|
|
5133
|
+
async collectRecipeAsync() {
|
|
5134
|
+
throw simulationUnavailableError();
|
|
5135
|
+
},
|
|
5136
|
+
async executeScopedRecipeAsync() {
|
|
5137
|
+
throw simulationUnavailableError();
|
|
5138
|
+
},
|
|
5139
|
+
async triggerRecipeChainAsync() {
|
|
5140
|
+
throw simulationUnavailableError();
|
|
5141
|
+
},
|
|
5142
|
+
async getAvailableRecipesAsync() {
|
|
5143
|
+
throw simulationUnavailableError();
|
|
5144
|
+
},
|
|
5145
|
+
async getRecipeRequirementsAsync() {
|
|
5146
|
+
throw simulationUnavailableError();
|
|
5147
|
+
},
|
|
5148
|
+
async getBatchRecipeRequirementsAsync() {
|
|
5149
|
+
throw simulationUnavailableError();
|
|
5150
|
+
},
|
|
5151
|
+
async resolveFieldValueAsync() {
|
|
5152
|
+
throw simulationUnavailableError();
|
|
5153
|
+
},
|
|
5154
|
+
async getEntityMetadataAsync() {
|
|
5155
|
+
throw simulationUnavailableError();
|
|
5156
|
+
},
|
|
5157
|
+
async getSlotContainersAsync() {
|
|
5158
|
+
throw simulationUnavailableError();
|
|
5159
|
+
},
|
|
5160
|
+
async getSlotAssignmentsAsync() {
|
|
5161
|
+
throw simulationUnavailableError();
|
|
5162
|
+
},
|
|
5163
|
+
async assignItemToSlotAsync() {
|
|
5164
|
+
throw simulationUnavailableError();
|
|
5165
|
+
},
|
|
5166
|
+
async removeItemFromSlotAsync() {
|
|
5167
|
+
throw simulationUnavailableError();
|
|
5168
|
+
},
|
|
5169
|
+
async getAvailableItemsAsync() {
|
|
5170
|
+
throw simulationUnavailableError();
|
|
5171
|
+
},
|
|
5172
|
+
async calculatePowerPreviewAsync() {
|
|
5173
|
+
throw simulationUnavailableError();
|
|
5174
|
+
},
|
|
5175
|
+
async validateSlotAssignmentAsync() {
|
|
5176
|
+
throw simulationUnavailableError();
|
|
5177
|
+
},
|
|
5178
|
+
async executeBatchOperationsAsync() {
|
|
5179
|
+
throw simulationUnavailableError();
|
|
5180
|
+
},
|
|
5181
|
+
async subscribeAsync() {
|
|
5182
|
+
throw simulationUnavailableError();
|
|
5183
|
+
}
|
|
5184
|
+
};
|
|
5185
|
+
}
|
|
5888
5186
|
var MockHost = class {
|
|
5889
5187
|
constructor(venusApi) {
|
|
5890
5188
|
__publicField(this, "ads");
|
|
@@ -5939,7 +5237,7 @@ var MockHost = class {
|
|
|
5939
5237
|
this.haptics = new MockHapticsApi(venusApi);
|
|
5940
5238
|
this.features = new MockFeaturesApi();
|
|
5941
5239
|
this.lifecycle = this._mockLifecyclesApi;
|
|
5942
|
-
this.simulation =
|
|
5240
|
+
this.simulation = createUnavailableSimulationApi();
|
|
5943
5241
|
this.rooms = createUnavailableRoomsApi();
|
|
5944
5242
|
this.logging = new MockLoggingApi();
|
|
5945
5243
|
this.iap = new MockIapApi();
|
|
@@ -6431,6 +5729,11 @@ var MockHost = class {
|
|
|
6431
5729
|
}
|
|
6432
5730
|
};
|
|
6433
5731
|
|
|
5732
|
+
// src/utils/idGenerator.ts
|
|
5733
|
+
function generateId() {
|
|
5734
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
5735
|
+
}
|
|
5736
|
+
|
|
6434
5737
|
// src/rpc/RpcClient.ts
|
|
6435
5738
|
var RpcClient = class {
|
|
6436
5739
|
constructor() {
|
|
@@ -6473,7 +5776,7 @@ var RpcClient = class {
|
|
|
6473
5776
|
}
|
|
6474
5777
|
async call(method, args, timeout = 5e3) {
|
|
6475
5778
|
return new Promise((resolve, reject) => {
|
|
6476
|
-
const id =
|
|
5779
|
+
const id = generateId();
|
|
6477
5780
|
this.addPendingCall(id, resolve, reject);
|
|
6478
5781
|
const request = {
|
|
6479
5782
|
type: "rpc-request",
|
|
@@ -6510,9 +5813,6 @@ var RpcClient = class {
|
|
|
6510
5813
|
getPendingCall(id) {
|
|
6511
5814
|
return this.pendingCalls.get(id);
|
|
6512
5815
|
}
|
|
6513
|
-
generateId() {
|
|
6514
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
6515
|
-
}
|
|
6516
5816
|
handleRpcResponse(response) {
|
|
6517
5817
|
const pending = this.getPendingCall(response.id);
|
|
6518
5818
|
if (!pending) {
|
|
@@ -6575,6 +5875,16 @@ var VenusTransport = class {
|
|
|
6575
5875
|
this.isProcessingMessage = false;
|
|
6576
5876
|
return;
|
|
6577
5877
|
}
|
|
5878
|
+
if (message.type === "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */) {
|
|
5879
|
+
const notification = {
|
|
5880
|
+
type: "rpc-notification",
|
|
5881
|
+
id: message.type,
|
|
5882
|
+
payload: message.data
|
|
5883
|
+
};
|
|
5884
|
+
this.handleNotification(notification);
|
|
5885
|
+
this.isProcessingMessage = false;
|
|
5886
|
+
return;
|
|
5887
|
+
}
|
|
6578
5888
|
const requestId = messageData.requestId;
|
|
6579
5889
|
if (!requestId) {
|
|
6580
5890
|
this.logWarn("No requestId. Ignoring message...");
|
|
@@ -6741,294 +6051,361 @@ var VenusTransport = class {
|
|
|
6741
6051
|
}
|
|
6742
6052
|
};
|
|
6743
6053
|
|
|
6744
|
-
// src/
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
// src/rooms/RpcRoomsApi.ts
|
|
6748
|
-
init_VenusRoom();
|
|
6749
|
-
var RpcRoomsApi = class {
|
|
6054
|
+
// src/simulation/RpcSimulationApi.ts
|
|
6055
|
+
var RpcSimulationApi = class {
|
|
6750
6056
|
constructor(rpcClient) {
|
|
6751
6057
|
__publicField(this, "rpcClient");
|
|
6752
|
-
__publicField(this, "
|
|
6753
|
-
__publicField(this, "
|
|
6058
|
+
__publicField(this, "_simulationConfig", null);
|
|
6059
|
+
__publicField(this, "subscriptionCallbacks", /* @__PURE__ */ new Map());
|
|
6754
6060
|
this.rpcClient = rpcClient;
|
|
6755
|
-
this.
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
allEvents: {}
|
|
6760
|
-
};
|
|
6061
|
+
this.rpcClient.onNotification(
|
|
6062
|
+
"H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */,
|
|
6063
|
+
this.handleSimulationUpdate.bind(this)
|
|
6064
|
+
);
|
|
6761
6065
|
}
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
*/
|
|
6765
|
-
getSubscriptions() {
|
|
6766
|
-
return this.subscriptions;
|
|
6066
|
+
isEnabled() {
|
|
6067
|
+
return true;
|
|
6767
6068
|
}
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6069
|
+
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
6070
|
+
return this.rpcClient.call(
|
|
6071
|
+
"H5_SIMULATION_VALIDATE_ASSIGNMENT" /* H5_SIMULATION_VALIDATE_ASSIGNMENT */,
|
|
6072
|
+
{
|
|
6073
|
+
containerId,
|
|
6074
|
+
slotId,
|
|
6075
|
+
itemId
|
|
6076
|
+
}
|
|
6776
6077
|
);
|
|
6777
6078
|
}
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
this.
|
|
6784
|
-
|
|
6785
|
-
|
|
6079
|
+
async subscribeAsync(options) {
|
|
6080
|
+
this.ensureValidSubscribeOptions(options);
|
|
6081
|
+
const subscriptionId = generateId();
|
|
6082
|
+
this.subscriptionCallbacks.set(subscriptionId, options.onUpdate);
|
|
6083
|
+
try {
|
|
6084
|
+
await this.rpcClient.call("H5_SIMULATION_SUBSCRIBE" /* H5_SIMULATION_SUBSCRIBE */, {
|
|
6085
|
+
subscriptionId,
|
|
6086
|
+
entities: options.entities,
|
|
6087
|
+
tags: options.tags,
|
|
6088
|
+
activeRuns: options.activeRuns,
|
|
6089
|
+
roomId: options.roomId
|
|
6090
|
+
});
|
|
6091
|
+
} catch (error) {
|
|
6092
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
6093
|
+
throw error;
|
|
6786
6094
|
}
|
|
6095
|
+
let unsubscribed = false;
|
|
6096
|
+
return () => {
|
|
6097
|
+
if (unsubscribed) {
|
|
6098
|
+
return;
|
|
6099
|
+
}
|
|
6100
|
+
unsubscribed = true;
|
|
6101
|
+
this.subscriptionCallbacks.delete(subscriptionId);
|
|
6102
|
+
void this.rpcClient.call("H5_SIMULATION_UNSUBSCRIBE" /* H5_SIMULATION_UNSUBSCRIBE */, {
|
|
6103
|
+
subscriptionId
|
|
6104
|
+
}).catch((error) => {
|
|
6105
|
+
console.error(
|
|
6106
|
+
"[Venus SDK] Failed to unsubscribe simulation listener",
|
|
6107
|
+
error
|
|
6108
|
+
);
|
|
6109
|
+
});
|
|
6110
|
+
};
|
|
6111
|
+
}
|
|
6112
|
+
executeBatchOperationsAsync(operations, validateOnly) {
|
|
6113
|
+
return this.rpcClient.call(
|
|
6114
|
+
"H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */,
|
|
6115
|
+
{
|
|
6116
|
+
operations,
|
|
6117
|
+
validateOnly
|
|
6118
|
+
}
|
|
6119
|
+
);
|
|
6787
6120
|
}
|
|
6788
|
-
async
|
|
6121
|
+
async getAvailableItemsAsync(containerId, slotId) {
|
|
6789
6122
|
const response = await this.rpcClient.call(
|
|
6790
|
-
"
|
|
6123
|
+
"H5_SIMULATION_GET_AVAILABLE_ITEMS" /* H5_SIMULATION_GET_AVAILABLE_ITEMS */,
|
|
6791
6124
|
{
|
|
6792
|
-
|
|
6125
|
+
containerId,
|
|
6126
|
+
slotId
|
|
6127
|
+
}
|
|
6128
|
+
);
|
|
6129
|
+
return response.availableItems || [];
|
|
6130
|
+
}
|
|
6131
|
+
calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
6132
|
+
return this.rpcClient.call(
|
|
6133
|
+
"H5_SIMULATION_CALCULATE_POWER_PREVIEW" /* H5_SIMULATION_CALCULATE_POWER_PREVIEW */,
|
|
6134
|
+
{
|
|
6135
|
+
containerId,
|
|
6136
|
+
slotId,
|
|
6137
|
+
candidateItemId
|
|
6138
|
+
}
|
|
6139
|
+
);
|
|
6140
|
+
}
|
|
6141
|
+
assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
6142
|
+
return this.rpcClient.call(
|
|
6143
|
+
"H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */,
|
|
6144
|
+
{
|
|
6145
|
+
containerId,
|
|
6146
|
+
slotId,
|
|
6147
|
+
itemId
|
|
6148
|
+
}
|
|
6149
|
+
);
|
|
6150
|
+
}
|
|
6151
|
+
removeItemFromSlotAsync(containerId, slotId) {
|
|
6152
|
+
return this.rpcClient.call(
|
|
6153
|
+
"H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */,
|
|
6154
|
+
{
|
|
6155
|
+
containerId,
|
|
6156
|
+
slotId
|
|
6793
6157
|
}
|
|
6794
6158
|
);
|
|
6795
|
-
if (response.success === false) {
|
|
6796
|
-
throw new Error(response.error || "Failed to create room");
|
|
6797
|
-
}
|
|
6798
|
-
const roomData = response.roomData || response;
|
|
6799
|
-
const room = new VenusRoom(roomData);
|
|
6800
|
-
return room;
|
|
6801
6159
|
}
|
|
6802
|
-
async
|
|
6160
|
+
async getSlotContainersAsync() {
|
|
6803
6161
|
const response = await this.rpcClient.call(
|
|
6804
|
-
"
|
|
6162
|
+
"H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
|
|
6163
|
+
{}
|
|
6164
|
+
);
|
|
6165
|
+
return response.containers || [];
|
|
6166
|
+
}
|
|
6167
|
+
async getSlotAssignmentsAsync(containerId) {
|
|
6168
|
+
const response = await this.rpcClient.call(
|
|
6169
|
+
"H5_SIMULATION_GET_ASSIGNMENTS" /* H5_SIMULATION_GET_ASSIGNMENTS */,
|
|
6805
6170
|
{
|
|
6806
|
-
|
|
6171
|
+
containerId
|
|
6172
|
+
}
|
|
6173
|
+
);
|
|
6174
|
+
return Array.isArray(response) ? response : response.assignments || [];
|
|
6175
|
+
}
|
|
6176
|
+
async getStateAsync(roomId) {
|
|
6177
|
+
const response = await this.rpcClient.call(
|
|
6178
|
+
"H5_SIMULATION_GET_STATE" /* H5_SIMULATION_GET_STATE */,
|
|
6179
|
+
{
|
|
6180
|
+
roomId
|
|
6181
|
+
}
|
|
6182
|
+
);
|
|
6183
|
+
if (response.configuration) {
|
|
6184
|
+
this._simulationConfig = response.configuration;
|
|
6185
|
+
}
|
|
6186
|
+
return response;
|
|
6187
|
+
}
|
|
6188
|
+
async getConfigAsync(roomId) {
|
|
6189
|
+
if (this._simulationConfig) {
|
|
6190
|
+
return this._simulationConfig;
|
|
6191
|
+
}
|
|
6192
|
+
const config = await this.rpcClient.call(
|
|
6193
|
+
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
6194
|
+
{
|
|
6195
|
+
roomId
|
|
6196
|
+
}
|
|
6197
|
+
);
|
|
6198
|
+
if (config) {
|
|
6199
|
+
this._simulationConfig = config;
|
|
6200
|
+
return config;
|
|
6201
|
+
}
|
|
6202
|
+
throw new Error("No simulation configuration available");
|
|
6203
|
+
}
|
|
6204
|
+
executeRecipeAsync(recipeId, inputs, options) {
|
|
6205
|
+
return this.rpcClient.call(
|
|
6206
|
+
"H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */,
|
|
6207
|
+
{
|
|
6208
|
+
recipeId,
|
|
6209
|
+
inputs,
|
|
6210
|
+
roomId: options?.roomId,
|
|
6211
|
+
batchAmount: options?.batchAmount,
|
|
6212
|
+
allowPartialBatch: options?.allowPartialBatch,
|
|
6213
|
+
entity: options?.entity
|
|
6807
6214
|
}
|
|
6808
6215
|
);
|
|
6809
|
-
if (response.success === false) {
|
|
6810
|
-
throw new Error(response.error || "Failed to join or create room");
|
|
6811
|
-
}
|
|
6812
|
-
const data = response.value || response;
|
|
6813
|
-
const room = new VenusRoom(data.roomData);
|
|
6814
|
-
return {
|
|
6815
|
-
action: data.action,
|
|
6816
|
-
room,
|
|
6817
|
-
playersJoined: data.playersJoined
|
|
6818
|
-
};
|
|
6819
6216
|
}
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6217
|
+
collectRecipeAsync(runId) {
|
|
6218
|
+
return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
|
|
6219
|
+
runId
|
|
6220
|
+
});
|
|
6221
|
+
}
|
|
6222
|
+
getActiveRunsAsync(options) {
|
|
6223
|
+
return this.rpcClient.call(
|
|
6224
|
+
"H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
|
|
6823
6225
|
{
|
|
6824
|
-
|
|
6226
|
+
roomId: options?.roomId
|
|
6825
6227
|
}
|
|
6826
6228
|
);
|
|
6827
|
-
if (response?.success === false) {
|
|
6828
|
-
throw new Error(response.error || "Failed to join room by code");
|
|
6829
|
-
}
|
|
6830
|
-
const roomData = response.roomData || response;
|
|
6831
|
-
const room = new VenusRoom(roomData);
|
|
6832
|
-
return room;
|
|
6833
6229
|
}
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
6230
|
+
executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
6231
|
+
return this.rpcClient.call(
|
|
6232
|
+
"H5_SIMULATION_EXECUTE_SCOPED_RECIPE" /* H5_SIMULATION_EXECUTE_SCOPED_RECIPE */,
|
|
6838
6233
|
{
|
|
6839
|
-
|
|
6234
|
+
recipeId,
|
|
6235
|
+
entity,
|
|
6236
|
+
inputs,
|
|
6237
|
+
roomId: options?.roomId ?? null,
|
|
6238
|
+
options
|
|
6840
6239
|
}
|
|
6841
6240
|
);
|
|
6842
|
-
if (response?.success === false) {
|
|
6843
|
-
throw new Error(response.error || "Failed to get user rooms");
|
|
6844
|
-
}
|
|
6845
|
-
const rawRooms = response.rooms || [];
|
|
6846
|
-
const venusRooms = [];
|
|
6847
|
-
for (const roomData of rawRooms) {
|
|
6848
|
-
if (!roomData.id) {
|
|
6849
|
-
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
6850
|
-
continue;
|
|
6851
|
-
}
|
|
6852
|
-
try {
|
|
6853
|
-
const venusRoom = new VenusRoom(roomData);
|
|
6854
|
-
venusRooms.push(venusRoom);
|
|
6855
|
-
} catch (error) {
|
|
6856
|
-
console.warn(
|
|
6857
|
-
"getUserRooms: Failed to create VenusRoom object:",
|
|
6858
|
-
error,
|
|
6859
|
-
roomData
|
|
6860
|
-
);
|
|
6861
|
-
}
|
|
6862
|
-
}
|
|
6863
|
-
return venusRooms;
|
|
6864
6241
|
}
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
"
|
|
6242
|
+
getAvailableRecipesAsync(options) {
|
|
6243
|
+
return this.rpcClient.call(
|
|
6244
|
+
"H5_SIMULATION_GET_AVAILABLE_RECIPES" /* H5_SIMULATION_GET_AVAILABLE_RECIPES */,
|
|
6868
6245
|
{
|
|
6869
|
-
roomId:
|
|
6870
|
-
|
|
6871
|
-
merge
|
|
6246
|
+
roomId: options?.roomId || null,
|
|
6247
|
+
includeActorRecipes: options?.includeActorRecipes || false
|
|
6872
6248
|
}
|
|
6873
6249
|
);
|
|
6874
|
-
if (response?.success === false) {
|
|
6875
|
-
throw new Error(response.error || "Failed to update room data");
|
|
6876
|
-
}
|
|
6877
|
-
return response.data;
|
|
6878
6250
|
}
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
"
|
|
6251
|
+
getRecipeRequirementsAsync(recipe) {
|
|
6252
|
+
return this.rpcClient.call(
|
|
6253
|
+
"H5_SIMULATION_GET_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_RECIPE_REQUIREMENTS */,
|
|
6882
6254
|
{
|
|
6883
|
-
|
|
6255
|
+
recipeId: recipe.recipeId,
|
|
6256
|
+
entity: recipe.entity,
|
|
6257
|
+
batchAmount: recipe.batchAmount
|
|
6884
6258
|
}
|
|
6885
6259
|
);
|
|
6886
|
-
if (response?.success === false) {
|
|
6887
|
-
throw new Error(response.error || "Failed to get room data");
|
|
6888
|
-
}
|
|
6889
|
-
return response.data;
|
|
6890
6260
|
}
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
"
|
|
6261
|
+
getBatchRecipeRequirementsAsync(recipes) {
|
|
6262
|
+
return this.rpcClient.call(
|
|
6263
|
+
"H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS */,
|
|
6894
6264
|
{
|
|
6895
|
-
|
|
6896
|
-
message: messageData
|
|
6265
|
+
recipes
|
|
6897
6266
|
}
|
|
6898
6267
|
);
|
|
6899
|
-
if (response?.success === false) {
|
|
6900
|
-
throw new Error(response.error || "Failed to send message");
|
|
6901
|
-
}
|
|
6902
|
-
return response.messageId;
|
|
6903
6268
|
}
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
"
|
|
6269
|
+
triggerRecipeChainAsync(recipeId, options) {
|
|
6270
|
+
return this.rpcClient.call(
|
|
6271
|
+
"H5_SIMULATION_TRIGGER_RECIPE_CHAIN" /* H5_SIMULATION_TRIGGER_RECIPE_CHAIN */,
|
|
6907
6272
|
{
|
|
6908
|
-
|
|
6273
|
+
triggerRecipeId: recipeId,
|
|
6274
|
+
context: options?.context,
|
|
6275
|
+
roomId: options?.roomId
|
|
6909
6276
|
}
|
|
6910
6277
|
);
|
|
6911
|
-
if (response?.success === false) {
|
|
6912
|
-
throw new Error(response.error || "Failed to leave room");
|
|
6913
|
-
}
|
|
6914
|
-
return response;
|
|
6915
6278
|
}
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
"
|
|
6279
|
+
getEntityMetadataAsync(entityId) {
|
|
6280
|
+
return this.rpcClient.call(
|
|
6281
|
+
"H5_SIMULATION_GET_ENTITY_METADATA" /* H5_SIMULATION_GET_ENTITY_METADATA */,
|
|
6919
6282
|
{
|
|
6920
|
-
|
|
6921
|
-
gameConfig,
|
|
6922
|
-
turnOrder
|
|
6283
|
+
entityId
|
|
6923
6284
|
}
|
|
6924
6285
|
);
|
|
6925
|
-
if (response?.success === false) {
|
|
6926
|
-
throw new Error(response.error || "Failed to start game");
|
|
6927
|
-
}
|
|
6928
|
-
return response.data;
|
|
6929
6286
|
}
|
|
6930
|
-
async
|
|
6287
|
+
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
6931
6288
|
const response = await this.rpcClient.call(
|
|
6932
|
-
"
|
|
6289
|
+
"H5_SIMULATION_RESOLVE_VALUE" /* H5_SIMULATION_RESOLVE_VALUE */,
|
|
6933
6290
|
{
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
clientContext: proposalPayload.clientContext,
|
|
6938
|
-
clientProposalId: proposalPayload.clientProposalId
|
|
6291
|
+
entityId,
|
|
6292
|
+
fieldPath,
|
|
6293
|
+
entity
|
|
6939
6294
|
}
|
|
6940
6295
|
);
|
|
6941
|
-
|
|
6942
|
-
throw new Error(response.error || "Failed to propose move");
|
|
6943
|
-
}
|
|
6944
|
-
return response.data;
|
|
6945
|
-
}
|
|
6946
|
-
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
6947
|
-
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
6948
|
-
return { success: true, moveId, isValid, reason };
|
|
6296
|
+
return response.value;
|
|
6949
6297
|
}
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6298
|
+
handleSimulationUpdate(notification) {
|
|
6299
|
+
if (!notification || !notification.subscriptionId) {
|
|
6300
|
+
console.warn("[Venus SDK] Received malformed simulation update");
|
|
6301
|
+
return;
|
|
6954
6302
|
}
|
|
6955
|
-
this.
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
if (!this.subscriptions.data[roomId]) {
|
|
6963
|
-
this.subscriptions.data[roomId] = [];
|
|
6964
|
-
}
|
|
6965
|
-
this.subscriptions.data[roomId].push(options.onData);
|
|
6966
|
-
subscriptionIds.push({
|
|
6967
|
-
type: "data",
|
|
6968
|
-
id: dataSubId,
|
|
6969
|
-
callback: options.onData
|
|
6970
|
-
});
|
|
6303
|
+
const callback = this.subscriptionCallbacks.get(notification.subscriptionId);
|
|
6304
|
+
if (!callback) {
|
|
6305
|
+
console.warn(
|
|
6306
|
+
"[Venus SDK] Received update for unknown subscription:",
|
|
6307
|
+
notification.subscriptionId
|
|
6308
|
+
);
|
|
6309
|
+
return;
|
|
6971
6310
|
}
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
}
|
|
6977
|
-
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
6978
|
-
subscriptionIds.push({
|
|
6979
|
-
type: "messages",
|
|
6980
|
-
id: msgSubId,
|
|
6981
|
-
callback: options.onMessages
|
|
6982
|
-
});
|
|
6311
|
+
try {
|
|
6312
|
+
callback(notification.updates);
|
|
6313
|
+
} catch (error) {
|
|
6314
|
+
console.error("[Venus SDK] Error in simulation subscription callback", error);
|
|
6983
6315
|
}
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
if (!this.subscriptions.gameEvents[roomId]) {
|
|
6989
|
-
this.subscriptions.gameEvents[roomId] = [];
|
|
6990
|
-
}
|
|
6991
|
-
this.subscriptions.gameEvents[roomId].push(handler);
|
|
6992
|
-
subscriptionIds.push({
|
|
6993
|
-
type: "gameEvents",
|
|
6994
|
-
id: gameSubId,
|
|
6995
|
-
callback: handler
|
|
6996
|
-
});
|
|
6997
|
-
}
|
|
6316
|
+
}
|
|
6317
|
+
ensureValidSubscribeOptions(options) {
|
|
6318
|
+
if (typeof options !== "object" || options === null) {
|
|
6319
|
+
throw new Error("Simulation subscribe requires an options object");
|
|
6998
6320
|
}
|
|
6999
|
-
const
|
|
7000
|
-
if (
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
});
|
|
6321
|
+
const opts = options;
|
|
6322
|
+
if (typeof opts.onUpdate !== "function") {
|
|
6323
|
+
throw new Error("Simulation subscribe requires an onUpdate callback");
|
|
6324
|
+
}
|
|
6325
|
+
const hasFilter = Array.isArray(opts.entities) && opts.entities.length > 0 || Array.isArray(opts.tags) && opts.tags.length > 0 || Boolean(opts.activeRuns);
|
|
6326
|
+
if (!hasFilter) {
|
|
6327
|
+
throw new Error(
|
|
6328
|
+
"Simulation subscribe requires at least one filter (entities, tags, activeRuns)"
|
|
6329
|
+
);
|
|
7009
6330
|
}
|
|
7010
|
-
let called = false;
|
|
7011
|
-
return () => {
|
|
7012
|
-
if (called) return;
|
|
7013
|
-
called = true;
|
|
7014
|
-
subscriptionIds.forEach((sub) => {
|
|
7015
|
-
const bucket = this.subscriptions[sub.type];
|
|
7016
|
-
const callbacks = bucket && bucket[roomId] || [];
|
|
7017
|
-
const index = callbacks.indexOf(sub.callback);
|
|
7018
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
7019
|
-
});
|
|
7020
|
-
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
7021
|
-
if (hasNoCallbacks) {
|
|
7022
|
-
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
7023
|
-
roomId
|
|
7024
|
-
}).catch((error) => {
|
|
7025
|
-
console.error("Failed to clean up room subscription:", error);
|
|
7026
|
-
});
|
|
7027
|
-
}
|
|
7028
|
-
};
|
|
7029
6331
|
}
|
|
7030
6332
|
};
|
|
7031
6333
|
|
|
6334
|
+
// src/simulation/index.ts
|
|
6335
|
+
function initializeSimulation(venusApi, host) {
|
|
6336
|
+
venusApi.simulation = {
|
|
6337
|
+
isEnabled: () => true
|
|
6338
|
+
};
|
|
6339
|
+
venusApi.simulation.getConfigAsync = () => {
|
|
6340
|
+
return host.simulation.getConfigAsync();
|
|
6341
|
+
};
|
|
6342
|
+
venusApi.simulation.getStateAsync = (roomId) => {
|
|
6343
|
+
return host.simulation.getStateAsync(roomId);
|
|
6344
|
+
};
|
|
6345
|
+
venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
|
|
6346
|
+
return host.simulation.executeRecipeAsync(recipeId, inputs, options);
|
|
6347
|
+
};
|
|
6348
|
+
venusApi.simulation.getActiveRunsAsync = () => {
|
|
6349
|
+
return host.simulation.getActiveRunsAsync();
|
|
6350
|
+
};
|
|
6351
|
+
venusApi.simulation.collectRecipeAsync = (runId) => {
|
|
6352
|
+
return host.simulation.collectRecipeAsync(runId);
|
|
6353
|
+
};
|
|
6354
|
+
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, options) => {
|
|
6355
|
+
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, options);
|
|
6356
|
+
};
|
|
6357
|
+
venusApi.simulation.triggerRecipeChainAsync = (recipeId, options) => {
|
|
6358
|
+
return host.simulation.triggerRecipeChainAsync(recipeId, options);
|
|
6359
|
+
};
|
|
6360
|
+
venusApi.simulation.getAvailableRecipesAsync = async (options) => {
|
|
6361
|
+
return host.simulation.getAvailableRecipesAsync(options);
|
|
6362
|
+
};
|
|
6363
|
+
venusApi.simulation.getRecipeRequirementsAsync = (recipe) => {
|
|
6364
|
+
return host.simulation.getRecipeRequirementsAsync(recipe);
|
|
6365
|
+
};
|
|
6366
|
+
venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
|
|
6367
|
+
return host.simulation.getBatchRecipeRequirementsAsync(recipes);
|
|
6368
|
+
};
|
|
6369
|
+
venusApi.simulation.resolveFieldValueAsync = (entityId, fieldPath, entity) => {
|
|
6370
|
+
return host.simulation.resolveFieldValueAsync(entityId, fieldPath, entity);
|
|
6371
|
+
};
|
|
6372
|
+
venusApi.simulation.getEntityMetadataAsync = (entityId) => {
|
|
6373
|
+
return host.simulation.getEntityMetadataAsync(entityId);
|
|
6374
|
+
};
|
|
6375
|
+
venusApi.simulation.getSlotAssignmentsAsync = (containerId) => {
|
|
6376
|
+
return host.simulation.getSlotAssignmentsAsync(containerId);
|
|
6377
|
+
};
|
|
6378
|
+
venusApi.simulation.getSlotContainersAsync = () => {
|
|
6379
|
+
return host.simulation.getSlotContainersAsync();
|
|
6380
|
+
};
|
|
6381
|
+
venusApi.simulation.assignItemToSlotAsync = (containerId, slotId, itemId) => {
|
|
6382
|
+
return host.simulation.assignItemToSlotAsync(containerId, slotId, itemId);
|
|
6383
|
+
};
|
|
6384
|
+
venusApi.simulation.removeItemFromSlotAsync = (containerId, slotId) => {
|
|
6385
|
+
return host.simulation.removeItemFromSlotAsync(containerId, slotId);
|
|
6386
|
+
};
|
|
6387
|
+
venusApi.simulation.getAvailableItemsAsync = (containerId, slotId) => {
|
|
6388
|
+
return host.simulation.getAvailableItemsAsync(containerId, slotId);
|
|
6389
|
+
};
|
|
6390
|
+
venusApi.simulation.calculatePowerPreviewAsync = (containerId, slotId, candidateItemId) => {
|
|
6391
|
+
return host.simulation.calculatePowerPreviewAsync(
|
|
6392
|
+
containerId,
|
|
6393
|
+
slotId,
|
|
6394
|
+
candidateItemId
|
|
6395
|
+
);
|
|
6396
|
+
};
|
|
6397
|
+
venusApi.simulation.executeBatchOperationsAsync = (operations, validateOnly) => {
|
|
6398
|
+
return host.simulation.executeBatchOperationsAsync(operations, validateOnly);
|
|
6399
|
+
};
|
|
6400
|
+
venusApi.simulation.validateSlotAssignmentAsync = (containerId, slotId, itemId) => {
|
|
6401
|
+
return host.simulation.validateSlotAssignmentAsync(
|
|
6402
|
+
containerId,
|
|
6403
|
+
slotId,
|
|
6404
|
+
itemId
|
|
6405
|
+
);
|
|
6406
|
+
};
|
|
6407
|
+
}
|
|
6408
|
+
|
|
7032
6409
|
// src/social/RpcSocialApi.ts
|
|
7033
6410
|
var RpcSocialApi = class {
|
|
7034
6411
|
constructor(rpcClient) {
|
|
@@ -7133,7 +6510,7 @@ var RemoteHost = class {
|
|
|
7133
6510
|
this.popups = new RpcPopupsApi(rpcClient);
|
|
7134
6511
|
this.profile = new HostProfileApi();
|
|
7135
6512
|
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
7136
|
-
this.time = new HostTimeApi(rpcClient);
|
|
6513
|
+
this.time = new HostTimeApi(rpcClient, venusApi);
|
|
7137
6514
|
this.post = new RpcPostApi(rpcClient);
|
|
7138
6515
|
this.ai = new RpcAiApi(rpcClient);
|
|
7139
6516
|
this.haptics = new RpcHapticsApi(rpcClient);
|
|
@@ -7149,7 +6526,6 @@ var RemoteHost = class {
|
|
|
7149
6526
|
venusApi.isMock = () => false;
|
|
7150
6527
|
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
7151
6528
|
initializeRoomsApi(this.venusApi, this);
|
|
7152
|
-
console.log("[Venus SDK] Remote host created");
|
|
7153
6529
|
}
|
|
7154
6530
|
get isInitialized() {
|
|
7155
6531
|
return this._isInitialized;
|
|
@@ -7208,19 +6584,14 @@ var RemoteHost = class {
|
|
|
7208
6584
|
// src/Host.ts
|
|
7209
6585
|
function createHost(venusApi, isMock) {
|
|
7210
6586
|
if (isMock) {
|
|
7211
|
-
console.log("[Venus SDK] Creating Local Host");
|
|
7212
6587
|
return new MockHost(venusApi);
|
|
7213
6588
|
} else {
|
|
7214
|
-
console.log("[Venus SDK] Creating Remote Host");
|
|
7215
6589
|
return new RemoteHost(venusApi);
|
|
7216
6590
|
}
|
|
7217
6591
|
}
|
|
7218
6592
|
|
|
7219
|
-
// src/venus-api/index.js
|
|
7220
|
-
init_rooms();
|
|
7221
|
-
|
|
7222
6593
|
// src/version.ts
|
|
7223
|
-
var SDK_VERSION = "3.0.
|
|
6594
|
+
var SDK_VERSION = "3.0.5";
|
|
7224
6595
|
|
|
7225
6596
|
// src/social/index.ts
|
|
7226
6597
|
function initializeSocial(venusApi, host) {
|
|
@@ -7281,67 +6652,6 @@ var VenusAPI2 = class {
|
|
|
7281
6652
|
height: 60
|
|
7282
6653
|
}
|
|
7283
6654
|
},
|
|
7284
|
-
// Complete theme structure (matching createH5Theme output)
|
|
7285
|
-
theme: {
|
|
7286
|
-
background: {
|
|
7287
|
-
default: "#131419",
|
|
7288
|
-
muted: "#1b1d25",
|
|
7289
|
-
dark: "#0d0e11"
|
|
7290
|
-
},
|
|
7291
|
-
text: {
|
|
7292
|
-
primary: "#ffffff",
|
|
7293
|
-
muted: "#808080",
|
|
7294
|
-
inverted: "#000000"
|
|
7295
|
-
},
|
|
7296
|
-
theme: {
|
|
7297
|
-
primary: "#f6c833",
|
|
7298
|
-
secondary: "#6366f1",
|
|
7299
|
-
background: "#131419",
|
|
7300
|
-
border: "#262626",
|
|
7301
|
-
card: "#1b1d25",
|
|
7302
|
-
"card-glass": "rgba(27, 29, 37, 0.8)"
|
|
7303
|
-
},
|
|
7304
|
-
typography: {
|
|
7305
|
-
fontFamily: {
|
|
7306
|
-
base: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7307
|
-
heading: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7308
|
-
mono: "monospace"
|
|
7309
|
-
},
|
|
7310
|
-
fontSize: {
|
|
7311
|
-
"2xs": "10px",
|
|
7312
|
-
xs: "12px",
|
|
7313
|
-
sm: "14px",
|
|
7314
|
-
md: "16px",
|
|
7315
|
-
lg: "18px",
|
|
7316
|
-
xl: "20px",
|
|
7317
|
-
"2xl": "24px",
|
|
7318
|
-
"3xl": "30px",
|
|
7319
|
-
"4xl": "36px",
|
|
7320
|
-
"5xl": "48px",
|
|
7321
|
-
"6xl": "60px"
|
|
7322
|
-
},
|
|
7323
|
-
fontWeight: {
|
|
7324
|
-
thin: "100",
|
|
7325
|
-
extralight: "200",
|
|
7326
|
-
light: "300",
|
|
7327
|
-
regular: "400",
|
|
7328
|
-
medium: "500",
|
|
7329
|
-
semibold: "600",
|
|
7330
|
-
bold: "700",
|
|
7331
|
-
extrabold: "800",
|
|
7332
|
-
black: "900",
|
|
7333
|
-
extrablack: "950"
|
|
7334
|
-
},
|
|
7335
|
-
lineHeight: {
|
|
7336
|
-
none: "1",
|
|
7337
|
-
tight: "1.25",
|
|
7338
|
-
snug: "1.375",
|
|
7339
|
-
normal: "1.5",
|
|
7340
|
-
relaxed: "1.625",
|
|
7341
|
-
loose: "2"
|
|
7342
|
-
}
|
|
7343
|
-
}
|
|
7344
|
-
},
|
|
7345
6655
|
// Static locale data at top level
|
|
7346
6656
|
locale: "en-US",
|
|
7347
6657
|
languageCode: "en",
|
|
@@ -7472,58 +6782,26 @@ var VenusAPI2 = class {
|
|
|
7472
6782
|
deviceType: "phone",
|
|
7473
6783
|
hapticsEnabled: false,
|
|
7474
6784
|
haptics: { supported: false, enabled: false }
|
|
6785
|
+
}
|
|
6786
|
+
});
|
|
6787
|
+
const originalConfig = this.config;
|
|
6788
|
+
this.config = new Proxy(originalConfig, {
|
|
6789
|
+
get(target, prop) {
|
|
6790
|
+
if (prop === "locale" || prop === "languageCode") {
|
|
6791
|
+
console.error(
|
|
6792
|
+
`[Venus SDK] config.${prop} is deprecated and will be removed in v4.0.0. Use VenusAPI.${prop === "locale" ? "getLocale()" : "getLanguageCode()"}() instead.`
|
|
6793
|
+
);
|
|
6794
|
+
}
|
|
6795
|
+
return target[prop];
|
|
7475
6796
|
},
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
secondary: "#6366f1",
|
|
7482
|
-
background: "#131419",
|
|
7483
|
-
border: "#262626",
|
|
7484
|
-
card: "#1b1d25",
|
|
7485
|
-
"card-glass": "rgba(27, 29, 37, 0.8)"
|
|
7486
|
-
},
|
|
7487
|
-
typography: {
|
|
7488
|
-
fontFamily: {
|
|
7489
|
-
base: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7490
|
-
heading: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7491
|
-
mono: "monospace"
|
|
7492
|
-
},
|
|
7493
|
-
fontSize: {
|
|
7494
|
-
"2xs": "10px",
|
|
7495
|
-
xs: "12px",
|
|
7496
|
-
sm: "14px",
|
|
7497
|
-
md: "16px",
|
|
7498
|
-
lg: "18px",
|
|
7499
|
-
xl: "20px",
|
|
7500
|
-
"2xl": "24px",
|
|
7501
|
-
"3xl": "30px",
|
|
7502
|
-
"4xl": "36px",
|
|
7503
|
-
"5xl": "48px",
|
|
7504
|
-
"6xl": "60px"
|
|
7505
|
-
},
|
|
7506
|
-
fontWeight: {
|
|
7507
|
-
thin: "100",
|
|
7508
|
-
extralight: "200",
|
|
7509
|
-
light: "300",
|
|
7510
|
-
regular: "400",
|
|
7511
|
-
medium: "500",
|
|
7512
|
-
semibold: "600",
|
|
7513
|
-
bold: "700",
|
|
7514
|
-
extrabold: "800",
|
|
7515
|
-
black: "900",
|
|
7516
|
-
extrablack: "950"
|
|
7517
|
-
},
|
|
7518
|
-
lineHeight: {
|
|
7519
|
-
none: "1",
|
|
7520
|
-
tight: "1.25",
|
|
7521
|
-
snug: "1.375",
|
|
7522
|
-
normal: "1.5",
|
|
7523
|
-
relaxed: "1.625",
|
|
7524
|
-
loose: "2"
|
|
7525
|
-
}
|
|
6797
|
+
set(target, prop, value) {
|
|
6798
|
+
if (prop === "locale" || prop === "languageCode") {
|
|
6799
|
+
console.error(
|
|
6800
|
+
`[Venus SDK] config.${prop} is deprecated and will be removed in v4.0.0. Use VenusAPI.${prop === "locale" ? "getLocale()" : "getLanguageCode()"}() instead.`
|
|
6801
|
+
);
|
|
7526
6802
|
}
|
|
6803
|
+
target[prop] = value;
|
|
6804
|
+
return true;
|
|
7527
6805
|
}
|
|
7528
6806
|
});
|
|
7529
6807
|
const isInsideHostedEnv = this._bootstrap.isInsideHostedEnvironment;
|
|
@@ -7532,7 +6810,6 @@ var VenusAPI2 = class {
|
|
|
7532
6810
|
initializeStorage(this, host);
|
|
7533
6811
|
initializeRoomsApi(this, host);
|
|
7534
6812
|
initializeAds(this, host);
|
|
7535
|
-
initializeTheme(this);
|
|
7536
6813
|
initializePopups(this, host);
|
|
7537
6814
|
initializeAnalytics(this, host);
|
|
7538
6815
|
initializeIap(this, host);
|
|
@@ -7556,6 +6833,28 @@ var VenusAPI2 = class {
|
|
|
7556
6833
|
initializeSimulation(this, host);
|
|
7557
6834
|
initializeSocial(this, host);
|
|
7558
6835
|
initializeAssetLoader(this, createProxiedMethod);
|
|
6836
|
+
this.getLocale = () => {
|
|
6837
|
+
if (typeof window !== "undefined" && window.venus) {
|
|
6838
|
+
const venus = window.venus;
|
|
6839
|
+
if (venus.config && venus.config.locale) {
|
|
6840
|
+
return venus.config.locale;
|
|
6841
|
+
}
|
|
6842
|
+
if (venus._config && venus._config.locale) {
|
|
6843
|
+
return venus._config.locale;
|
|
6844
|
+
}
|
|
6845
|
+
if (venus.config?.environment?.browserInfo?.language) {
|
|
6846
|
+
return venus.config.environment.browserInfo.language;
|
|
6847
|
+
}
|
|
6848
|
+
}
|
|
6849
|
+
if (typeof navigator !== "undefined" && navigator.language) {
|
|
6850
|
+
return navigator.language;
|
|
6851
|
+
}
|
|
6852
|
+
return "en-US";
|
|
6853
|
+
};
|
|
6854
|
+
this.getLanguageCode = () => {
|
|
6855
|
+
const locale = this.getLocale();
|
|
6856
|
+
return locale.split("-")[0];
|
|
6857
|
+
};
|
|
7559
6858
|
}
|
|
7560
6859
|
// Generate deterministic instance ID based on current page URL
|
|
7561
6860
|
_generateDeterministicInstanceId() {
|
|
@@ -7592,13 +6891,9 @@ var VenusAPI2 = class {
|
|
|
7592
6891
|
// BOOTSTRAP METHODS
|
|
7593
6892
|
//---------------------------------------
|
|
7594
6893
|
_detectHostedEnvironment() {
|
|
7595
|
-
console.log("[Venus SDK] Detecting host environment...");
|
|
7596
6894
|
const isInIframe = window.self !== window.top;
|
|
7597
6895
|
const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
|
|
7598
6896
|
this._bootstrap.isInsideHostedEnvironment = isInIframe || hasReactNativeWebView;
|
|
7599
|
-
console.log(
|
|
7600
|
-
`[Venus SDK] isInIframe: ${isInIframe}, hasReactNativeWebView: ${hasReactNativeWebView}`
|
|
7601
|
-
);
|
|
7602
6897
|
}
|
|
7603
6898
|
isMobile() {
|
|
7604
6899
|
return typeof window.ReactNativeWebView !== "undefined";
|
|
@@ -7653,7 +6948,6 @@ instance.isAvailable = function() {
|
|
|
7653
6948
|
(async () => {
|
|
7654
6949
|
try {
|
|
7655
6950
|
await initializeNumbers(instance);
|
|
7656
|
-
console.log("[Venus SDK] Numbers system initialized");
|
|
7657
6951
|
} catch (error) {
|
|
7658
6952
|
console.error("[Venus SDK] Failed to initialize numbers system:", error);
|
|
7659
6953
|
}
|