@series-inc/venus-sdk 3.0.6 → 3.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1180 -14
- package/dist/{AdsApi-CIXV8I_p.d.mts → AdsApi-meVfUcZy.d.mts} +164 -355
- package/dist/{AdsApi-CIXV8I_p.d.ts → AdsApi-meVfUcZy.d.ts} +164 -355
- package/dist/chunk-2PDL7CQK.mjs +26 -0
- package/dist/chunk-2PDL7CQK.mjs.map +1 -0
- package/dist/{chunk-LBJFUHOH.mjs → chunk-EMVTVSGL.mjs} +1471 -737
- package/dist/chunk-EMVTVSGL.mjs.map +1 -0
- package/dist/chunk-IZLOB7DV.mjs +343 -0
- package/dist/chunk-IZLOB7DV.mjs.map +1 -0
- package/dist/{chunk-MWUS3A7C.mjs → chunk-QABXMFND.mjs} +3 -7
- package/dist/chunk-QABXMFND.mjs.map +1 -0
- package/dist/core-5JLON75E.mjs +4 -0
- package/dist/{core-RDMPQV6U.mjs.map → core-5JLON75E.mjs.map} +1 -1
- package/dist/index.cjs +1883 -778
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +113 -61
- package/dist/index.d.ts +113 -61
- package/dist/index.mjs +8 -2
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +1806 -748
- 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 +311 -3
- package/dist/venus-api/index.mjs.map +1 -1
- package/dist/vite/index.cjs +534 -0
- package/dist/vite/index.cjs.map +1 -0
- package/dist/vite/index.mjs +527 -0
- package/dist/vite/index.mjs.map +1 -0
- package/dist/webview/index.cjs +346 -0
- package/dist/webview/index.cjs.map +1 -0
- package/dist/webview/index.d.mts +17 -0
- package/dist/webview/index.d.ts +17 -0
- package/dist/webview/index.mjs +4 -0
- package/dist/webview/index.mjs.map +1 -0
- package/package.json +19 -1
- package/dist/chunk-LBJFUHOH.mjs.map +0 -1
- package/dist/chunk-MWUS3A7C.mjs.map +0 -1
- package/dist/core-RDMPQV6U.mjs +0 -3
package/dist/venus-api/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
8
|
var __esm = (fn, res) => function __init() {
|
|
7
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
@@ -10,6 +12,15 @@ var __export = (target, all) => {
|
|
|
10
12
|
for (var name in all)
|
|
11
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
14
|
};
|
|
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);
|
|
13
24
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
25
|
|
|
15
26
|
// src/venus-api/systems/core.js
|
|
@@ -100,6 +111,221 @@ var init_core = __esm({
|
|
|
100
111
|
}
|
|
101
112
|
});
|
|
102
113
|
|
|
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
|
+
|
|
103
329
|
// src/storage/MockStorageApi.ts
|
|
104
330
|
function createMockStorageApi(storageType, appUrl) {
|
|
105
331
|
const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
|
|
@@ -409,6 +635,190 @@ function initializeAds(venusApiInstance, host) {
|
|
|
409
635
|
venusApiInstance.ads = host.ads;
|
|
410
636
|
}
|
|
411
637
|
|
|
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
|
+
|
|
412
822
|
// src/popups/RpcPopupsApi.ts
|
|
413
823
|
var RpcPopupsApi = class {
|
|
414
824
|
constructor(rpcClient) {
|
|
@@ -561,8 +971,13 @@ var MockNotificationsApi = class {
|
|
|
561
971
|
async cancelNotification(notificationId) {
|
|
562
972
|
const venusApi = this.venusApi;
|
|
563
973
|
if (isWebPlatform()) {
|
|
974
|
+
console.log(
|
|
975
|
+
"[Venus Mock] Cancel notification on web platform (simulated):",
|
|
976
|
+
notificationId
|
|
977
|
+
);
|
|
564
978
|
return true;
|
|
565
979
|
}
|
|
980
|
+
console.log("[Venus Mock] Cancel local notification:", notificationId);
|
|
566
981
|
await createMockDelay(MOCK_DELAYS.short);
|
|
567
982
|
if (venusApi._mock.scheduledNotifications && venusApi._mock.scheduledNotifications[notificationId]) {
|
|
568
983
|
delete venusApi._mock.scheduledNotifications[notificationId];
|
|
@@ -572,8 +987,12 @@ var MockNotificationsApi = class {
|
|
|
572
987
|
}
|
|
573
988
|
async getAllScheduledLocalNotifications() {
|
|
574
989
|
if (isWebPlatform()) {
|
|
990
|
+
console.log(
|
|
991
|
+
"[Venus Mock] Get notifications on web platform (returning empty list)"
|
|
992
|
+
);
|
|
575
993
|
return [];
|
|
576
994
|
}
|
|
995
|
+
console.log("[Venus Mock] Get all scheduled local notifications");
|
|
577
996
|
await createMockDelay(MOCK_DELAYS.short);
|
|
578
997
|
const venusApi = this.venusApi;
|
|
579
998
|
const notifications = venusApi._mock.scheduledNotifications || {};
|
|
@@ -581,8 +1000,10 @@ var MockNotificationsApi = class {
|
|
|
581
1000
|
}
|
|
582
1001
|
async isLocalNotificationsEnabled() {
|
|
583
1002
|
if (isWebPlatform()) {
|
|
1003
|
+
console.log("[Venus Mock] Notifications not available on web platform");
|
|
584
1004
|
return false;
|
|
585
1005
|
}
|
|
1006
|
+
console.log("[Venus Mock] Check if local notifications are enabled");
|
|
586
1007
|
await createMockDelay(MOCK_DELAYS.short);
|
|
587
1008
|
const venusApi = this.venusApi;
|
|
588
1009
|
const isEnabled = venusApi._mock.notificationsEnabled !== false;
|
|
@@ -591,6 +1012,9 @@ var MockNotificationsApi = class {
|
|
|
591
1012
|
async scheduleAsync(title, body, seconds, notificationId, options) {
|
|
592
1013
|
const { priority = 50, groupId, payload } = options || {};
|
|
593
1014
|
if (isWebPlatform()) {
|
|
1015
|
+
console.log(
|
|
1016
|
+
"[Venus Mock] Notifications not supported on web platform, simulating success"
|
|
1017
|
+
);
|
|
594
1018
|
console.info(
|
|
595
1019
|
"\u{1F514} [Venus Mock] Notification would be scheduled:",
|
|
596
1020
|
title || "Untitled",
|
|
@@ -601,11 +1025,14 @@ var MockNotificationsApi = class {
|
|
|
601
1025
|
const mockId = `mock-web-notification-${Date.now()}`;
|
|
602
1026
|
return mockId;
|
|
603
1027
|
}
|
|
1028
|
+
console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
|
|
604
1029
|
const venusApi = this.venusApi;
|
|
605
1030
|
if (!venusApi._mock.pendingRequests) {
|
|
1031
|
+
console.log("[Venus Mock] Initializing pendingRequests");
|
|
606
1032
|
venusApi._mock.pendingRequests = {};
|
|
607
1033
|
}
|
|
608
1034
|
const requestId = Date.now().toString();
|
|
1035
|
+
console.log("[Venus Mock] Creating request with ID:", requestId);
|
|
609
1036
|
return new Promise((resolve) => {
|
|
610
1037
|
venusApi._mock.pendingRequests[requestId] = { resolve };
|
|
611
1038
|
const id = notificationId || `mock-notification-${Date.now()}`;
|
|
@@ -627,8 +1054,13 @@ var MockNotificationsApi = class {
|
|
|
627
1054
|
async setLocalNotificationsEnabled(enabled) {
|
|
628
1055
|
const venusApi = this.venusApi;
|
|
629
1056
|
if (isWebPlatform()) {
|
|
1057
|
+
console.log(
|
|
1058
|
+
"[Venus Mock] Set notifications enabled on web platform (simulated):",
|
|
1059
|
+
enabled
|
|
1060
|
+
);
|
|
630
1061
|
return true;
|
|
631
1062
|
}
|
|
1063
|
+
console.log("[Venus Mock] Set local notifications enabled:", enabled);
|
|
632
1064
|
await createMockDelay(MOCK_DELAYS.short);
|
|
633
1065
|
venusApi._mock.notificationsEnabled = enabled;
|
|
634
1066
|
return enabled;
|
|
@@ -822,6 +1254,7 @@ var MockTimeApi = class {
|
|
|
822
1254
|
maximumFractionDigits: options?.maximumFractionDigits || 2,
|
|
823
1255
|
...options
|
|
824
1256
|
};
|
|
1257
|
+
console.log(`[Venus Mock] Formatting number ${value} with locale ${locale}`);
|
|
825
1258
|
return value.toLocaleString(locale, numberOptions);
|
|
826
1259
|
}
|
|
827
1260
|
formatTime(timestamp, options) {
|
|
@@ -833,9 +1266,13 @@ var MockTimeApi = class {
|
|
|
833
1266
|
hour12: options.hour12 !== void 0 ? options.hour12 : true,
|
|
834
1267
|
...options
|
|
835
1268
|
};
|
|
1269
|
+
console.log(
|
|
1270
|
+
`[Venus Mock] Formatting time ${timestamp} with locale ${locale}`
|
|
1271
|
+
);
|
|
836
1272
|
return date.toLocaleString(locale, dateTimeOptions);
|
|
837
1273
|
}
|
|
838
1274
|
async getFutureTimeAsync(options) {
|
|
1275
|
+
console.log("[Venus Mock] Getting future time with options:", options);
|
|
839
1276
|
const timeInfo = await this.requestTimeAsync();
|
|
840
1277
|
const serverTime = new Date(timeInfo.serverTime);
|
|
841
1278
|
const result = new Date(serverTime);
|
|
@@ -880,6 +1317,7 @@ var MockTimeApi = class {
|
|
|
880
1317
|
return result.getTime();
|
|
881
1318
|
}
|
|
882
1319
|
async requestTimeAsync() {
|
|
1320
|
+
console.log("[Venus Mock] Requesting time");
|
|
883
1321
|
await createMockDelay(MOCK_DELAYS.short);
|
|
884
1322
|
const venusApi = this.venusApi;
|
|
885
1323
|
const mockOffset = venusApi._mock.serverTimeOffset || 2500;
|
|
@@ -893,6 +1331,11 @@ var MockTimeApi = class {
|
|
|
893
1331
|
formattedTime: new Date(localTime).toISOString(),
|
|
894
1332
|
locale: venusApi._mock.user?.locale || "en-US"
|
|
895
1333
|
};
|
|
1334
|
+
console.log("[Venus Mock] Time response:", {
|
|
1335
|
+
serverTime: new Date(timeInfo.serverTime).toISOString(),
|
|
1336
|
+
localTime: new Date(timeInfo.localTime).toISOString(),
|
|
1337
|
+
timezoneOffset: timeInfo.timezoneOffset
|
|
1338
|
+
});
|
|
896
1339
|
return timeInfo;
|
|
897
1340
|
}
|
|
898
1341
|
};
|
|
@@ -1743,11 +2186,14 @@ var VenusAssetLoader = class {
|
|
|
1743
2186
|
}, 1e4);
|
|
1744
2187
|
if (type === "image") {
|
|
1745
2188
|
const img = new Image();
|
|
2189
|
+
console.log(`\u{1F5BC}\uFE0F [Asset Verification] Verifying image: ${url}`);
|
|
1746
2190
|
img.onload = () => {
|
|
2191
|
+
console.log(`\u2705 [Asset Verification] Image verified successfully: ${url}`);
|
|
1747
2192
|
clearTimeout(timeout);
|
|
1748
2193
|
resolve();
|
|
1749
2194
|
};
|
|
1750
2195
|
img.onerror = (error) => {
|
|
2196
|
+
console.log(`\u274C [Asset Verification] Image verification failed: ${url}`, error);
|
|
1751
2197
|
clearTimeout(timeout);
|
|
1752
2198
|
reject(new Error("Failed to load image"));
|
|
1753
2199
|
};
|
|
@@ -1799,6 +2245,7 @@ var VenusAssetLoader = class {
|
|
|
1799
2245
|
const CDN_BASE_URL = "https://venus-static-01293ak.web.app/";
|
|
1800
2246
|
const cleanUrl = url.startsWith("/") ? url.slice(1) : url;
|
|
1801
2247
|
const fullUrl = CDN_BASE_URL + cleanUrl;
|
|
2248
|
+
console.log(`\u{1F310} [Asset Loader] Force remote CDN: ${url} -> ${fullUrl}`);
|
|
1802
2249
|
return fullUrl;
|
|
1803
2250
|
}
|
|
1804
2251
|
if (this.venusAPI && this.venusAPI.isMock && this.venusAPI.isMock()) {
|
|
@@ -4174,6 +4621,7 @@ var MockPostApi = class {
|
|
|
4174
4621
|
}
|
|
4175
4622
|
async toggleFollowAsync() {
|
|
4176
4623
|
const venusApi = this.venusApi;
|
|
4624
|
+
console.log("[Venus Mock] *Toggling follow status");
|
|
4177
4625
|
await createMockDelay(MOCK_DELAYS.short);
|
|
4178
4626
|
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
4179
4627
|
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
@@ -4432,426 +4880,871 @@ function initializeLifecycleApi(venusApi, host) {
|
|
|
4432
4880
|
venusApi.lifecycles = host.lifecycle;
|
|
4433
4881
|
}
|
|
4434
4882
|
|
|
4435
|
-
// src/
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
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;
|
|
4474
|
-
}
|
|
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");
|
|
4883
|
+
// src/simulation/utils.ts
|
|
4884
|
+
function sumContributions(contributions) {
|
|
4885
|
+
const totals = {};
|
|
4886
|
+
for (const profileId in contributions) {
|
|
4887
|
+
for (const entityId in contributions[profileId]) {
|
|
4888
|
+
const amount = contributions[profileId][entityId] || 0;
|
|
4889
|
+
totals[entityId] = (totals[entityId] || 0) + amount;
|
|
4534
4890
|
}
|
|
4535
|
-
}
|
|
4891
|
+
}
|
|
4892
|
+
return totals;
|
|
4536
4893
|
}
|
|
4537
4894
|
|
|
4538
|
-
// src/
|
|
4539
|
-
var
|
|
4895
|
+
// src/simulation/RpcSimulationApi.ts
|
|
4896
|
+
var RpcSimulationApi = class {
|
|
4540
4897
|
constructor(rpcClient) {
|
|
4541
4898
|
__publicField(this, "rpcClient");
|
|
4542
|
-
__publicField(this, "
|
|
4899
|
+
__publicField(this, "_simulationConfig", null);
|
|
4543
4900
|
this.rpcClient = rpcClient;
|
|
4544
|
-
this.subscriptions = {
|
|
4545
|
-
data: {},
|
|
4546
|
-
messages: {},
|
|
4547
|
-
gameEvents: {}
|
|
4548
|
-
};
|
|
4549
4901
|
}
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4902
|
+
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
4903
|
+
return this.rpcClient.call(
|
|
4904
|
+
"H5_SIMULATION_VALIDATE_ASSIGNMENT" /* H5_SIMULATION_VALIDATE_ASSIGNMENT */,
|
|
4905
|
+
{
|
|
4906
|
+
containerId,
|
|
4907
|
+
slotId,
|
|
4908
|
+
itemId
|
|
4909
|
+
}
|
|
4910
|
+
);
|
|
4555
4911
|
}
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
*/
|
|
4559
|
-
setupNotifications(transport) {
|
|
4560
|
-
setupRoomNotifications(transport, () => this.getSubscriptions());
|
|
4912
|
+
sumContributions(contributions) {
|
|
4913
|
+
return sumContributions(contributions);
|
|
4561
4914
|
}
|
|
4562
|
-
|
|
4915
|
+
executeBatchOperationsAsync(operations, validateOnly) {
|
|
4916
|
+
return this.rpcClient.call("H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */, {
|
|
4917
|
+
operations,
|
|
4918
|
+
validateOnly
|
|
4919
|
+
});
|
|
4920
|
+
}
|
|
4921
|
+
async getAvailableItemsAsync(containerId, slotId) {
|
|
4563
4922
|
const response = await this.rpcClient.call(
|
|
4564
|
-
"
|
|
4923
|
+
"H5_SIMULATION_GET_AVAILABLE_ITEMS" /* H5_SIMULATION_GET_AVAILABLE_ITEMS */,
|
|
4565
4924
|
{
|
|
4566
|
-
|
|
4925
|
+
containerId,
|
|
4926
|
+
slotId
|
|
4567
4927
|
}
|
|
4568
4928
|
);
|
|
4569
|
-
|
|
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;
|
|
4929
|
+
return response.availableItems || [];
|
|
4575
4930
|
}
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
"
|
|
4931
|
+
calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
4932
|
+
return this.rpcClient.call(
|
|
4933
|
+
"H5_SIMULATION_CALCULATE_POWER_PREVIEW" /* H5_SIMULATION_CALCULATE_POWER_PREVIEW */,
|
|
4579
4934
|
{
|
|
4580
|
-
|
|
4935
|
+
containerId,
|
|
4936
|
+
slotId,
|
|
4937
|
+
candidateItemId
|
|
4581
4938
|
}
|
|
4582
4939
|
);
|
|
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
|
-
};
|
|
4593
4940
|
}
|
|
4594
|
-
|
|
4941
|
+
assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
4942
|
+
return this.rpcClient.call("H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */, {
|
|
4943
|
+
containerId,
|
|
4944
|
+
slotId,
|
|
4945
|
+
itemId
|
|
4946
|
+
});
|
|
4947
|
+
}
|
|
4948
|
+
removeItemFromSlotAsync(containerId, slotId) {
|
|
4949
|
+
return this.rpcClient.call("H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */, {
|
|
4950
|
+
containerId,
|
|
4951
|
+
slotId
|
|
4952
|
+
});
|
|
4953
|
+
}
|
|
4954
|
+
async getSlotContainersAsync() {
|
|
4595
4955
|
const response = await this.rpcClient.call(
|
|
4596
|
-
"
|
|
4597
|
-
{
|
|
4598
|
-
roomCode
|
|
4599
|
-
}
|
|
4956
|
+
"H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
|
|
4957
|
+
{}
|
|
4600
4958
|
);
|
|
4601
|
-
|
|
4602
|
-
const errorMessage = typeof response.error === "string" ? response.error : "Failed to join room by code";
|
|
4603
|
-
throw new Error(errorMessage);
|
|
4604
|
-
}
|
|
4605
|
-
const room = new VenusRoom(response.roomData);
|
|
4606
|
-
return room;
|
|
4959
|
+
return response.containers || [];
|
|
4607
4960
|
}
|
|
4608
|
-
|
|
4609
|
-
async getUserRoomsAsync(options = {}) {
|
|
4961
|
+
async getSlotAssignmentsAsync(containerId) {
|
|
4610
4962
|
const response = await this.rpcClient.call(
|
|
4611
|
-
"
|
|
4963
|
+
"H5_SIMULATION_GET_ASSIGNMENTS" /* H5_SIMULATION_GET_ASSIGNMENTS */,
|
|
4612
4964
|
{
|
|
4613
|
-
|
|
4965
|
+
containerId
|
|
4614
4966
|
}
|
|
4615
4967
|
);
|
|
4616
|
-
|
|
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;
|
|
4625
|
-
}
|
|
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
|
-
);
|
|
4635
|
-
}
|
|
4636
|
-
}
|
|
4637
|
-
return venusRooms;
|
|
4968
|
+
return Array.isArray(response) ? response : response.assignments || [];
|
|
4638
4969
|
}
|
|
4639
|
-
async
|
|
4970
|
+
async getStateAsync(roomId) {
|
|
4640
4971
|
const response = await this.rpcClient.call(
|
|
4641
|
-
"
|
|
4972
|
+
"H5_SIMULATION_GET_STATE" /* H5_SIMULATION_GET_STATE */,
|
|
4642
4973
|
{
|
|
4643
|
-
roomId
|
|
4644
|
-
updates,
|
|
4645
|
-
merge: options.merge ?? true
|
|
4974
|
+
roomId
|
|
4646
4975
|
}
|
|
4647
4976
|
);
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4977
|
+
console.log("[Venus SDK] getStateAsync", response);
|
|
4978
|
+
if (response.configuration) {
|
|
4979
|
+
this._simulationConfig = response.configuration;
|
|
4651
4980
|
}
|
|
4981
|
+
return response;
|
|
4652
4982
|
}
|
|
4653
|
-
async
|
|
4654
|
-
|
|
4655
|
-
|
|
4983
|
+
async getConfigAsync(roomId) {
|
|
4984
|
+
if (this._simulationConfig) {
|
|
4985
|
+
return this._simulationConfig;
|
|
4986
|
+
}
|
|
4987
|
+
const config = await this.rpcClient.call(
|
|
4988
|
+
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
4989
|
+
{}
|
|
4990
|
+
);
|
|
4991
|
+
console.log("[Venus SDK] getConfigAsync", config);
|
|
4992
|
+
if (config) {
|
|
4993
|
+
this._simulationConfig = config;
|
|
4994
|
+
return config;
|
|
4995
|
+
}
|
|
4996
|
+
throw new Error("No simulation configuration available");
|
|
4997
|
+
}
|
|
4998
|
+
executeRecipeAsync(recipeId, inputs, options) {
|
|
4999
|
+
return this.rpcClient.call("H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */, {
|
|
5000
|
+
recipeId,
|
|
5001
|
+
inputs,
|
|
5002
|
+
roomId: options?.roomId,
|
|
5003
|
+
batchAmount: options?.batchAmount,
|
|
5004
|
+
allowPartialBatch: options?.allowPartialBatch,
|
|
5005
|
+
entity: options?.entity
|
|
5006
|
+
});
|
|
5007
|
+
}
|
|
5008
|
+
collectRecipeAsync(runId) {
|
|
5009
|
+
return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
|
|
5010
|
+
runId
|
|
5011
|
+
});
|
|
5012
|
+
}
|
|
5013
|
+
getActiveRunsAsync(options) {
|
|
5014
|
+
return this.rpcClient.call("H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */, {
|
|
5015
|
+
roomId: options?.roomId
|
|
5016
|
+
});
|
|
5017
|
+
}
|
|
5018
|
+
executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
5019
|
+
return this.rpcClient.call(
|
|
5020
|
+
"H5_SIMULATION_EXECUTE_SCOPED_RECIPE" /* H5_SIMULATION_EXECUTE_SCOPED_RECIPE */,
|
|
4656
5021
|
{
|
|
4657
|
-
|
|
5022
|
+
recipeId,
|
|
5023
|
+
entity,
|
|
5024
|
+
inputs,
|
|
5025
|
+
roomId: options?.roomId ?? null,
|
|
5026
|
+
options
|
|
4658
5027
|
}
|
|
4659
5028
|
);
|
|
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;
|
|
4665
5029
|
}
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
"
|
|
5030
|
+
getAvailableRecipesAsync(options) {
|
|
5031
|
+
return this.rpcClient.call(
|
|
5032
|
+
"H5_SIMULATION_GET_AVAILABLE_RECIPES" /* H5_SIMULATION_GET_AVAILABLE_RECIPES */,
|
|
4669
5033
|
{
|
|
4670
|
-
roomId:
|
|
4671
|
-
|
|
4672
|
-
metadata: request.metadata
|
|
5034
|
+
roomId: options?.roomId || null,
|
|
5035
|
+
includeActorRecipes: options?.includeActorRecipes || false
|
|
4673
5036
|
}
|
|
4674
5037
|
);
|
|
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;
|
|
4680
5038
|
}
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
"
|
|
5039
|
+
getRecipeRequirementsAsync(recipe) {
|
|
5040
|
+
return this.rpcClient.call(
|
|
5041
|
+
"H5_SIMULATION_GET_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_RECIPE_REQUIREMENTS */,
|
|
4684
5042
|
{
|
|
4685
|
-
|
|
5043
|
+
recipeId: recipe.recipeId,
|
|
5044
|
+
entity: recipe.entity,
|
|
5045
|
+
batchAmount: recipe.batchAmount
|
|
4686
5046
|
}
|
|
4687
5047
|
);
|
|
4688
|
-
if (response?.success === false) {
|
|
4689
|
-
const errorMessage = typeof response.error === "string" ? response.error : "Failed to leave room";
|
|
4690
|
-
throw new Error(errorMessage);
|
|
4691
|
-
}
|
|
4692
5048
|
}
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
"
|
|
5049
|
+
getBatchRecipeRequirementsAsync(recipes) {
|
|
5050
|
+
return this.rpcClient.call(
|
|
5051
|
+
"H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS */,
|
|
4696
5052
|
{
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
5053
|
+
recipes
|
|
5054
|
+
}
|
|
5055
|
+
);
|
|
5056
|
+
}
|
|
5057
|
+
triggerRecipeChainAsync(recipeId, options) {
|
|
5058
|
+
return this.rpcClient.call(
|
|
5059
|
+
"H5_SIMULATION_TRIGGER_RECIPE_CHAIN" /* H5_SIMULATION_TRIGGER_RECIPE_CHAIN */,
|
|
5060
|
+
{
|
|
5061
|
+
triggerRecipeId: recipeId,
|
|
5062
|
+
context: options?.context,
|
|
5063
|
+
roomId: options?.roomId
|
|
5064
|
+
}
|
|
5065
|
+
);
|
|
5066
|
+
}
|
|
5067
|
+
getEntityMetadataAsync(entityId) {
|
|
5068
|
+
return this.rpcClient.call(
|
|
5069
|
+
"H5_SIMULATION_GET_ENTITY_METADATA" /* H5_SIMULATION_GET_ENTITY_METADATA */,
|
|
5070
|
+
{
|
|
5071
|
+
entityId
|
|
4700
5072
|
}
|
|
4701
5073
|
);
|
|
4702
|
-
if (response?.success === false) {
|
|
4703
|
-
const errorMessage = typeof response.error === "string" ? response.error : "Failed to start game";
|
|
4704
|
-
throw new Error(errorMessage);
|
|
4705
|
-
}
|
|
4706
5074
|
}
|
|
4707
|
-
async
|
|
5075
|
+
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
4708
5076
|
const response = await this.rpcClient.call(
|
|
4709
|
-
"
|
|
5077
|
+
"H5_SIMULATION_RESOLVE_VALUE" /* H5_SIMULATION_RESOLVE_VALUE */,
|
|
4710
5078
|
{
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
clientContext: proposalPayload.clientContext,
|
|
4715
|
-
clientProposalId: proposalPayload.clientProposalId
|
|
5079
|
+
entityId,
|
|
5080
|
+
fieldPath,
|
|
5081
|
+
entity
|
|
4716
5082
|
}
|
|
4717
5083
|
);
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
5084
|
+
return response.value;
|
|
5085
|
+
}
|
|
5086
|
+
};
|
|
5087
|
+
|
|
5088
|
+
// src/simulation/MockSimulationApi.ts
|
|
5089
|
+
function generateAppIdentifier2() {
|
|
5090
|
+
if (typeof window === "undefined") return "unknown-app";
|
|
5091
|
+
const url = window.location.href;
|
|
5092
|
+
const match = url.match(/\/H5\/([^\/]+)/);
|
|
5093
|
+
return match ? match[1] : "unknown-app";
|
|
5094
|
+
}
|
|
5095
|
+
var MockSimulationApi = class {
|
|
5096
|
+
constructor(simulationConfig = null) {
|
|
5097
|
+
__publicField(this, "mockSimulationConfigs", /* @__PURE__ */ new Map());
|
|
5098
|
+
// appIdentifier -> config
|
|
5099
|
+
__publicField(this, "mockSimulationStates", /* @__PURE__ */ new Map());
|
|
5100
|
+
// appIdentifier -> config
|
|
5101
|
+
__publicField(this, "mockActiveTimers", /* @__PURE__ */ new Map());
|
|
5102
|
+
// appIdentifier -> timers[]
|
|
5103
|
+
__publicField(this, "appId");
|
|
5104
|
+
__publicField(this, "providedSimulationConfig");
|
|
5105
|
+
this.appId = generateAppIdentifier2();
|
|
5106
|
+
this.providedSimulationConfig = simulationConfig;
|
|
5107
|
+
}
|
|
5108
|
+
sumContributions(contributions) {
|
|
5109
|
+
return sumContributions(contributions);
|
|
5110
|
+
}
|
|
5111
|
+
async validateSlotAssignmentAsync(containerId, slotId, itemId) {
|
|
5112
|
+
this.log("validateSlotAssignmentAsync called:", {
|
|
5113
|
+
containerId,
|
|
5114
|
+
slotId,
|
|
5115
|
+
itemId
|
|
5116
|
+
});
|
|
5117
|
+
return { valid: true, message: "Mock validation successful" };
|
|
5118
|
+
}
|
|
5119
|
+
async executeBatchOperationsAsync(operations, validateOnly) {
|
|
5120
|
+
this.log("executeBatchOperationsAsync called:", {
|
|
5121
|
+
operations,
|
|
5122
|
+
validateOnly
|
|
5123
|
+
});
|
|
5124
|
+
return {
|
|
5125
|
+
success: true,
|
|
5126
|
+
results: operations.map(() => ({ success: true }))
|
|
5127
|
+
};
|
|
5128
|
+
}
|
|
5129
|
+
async getAvailableItemsAsync(containerId, slotId) {
|
|
5130
|
+
console.log("[Venus Simulation Mock] getAvailableItemsAsync called:", {
|
|
5131
|
+
containerId,
|
|
5132
|
+
slotId
|
|
5133
|
+
});
|
|
5134
|
+
const appIdentifier = generateAppIdentifier2();
|
|
5135
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5136
|
+
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
5137
|
+
entities: {}
|
|
5138
|
+
};
|
|
5139
|
+
const availableItems = Object.entries(config.entities).slice(0, 3).map(([entityId, entity]) => ({
|
|
5140
|
+
entityId,
|
|
5141
|
+
quantity: 1,
|
|
5142
|
+
metadata: entity.metadata,
|
|
5143
|
+
powerPreview: 100
|
|
5144
|
+
// Mock power value
|
|
5145
|
+
}));
|
|
5146
|
+
return availableItems;
|
|
5147
|
+
}
|
|
5148
|
+
async calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
|
|
5149
|
+
this.log("calculatePowerPreviewAsync called:", {
|
|
5150
|
+
containerId,
|
|
5151
|
+
slotId,
|
|
5152
|
+
candidateItemId
|
|
5153
|
+
});
|
|
5154
|
+
return {
|
|
5155
|
+
currentPower: 1e3,
|
|
5156
|
+
previewPower: 1200,
|
|
5157
|
+
powerDelta: 200,
|
|
5158
|
+
breakdown: { base: 800, weapon: 200, armor: 200 }
|
|
5159
|
+
};
|
|
5160
|
+
}
|
|
5161
|
+
async getSlotContainersAsync() {
|
|
5162
|
+
this.log("getSlotContainersAsync called");
|
|
5163
|
+
const appIdentifier = this.appId;
|
|
5164
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5165
|
+
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
5166
|
+
entities: {}
|
|
5167
|
+
};
|
|
5168
|
+
const containers = Object.entries(config.entities).filter(([_2, entity]) => entity.metadata?.slots).map(([entityId, entity]) => ({
|
|
5169
|
+
entityId,
|
|
5170
|
+
slots: entity.metadata?.slots,
|
|
5171
|
+
isOwned: true
|
|
5172
|
+
// Mock: assume all containers are owned
|
|
5173
|
+
}));
|
|
5174
|
+
return containers;
|
|
5175
|
+
}
|
|
5176
|
+
async getSlotAssignmentsAsync(containerId) {
|
|
5177
|
+
this.log("getSlotAssignmentsAsync called for:", containerId);
|
|
5178
|
+
return [];
|
|
5179
|
+
}
|
|
5180
|
+
async resolveFieldValueAsync(entityId, fieldPath, entity) {
|
|
5181
|
+
this.log("resolveFieldValueAsync called:", {
|
|
5182
|
+
entityId,
|
|
5183
|
+
fieldPath,
|
|
5184
|
+
entity
|
|
5185
|
+
});
|
|
5186
|
+
const mockValues = {
|
|
5187
|
+
basePower: 850,
|
|
5188
|
+
weaponPower: 300,
|
|
5189
|
+
armorPower: 150,
|
|
5190
|
+
total_power: 1300,
|
|
5191
|
+
total_defense_power: 5e3
|
|
5192
|
+
};
|
|
5193
|
+
return mockValues[fieldPath] || 100;
|
|
5194
|
+
}
|
|
5195
|
+
async getEntityMetadataAsync(entityId) {
|
|
5196
|
+
this.log("getEntityMetadataAsync called for:", entityId);
|
|
5197
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5198
|
+
const appIdentifier = this.appId;
|
|
5199
|
+
const config = mockSimulationConfigs.get(
|
|
5200
|
+
appIdentifier
|
|
5201
|
+
) || {
|
|
5202
|
+
entities: {}};
|
|
5203
|
+
const entity = config.entities[entityId];
|
|
5204
|
+
return entity?.metadata || {};
|
|
5205
|
+
}
|
|
5206
|
+
async collectRecipeAsync(runId) {
|
|
5207
|
+
this.log("collectRecipeAsync called:", { runId });
|
|
5208
|
+
const mockRewards = {
|
|
5209
|
+
cash: Math.floor(Math.random() * 1e3) + 500,
|
|
5210
|
+
experience: Math.floor(Math.random() * 50) + 25
|
|
5211
|
+
};
|
|
5212
|
+
return {
|
|
5213
|
+
success: true,
|
|
5214
|
+
runId,
|
|
5215
|
+
rewards: mockRewards,
|
|
5216
|
+
message: "Rewards collected successfully"
|
|
5217
|
+
};
|
|
5218
|
+
}
|
|
5219
|
+
executeRecipeAsync(recipeId, inputs, options) {
|
|
5220
|
+
this.log("executeRecipeAsync called:", {
|
|
5221
|
+
recipeId,
|
|
5222
|
+
inputs,
|
|
5223
|
+
options
|
|
5224
|
+
});
|
|
5225
|
+
const appIdentifier = this.appId;
|
|
5226
|
+
return this.executeRecipe(appIdentifier, recipeId, inputs);
|
|
5227
|
+
}
|
|
5228
|
+
async executeScopedRecipeAsync(recipeId, entity, inputs, options) {
|
|
5229
|
+
this.log("executeScopedRecipeAsync called:", {
|
|
5230
|
+
recipeId,
|
|
5231
|
+
entity,
|
|
5232
|
+
inputs,
|
|
5233
|
+
roomId: options?.roomId,
|
|
5234
|
+
options
|
|
5235
|
+
});
|
|
5236
|
+
return {
|
|
5237
|
+
success: true,
|
|
5238
|
+
message: "Mock scoped recipe execution successful"
|
|
5239
|
+
};
|
|
5240
|
+
}
|
|
5241
|
+
async getActiveRunsAsync(options) {
|
|
5242
|
+
this.log("getActiveRunsAsync called:", options);
|
|
5243
|
+
const appIdentifier = this.appId;
|
|
5244
|
+
let state = this.mockSimulationStates.get(appIdentifier);
|
|
5245
|
+
if (!state) {
|
|
5246
|
+
state = await this.initializeSimulationState(appIdentifier);
|
|
4721
5247
|
}
|
|
4722
|
-
return
|
|
5248
|
+
return state.activeRuns || [];
|
|
5249
|
+
}
|
|
5250
|
+
async getAvailableRecipesAsync(options) {
|
|
5251
|
+
this.log("getAvailableRecipesAsync called:", options);
|
|
5252
|
+
const baseRecipes = [
|
|
5253
|
+
{ id: "collect_resources", scope: "player", clientViewable: true },
|
|
5254
|
+
{ id: "upgrade_equipment", scope: "player", clientViewable: true }
|
|
5255
|
+
];
|
|
5256
|
+
if (options?.roomId) {
|
|
5257
|
+
baseRecipes.push(
|
|
5258
|
+
{ id: "room_upgrade", scope: "room", clientViewable: true },
|
|
5259
|
+
{ id: "cooperative_project", scope: "room", clientViewable: true }
|
|
5260
|
+
);
|
|
5261
|
+
}
|
|
5262
|
+
if (options?.includeActorRecipes && options?.roomId) {
|
|
5263
|
+
baseRecipes.push(
|
|
5264
|
+
{ id: "trade_with_npc", scope: "actor", clientViewable: true },
|
|
5265
|
+
{ id: "attack_monster", scope: "actor", clientViewable: true }
|
|
5266
|
+
);
|
|
5267
|
+
}
|
|
5268
|
+
return { success: true, recipes: baseRecipes };
|
|
5269
|
+
}
|
|
5270
|
+
async getBatchRecipeRequirementsAsync(recipes) {
|
|
5271
|
+
this.log("getBatchRecipeRequirementsAsync called:", {
|
|
5272
|
+
count: recipes?.length
|
|
5273
|
+
});
|
|
5274
|
+
const results = (recipes || []).map((q) => ({
|
|
5275
|
+
recipeId: q.recipeId,
|
|
5276
|
+
entity: q.entity || null,
|
|
5277
|
+
amount: q.batchAmount || 1,
|
|
5278
|
+
inputs: { cash: "BE:0" },
|
|
5279
|
+
canAfford: true,
|
|
5280
|
+
disabled: false
|
|
5281
|
+
}));
|
|
5282
|
+
return { success: true, results };
|
|
4723
5283
|
}
|
|
4724
|
-
async
|
|
5284
|
+
async getRecipeRequirementsAsync(recipe) {
|
|
5285
|
+
this.log("getRecipeRequirementsAsync called:", recipe);
|
|
5286
|
+
return {
|
|
5287
|
+
recipeId: recipe.recipeId,
|
|
5288
|
+
entity: recipe.entity || null,
|
|
5289
|
+
amount: recipe.batchAmount,
|
|
5290
|
+
inputs: { cash: "BE:0" },
|
|
5291
|
+
canAfford: true,
|
|
5292
|
+
disabled: false
|
|
5293
|
+
};
|
|
5294
|
+
}
|
|
5295
|
+
async triggerRecipeChainAsync(recipeId, options) {
|
|
5296
|
+
this.log("triggerRecipeChainAsync called:", { recipeId, ...options });
|
|
4725
5297
|
return {
|
|
4726
5298
|
success: true,
|
|
4727
|
-
|
|
4728
|
-
isValid: verdict.isValid,
|
|
4729
|
-
reason: verdict.reason
|
|
5299
|
+
message: "Mock recipe chain triggered successfully"
|
|
4730
5300
|
};
|
|
4731
5301
|
}
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
const
|
|
4738
|
-
const
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
5302
|
+
log(message, ...args) {
|
|
5303
|
+
console.log(`[Venus Sim Mock] ${message}`, args);
|
|
5304
|
+
}
|
|
5305
|
+
async executeRecipe(appIdentifier, recipeId, inputs) {
|
|
5306
|
+
this.log(`Executing recipe ${recipeId} for ${appIdentifier}`, inputs);
|
|
5307
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5308
|
+
const mockSimulationStates = this.mockSimulationStates;
|
|
5309
|
+
let config = mockSimulationConfigs.get(appIdentifier);
|
|
5310
|
+
let state = mockSimulationStates.get(appIdentifier);
|
|
5311
|
+
if (!config || !state) {
|
|
5312
|
+
state = await this.initializeSimulationState(appIdentifier);
|
|
5313
|
+
config = mockSimulationConfigs.get(appIdentifier);
|
|
5314
|
+
if (!config) {
|
|
5315
|
+
throw new Error("Failed to initialize simulation config");
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
const recipe = config.recipes?.[recipeId];
|
|
5319
|
+
if (!recipe) {
|
|
5320
|
+
throw new Error(`Recipe ${recipeId} not found`);
|
|
5321
|
+
}
|
|
5322
|
+
if (state.disabledRecipes?.includes(recipeId)) {
|
|
5323
|
+
throw new Error(`Recipe ${recipeId} is disabled`);
|
|
5324
|
+
}
|
|
5325
|
+
if (recipe.inputs) {
|
|
5326
|
+
for (const [entityId, required] of Object.entries(recipe.inputs)) {
|
|
5327
|
+
const available = state.inventory[entityId] || 0;
|
|
5328
|
+
if (available < required) {
|
|
5329
|
+
throw new Error(
|
|
5330
|
+
`Insufficient ${entityId}: required ${required}, available ${available}`
|
|
5331
|
+
);
|
|
5332
|
+
}
|
|
4751
5333
|
}
|
|
4752
5334
|
}
|
|
4753
|
-
if (
|
|
4754
|
-
|
|
4755
|
-
|
|
5335
|
+
if (recipe.inputs) {
|
|
5336
|
+
for (const [entityId, input] of Object.entries(recipe.inputs)) {
|
|
5337
|
+
const inventoryValue = state.inventory[entityId] || 0;
|
|
5338
|
+
if (typeof input === "number" && typeof inventoryValue === "number") {
|
|
5339
|
+
state.inventory[entityId] = inventoryValue - input;
|
|
5340
|
+
}
|
|
4756
5341
|
}
|
|
4757
|
-
this.subscriptions.data[roomId].push(options.onData);
|
|
4758
5342
|
}
|
|
4759
|
-
if (
|
|
4760
|
-
|
|
4761
|
-
this.subscriptions.messages[roomId] = [];
|
|
4762
|
-
}
|
|
4763
|
-
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
5343
|
+
if (recipe.beginEffects) {
|
|
5344
|
+
this.applyEffects(state, recipe.beginEffects);
|
|
4764
5345
|
}
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
5346
|
+
const runId = this.generateRunId();
|
|
5347
|
+
const now = Date.now();
|
|
5348
|
+
const expiresAt = now + (recipe.duration || 0);
|
|
5349
|
+
const run = {
|
|
5350
|
+
id: runId,
|
|
5351
|
+
recipeId,
|
|
5352
|
+
status: "running",
|
|
5353
|
+
startTime: now,
|
|
5354
|
+
expiresAt,
|
|
5355
|
+
inputs: recipe.inputs || {}
|
|
5356
|
+
};
|
|
5357
|
+
state.activeRuns.push(run);
|
|
5358
|
+
if (recipe.duration === 0) {
|
|
5359
|
+
this.completeRun(appIdentifier, runId);
|
|
5360
|
+
return { status: "completed", runId };
|
|
5361
|
+
} else {
|
|
5362
|
+
const mockActiveTimers = this.mockActiveTimers;
|
|
5363
|
+
const timer = setTimeout(() => {
|
|
5364
|
+
this.completeRun(appIdentifier, runId);
|
|
5365
|
+
}, recipe.duration);
|
|
5366
|
+
const timers = mockActiveTimers.get(appIdentifier) || [];
|
|
5367
|
+
timers.push(timer);
|
|
5368
|
+
mockActiveTimers.set(appIdentifier, timers);
|
|
5369
|
+
return {
|
|
5370
|
+
status: "running",
|
|
5371
|
+
runId,
|
|
5372
|
+
expiresAt: new Date(expiresAt).toISOString()
|
|
5373
|
+
};
|
|
4770
5374
|
}
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
5375
|
+
}
|
|
5376
|
+
async initializeSimulationState(appIdentifier) {
|
|
5377
|
+
this.log(`Initializing simulation state for ${appIdentifier}`);
|
|
5378
|
+
const providedSimulationConfig = this.providedSimulationConfig;
|
|
5379
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5380
|
+
const mockSimulationStates = this.mockSimulationStates;
|
|
5381
|
+
const mockActiveTimers = this.mockActiveTimers;
|
|
5382
|
+
const config = providedSimulationConfig || {
|
|
5383
|
+
version: "1.0",
|
|
5384
|
+
entities: {},
|
|
5385
|
+
recipes: {}
|
|
5386
|
+
};
|
|
5387
|
+
mockSimulationConfigs.set(appIdentifier, config);
|
|
5388
|
+
const initialInventory = {};
|
|
5389
|
+
if (providedSimulationConfig && config.entities) {
|
|
5390
|
+
Object.keys(config.entities).forEach((entityId) => {
|
|
5391
|
+
initialInventory[entityId] = 0;
|
|
5392
|
+
});
|
|
5393
|
+
}
|
|
5394
|
+
const state = {
|
|
5395
|
+
inventory: initialInventory,
|
|
5396
|
+
activeRuns: [],
|
|
5397
|
+
disabledRecipes: new Array()
|
|
5398
|
+
};
|
|
5399
|
+
if (config.recipes) {
|
|
5400
|
+
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
5401
|
+
if (recipe.metadata?.startsDisabled) {
|
|
5402
|
+
state.disabledRecipes.push(recipeId);
|
|
4782
5403
|
}
|
|
4783
|
-
}
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
5404
|
+
});
|
|
5405
|
+
}
|
|
5406
|
+
mockSimulationStates.set(appIdentifier, state);
|
|
5407
|
+
mockActiveTimers.set(appIdentifier, []);
|
|
5408
|
+
console.log(
|
|
5409
|
+
`[Venus Simulation Mock] Initialized state for ${appIdentifier}:`,
|
|
5410
|
+
state
|
|
5411
|
+
);
|
|
5412
|
+
if (config.recipes) {
|
|
5413
|
+
Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
|
|
5414
|
+
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
5415
|
+
if (isAutoRestart && recipe.outputs) {
|
|
5416
|
+
this.log(`Found auto-restart recipe: ${recipeId}`, {
|
|
5417
|
+
topLevelAutoRestart: recipe.autoRestart,
|
|
5418
|
+
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
5419
|
+
hasOutputs: !!recipe.outputs,
|
|
5420
|
+
duration: recipe.duration
|
|
5421
|
+
});
|
|
5422
|
+
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
5423
|
+
if (condition && condition.entity) {
|
|
5424
|
+
const currentAmount = initialInventory[condition.entity] || 0;
|
|
5425
|
+
if (currentAmount < condition.maxValue) {
|
|
5426
|
+
console.log(
|
|
5427
|
+
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization`,
|
|
5428
|
+
{
|
|
5429
|
+
currentAmount,
|
|
5430
|
+
maxValue: condition.maxValue,
|
|
5431
|
+
entity: condition.entity
|
|
5432
|
+
}
|
|
5433
|
+
);
|
|
5434
|
+
setTimeout(() => {
|
|
5435
|
+
this.executeRecipe(appIdentifier, recipeId, {});
|
|
5436
|
+
}, 1e3);
|
|
5437
|
+
}
|
|
5438
|
+
} else {
|
|
5439
|
+
console.log(
|
|
5440
|
+
`[Venus Simulation Mock] Auto-starting ${recipeId} at initialization (no condition)`
|
|
5441
|
+
);
|
|
5442
|
+
setTimeout(() => {
|
|
5443
|
+
this.executeRecipe(appIdentifier, recipeId, {});
|
|
5444
|
+
}, 1e3);
|
|
4790
5445
|
}
|
|
4791
5446
|
}
|
|
5447
|
+
});
|
|
5448
|
+
}
|
|
5449
|
+
return state;
|
|
5450
|
+
}
|
|
5451
|
+
generateRunId() {
|
|
5452
|
+
return "run_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
5453
|
+
}
|
|
5454
|
+
completeRun(appIdentifier, runId) {
|
|
5455
|
+
this.log(`Completing run ${runId} for ${appIdentifier}`);
|
|
5456
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5457
|
+
const mockSimulationStates = this.mockSimulationStates;
|
|
5458
|
+
const config = mockSimulationConfigs.get(appIdentifier);
|
|
5459
|
+
const state = mockSimulationStates.get(appIdentifier);
|
|
5460
|
+
if (!config || !state) return;
|
|
5461
|
+
const runIndex = state.activeRuns.findIndex((r2) => r2.id === runId);
|
|
5462
|
+
if (runIndex === -1) return;
|
|
5463
|
+
const run = state.activeRuns[runIndex];
|
|
5464
|
+
const recipe = config.recipes?.[run.recipeId];
|
|
5465
|
+
if (!recipe) return;
|
|
5466
|
+
const outputs = {};
|
|
5467
|
+
const rng = this.createSeededRandom(runId);
|
|
5468
|
+
if (recipe.outputs) {
|
|
5469
|
+
for (const [entityId, value] of Object.entries(recipe.outputs)) {
|
|
5470
|
+
if (typeof value === "number") {
|
|
5471
|
+
outputs[entityId] = value;
|
|
5472
|
+
} else if (typeof value === "object" && value != null && "min" in value && "max" in value && typeof value.min == "number" && typeof value.max === "number") {
|
|
5473
|
+
outputs[entityId] = Math.floor(rng() * (value.max - value.min + 1)) + value.min;
|
|
5474
|
+
}
|
|
4792
5475
|
}
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
5476
|
+
}
|
|
5477
|
+
for (const [entityId, amount] of Object.entries(outputs)) {
|
|
5478
|
+
state.inventory[entityId] = (state.inventory[entityId] || 0) + amount;
|
|
5479
|
+
}
|
|
5480
|
+
if (recipe.endEffects) {
|
|
5481
|
+
this.applyEffects(state, recipe.endEffects);
|
|
5482
|
+
}
|
|
5483
|
+
run.status = "completed";
|
|
5484
|
+
run.outputs = outputs;
|
|
5485
|
+
state.activeRuns.splice(runIndex, 1);
|
|
5486
|
+
const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
|
|
5487
|
+
if (isAutoRestart) {
|
|
5488
|
+
console.log(
|
|
5489
|
+
`[Venus Simulation Mock] Checking auto-restart for ${run.recipeId}`,
|
|
5490
|
+
{
|
|
5491
|
+
topLevelAutoRestart: recipe.autoRestart,
|
|
5492
|
+
metadataAutoRestart: recipe.metadata?.autoRestart,
|
|
5493
|
+
hasCondition: !!(recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition)
|
|
5494
|
+
}
|
|
5495
|
+
);
|
|
5496
|
+
const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
|
|
5497
|
+
if (condition) {
|
|
5498
|
+
const currentAmount = state.inventory[condition.entity] || 0;
|
|
5499
|
+
if (currentAmount < condition.maxValue) {
|
|
5500
|
+
console.log(
|
|
5501
|
+
`[Venus Simulation Mock] Auto-restarting ${run.recipeId}`,
|
|
5502
|
+
{
|
|
5503
|
+
currentAmount,
|
|
5504
|
+
maxValue: condition.maxValue,
|
|
5505
|
+
entity: condition.entity
|
|
5506
|
+
}
|
|
5507
|
+
);
|
|
5508
|
+
setTimeout(() => {
|
|
5509
|
+
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
5510
|
+
}, 1e3);
|
|
4800
5511
|
}
|
|
5512
|
+
} else {
|
|
5513
|
+
console.log(
|
|
5514
|
+
`[Venus Simulation Mock] Auto-restarting ${run.recipeId} (no condition)`
|
|
5515
|
+
);
|
|
5516
|
+
setTimeout(() => {
|
|
5517
|
+
this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
|
|
5518
|
+
}, 1e3);
|
|
4801
5519
|
}
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
5520
|
+
}
|
|
5521
|
+
console.log(
|
|
5522
|
+
`[Venus Simulation Mock] Completed run ${runId}, outputs:`,
|
|
5523
|
+
outputs
|
|
5524
|
+
);
|
|
5525
|
+
}
|
|
5526
|
+
createSeededRandom(seed) {
|
|
5527
|
+
let hash = 0;
|
|
5528
|
+
for (let i = 0; i < seed.length; i++) {
|
|
5529
|
+
const char = seed.charCodeAt(i);
|
|
5530
|
+
hash = (hash << 5) - hash + char;
|
|
5531
|
+
hash = hash & hash;
|
|
5532
|
+
}
|
|
5533
|
+
return () => {
|
|
5534
|
+
hash = (hash * 9301 + 49297) % 233280;
|
|
5535
|
+
return hash / 233280;
|
|
5536
|
+
};
|
|
5537
|
+
}
|
|
5538
|
+
applyEffects(state, effects) {
|
|
5539
|
+
if (!effects || !Array.isArray(effects)) return;
|
|
5540
|
+
for (const effect of effects) {
|
|
5541
|
+
switch (effect.type) {
|
|
5542
|
+
case "set":
|
|
5543
|
+
state.inventory[effect.target] = effect.value;
|
|
5544
|
+
console.log(
|
|
5545
|
+
`[Venus Simulation Mock] Effect: Set ${effect.target} = ${effect.value}`
|
|
5546
|
+
);
|
|
5547
|
+
break;
|
|
5548
|
+
case "add":
|
|
5549
|
+
state.inventory[effect.target] = (state.inventory[effect.target] || 0) + effect.value;
|
|
5550
|
+
console.log(
|
|
5551
|
+
`[Venus Simulation Mock] Effect: Add ${effect.value} to ${effect.target} (new value: ${state.inventory[effect.target]})`
|
|
5552
|
+
);
|
|
5553
|
+
break;
|
|
5554
|
+
case "multiply":
|
|
5555
|
+
state.inventory[effect.target] = (state.inventory[effect.target] || 0) * effect.value;
|
|
5556
|
+
console.log(
|
|
5557
|
+
`[Venus Simulation Mock] Effect: Multiply ${effect.target} by ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5558
|
+
);
|
|
5559
|
+
break;
|
|
5560
|
+
case "min":
|
|
5561
|
+
state.inventory[effect.target] = Math.max(
|
|
5562
|
+
state.inventory[effect.target] || 0,
|
|
5563
|
+
effect.value
|
|
5564
|
+
);
|
|
5565
|
+
console.log(
|
|
5566
|
+
`[Venus Simulation Mock] Effect: Set ${effect.target} min ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5567
|
+
);
|
|
5568
|
+
break;
|
|
5569
|
+
case "max":
|
|
5570
|
+
state.inventory[effect.target] = Math.min(
|
|
5571
|
+
state.inventory[effect.target] || 0,
|
|
5572
|
+
effect.value
|
|
5573
|
+
);
|
|
5574
|
+
console.log(
|
|
5575
|
+
`[Venus Simulation Mock] Effect: Set ${effect.target} max ${effect.value} (new value: ${state.inventory[effect.target]})`
|
|
5576
|
+
);
|
|
5577
|
+
break;
|
|
5578
|
+
case "enable_recipe":
|
|
5579
|
+
if (state.disabledRecipes?.includes(effect.target)) {
|
|
5580
|
+
state.disabledRecipes = state.disabledRecipes.filter(
|
|
5581
|
+
(r2) => r2 !== effect.target
|
|
5582
|
+
);
|
|
5583
|
+
console.log(
|
|
5584
|
+
`[Venus Simulation Mock] Effect: Enabled recipe ${effect.target}`
|
|
5585
|
+
);
|
|
5586
|
+
}
|
|
5587
|
+
break;
|
|
5588
|
+
case "disable_recipe":
|
|
5589
|
+
if (!state.disabledRecipes) state.disabledRecipes = [];
|
|
5590
|
+
if (!state.disabledRecipes.includes(effect.target)) {
|
|
5591
|
+
state.disabledRecipes.push(effect.target);
|
|
5592
|
+
console.log(
|
|
5593
|
+
`[Venus Simulation Mock] Effect: Disabled recipe ${effect.target}`
|
|
5594
|
+
);
|
|
5595
|
+
}
|
|
5596
|
+
break;
|
|
5597
|
+
case "trigger_recipe":
|
|
5598
|
+
console.log(
|
|
5599
|
+
`[Venus Simulation Mock] Effect: Trigger recipe ${effect.target} (not implemented)`
|
|
5600
|
+
);
|
|
5601
|
+
break;
|
|
5602
|
+
default:
|
|
5603
|
+
console.warn(
|
|
5604
|
+
`[Venus Simulation Mock] Unknown effect type: ${effect.type}`
|
|
5605
|
+
);
|
|
4809
5606
|
}
|
|
5607
|
+
}
|
|
5608
|
+
}
|
|
5609
|
+
async getConfigAsync() {
|
|
5610
|
+
console.log("[Venus Simulation Mock] getConfigAsync called");
|
|
5611
|
+
const appIdentifier = this.appId;
|
|
5612
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5613
|
+
const config = mockSimulationConfigs.get(appIdentifier) || {
|
|
5614
|
+
version: "1.0",
|
|
5615
|
+
entities: {},
|
|
5616
|
+
recipes: {}
|
|
5617
|
+
};
|
|
5618
|
+
return config;
|
|
5619
|
+
}
|
|
5620
|
+
async getStateAsync(roomId) {
|
|
5621
|
+
this.log("getStateAsync called:", roomId);
|
|
5622
|
+
const appIdentifier = this.appId;
|
|
5623
|
+
const mockSimulationStates = this.mockSimulationStates;
|
|
5624
|
+
let state = mockSimulationStates.get(appIdentifier);
|
|
5625
|
+
if (!state) {
|
|
5626
|
+
state = await this.initializeSimulationState(appIdentifier);
|
|
5627
|
+
}
|
|
5628
|
+
const mockSimulationConfigs = this.mockSimulationConfigs;
|
|
5629
|
+
return {
|
|
5630
|
+
...state,
|
|
5631
|
+
roomId,
|
|
5632
|
+
configuration: mockSimulationConfigs.get(appIdentifier)
|
|
4810
5633
|
};
|
|
4811
5634
|
}
|
|
5635
|
+
async assignItemToSlotAsync(containerId, slotId, itemId) {
|
|
5636
|
+
this.log("assignItemToSlotAsync called:", {
|
|
5637
|
+
containerId,
|
|
5638
|
+
slotId,
|
|
5639
|
+
itemId
|
|
5640
|
+
});
|
|
5641
|
+
return { success: true, message: "Mock assignment successful" };
|
|
5642
|
+
}
|
|
5643
|
+
async removeItemFromSlotAsync(containerId, slotId) {
|
|
5644
|
+
this.log("removeItemFromSlotAsync called:", {
|
|
5645
|
+
containerId,
|
|
5646
|
+
slotId
|
|
5647
|
+
});
|
|
5648
|
+
return { success: true, message: "Mock removal successful" };
|
|
5649
|
+
}
|
|
4812
5650
|
};
|
|
4813
5651
|
|
|
4814
|
-
// src/
|
|
4815
|
-
function
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
5652
|
+
// src/simulation/index.ts
|
|
5653
|
+
function initializeSimulation(venusApi, host) {
|
|
5654
|
+
console.log("[Venus SDK] Initializing new Simulation Api");
|
|
5655
|
+
venusApi.simulation = {
|
|
5656
|
+
isEnabled: () => true
|
|
5657
|
+
};
|
|
5658
|
+
venusApi.simulation.getConfigAsync = () => {
|
|
5659
|
+
return host.simulation.getConfigAsync();
|
|
5660
|
+
};
|
|
5661
|
+
venusApi.simulation.getStateAsync = (options) => {
|
|
5662
|
+
return host.simulation.getStateAsync(options?.roomId);
|
|
5663
|
+
};
|
|
5664
|
+
venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
|
|
5665
|
+
return host.simulation.executeRecipeAsync(recipeId, inputs, options);
|
|
5666
|
+
};
|
|
5667
|
+
venusApi.simulation.getActiveRunsAsync = () => {
|
|
5668
|
+
return host.simulation.getActiveRunsAsync();
|
|
5669
|
+
};
|
|
5670
|
+
venusApi.simulation.collectRecipeAsync = (runId) => {
|
|
5671
|
+
return host.simulation.collectRecipeAsync(runId);
|
|
5672
|
+
};
|
|
5673
|
+
venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, roomId, options) => {
|
|
5674
|
+
return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, {
|
|
5675
|
+
roomId,
|
|
5676
|
+
...options
|
|
5677
|
+
});
|
|
5678
|
+
};
|
|
5679
|
+
venusApi.simulation.triggerRecipeChainAsync = (recipeId, context, roomId) => {
|
|
5680
|
+
return host.simulation.triggerRecipeChainAsync(recipeId, {
|
|
5681
|
+
context,
|
|
5682
|
+
roomId
|
|
5683
|
+
});
|
|
5684
|
+
};
|
|
5685
|
+
venusApi.simulation.getAvailableRecipesAsync = async (roomId, includeActorRecipes) => {
|
|
5686
|
+
const result = await host.simulation.getAvailableRecipesAsync({
|
|
5687
|
+
roomId,
|
|
5688
|
+
includeActorRecipes
|
|
5689
|
+
});
|
|
5690
|
+
return result.recipes;
|
|
5691
|
+
};
|
|
5692
|
+
venusApi.simulation.getRecipeRequirementsAsync = (recipeId, entity, amount) => {
|
|
5693
|
+
return host.simulation.getRecipeRequirementsAsync({
|
|
5694
|
+
recipeId,
|
|
5695
|
+
entity,
|
|
5696
|
+
batchAmount: amount
|
|
5697
|
+
});
|
|
5698
|
+
};
|
|
5699
|
+
venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
|
|
5700
|
+
return host.simulation.getBatchRecipeRequirementsAsync(recipes);
|
|
5701
|
+
};
|
|
5702
|
+
venusApi.simulation.resolveFieldValueAsync = (entityId, fieldPath, entity) => {
|
|
5703
|
+
return host.simulation.resolveFieldValueAsync(entityId, fieldPath, entity);
|
|
5704
|
+
};
|
|
5705
|
+
venusApi.simulation.getEntityMetadataAsync = (entityId) => {
|
|
5706
|
+
return host.simulation.getEntityMetadataAsync(entityId);
|
|
5707
|
+
};
|
|
5708
|
+
venusApi.simulation.getSlotAssignmentsAsync = (containerId) => {
|
|
5709
|
+
return host.simulation.getSlotAssignmentsAsync(containerId);
|
|
5710
|
+
};
|
|
5711
|
+
venusApi.simulation.getSlotContainersAsync = () => {
|
|
5712
|
+
return host.simulation.getSlotContainersAsync();
|
|
5713
|
+
};
|
|
5714
|
+
venusApi.simulation.assignItemToSlotAsync = (containerId, slotId, itemId) => {
|
|
5715
|
+
return host.simulation.assignItemToSlotAsync(containerId, slotId, itemId);
|
|
5716
|
+
};
|
|
5717
|
+
venusApi.simulation.removeItemFromSlotAsync = (containerId, slotId) => {
|
|
5718
|
+
return host.simulation.removeItemFromSlotAsync(containerId, slotId);
|
|
5719
|
+
};
|
|
5720
|
+
venusApi.simulation.getAvailableItemsAsync = (containerId, slotId) => {
|
|
5721
|
+
return host.simulation.getAvailableItemsAsync(containerId, slotId);
|
|
5722
|
+
};
|
|
5723
|
+
venusApi.simulation.calculatePowerPreviewAsync = (containerId, slotId, candidateItemId) => {
|
|
5724
|
+
return host.simulation.calculatePowerPreviewAsync(
|
|
5725
|
+
containerId,
|
|
5726
|
+
slotId,
|
|
5727
|
+
candidateItemId
|
|
4829
5728
|
);
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
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;
|
|
5729
|
+
};
|
|
5730
|
+
venusApi.simulation.executeBatchOperationsAsync = (operations, validateOnly) => {
|
|
5731
|
+
return host.simulation.executeBatchOperationsAsync(operations, validateOnly);
|
|
5732
|
+
};
|
|
5733
|
+
venusApi.simulation.validateSlotAssignmentAsync = (containerId, slotId, itemId) => {
|
|
5734
|
+
return host.simulation.validateSlotAssignmentAsync(
|
|
5735
|
+
containerId,
|
|
5736
|
+
slotId,
|
|
5737
|
+
itemId
|
|
5738
|
+
);
|
|
5739
|
+
};
|
|
5740
|
+
venusApi.simulation.sumContributions = (contributions) => {
|
|
5741
|
+
return host.simulation.sumContributions(contributions);
|
|
5742
|
+
};
|
|
4853
5743
|
}
|
|
4854
5744
|
|
|
5745
|
+
// src/MockHost.ts
|
|
5746
|
+
init_rooms();
|
|
5747
|
+
|
|
4855
5748
|
// src/logging/MockLoggingApi.ts
|
|
4856
5749
|
var MockLoggingApi = class {
|
|
4857
5750
|
logDebug(message, ...args) {
|
|
@@ -4931,6 +5824,174 @@ function initializeLoggingApi(venusApi, host) {
|
|
|
4931
5824
|
var BurgerTimeAssetsCdnPath = "burger-time/Core.stow";
|
|
4932
5825
|
var CharacterAssetsCdnPath = "burger-time/Character.stow";
|
|
4933
5826
|
|
|
5827
|
+
// src/shared-assets/embeddedLibrariesManifest.ts
|
|
5828
|
+
var EMBEDDED_LIBRARIES = [
|
|
5829
|
+
{
|
|
5830
|
+
libraryKey: "phaser@3.90.0",
|
|
5831
|
+
assetKey: "library:phaser@3.90.0",
|
|
5832
|
+
packageName: "phaser",
|
|
5833
|
+
version: "3.90.0",
|
|
5834
|
+
globalVar: "Phaser",
|
|
5835
|
+
cdnPath: "phaser/3.90.0/phaser.min.js",
|
|
5836
|
+
moduleSpecifiers: [{ match: "exact", value: "phaser" }],
|
|
5837
|
+
loadStage: 0,
|
|
5838
|
+
enabled: true
|
|
5839
|
+
},
|
|
5840
|
+
{
|
|
5841
|
+
libraryKey: "react@18.3.1",
|
|
5842
|
+
assetKey: "library:react@18.3.1",
|
|
5843
|
+
packageName: "react",
|
|
5844
|
+
version: "18.3.1",
|
|
5845
|
+
globalVar: "React",
|
|
5846
|
+
cdnPath: "react/18.3.1/react.production.min.js",
|
|
5847
|
+
moduleSpecifiers: [
|
|
5848
|
+
{ match: "exact", value: "react", behavior: "namespace" },
|
|
5849
|
+
{ match: "exact", value: "react/jsx-runtime", behavior: "react-jsx-runtime" },
|
|
5850
|
+
{
|
|
5851
|
+
match: "exact",
|
|
5852
|
+
value: "react/jsx-dev-runtime",
|
|
5853
|
+
behavior: "react-jsx-dev-runtime"
|
|
5854
|
+
}
|
|
5855
|
+
],
|
|
5856
|
+
loadStage: 0,
|
|
5857
|
+
// Must load before ReactDOM
|
|
5858
|
+
enabled: true
|
|
5859
|
+
},
|
|
5860
|
+
{
|
|
5861
|
+
libraryKey: "react-dom@18.3.1",
|
|
5862
|
+
assetKey: "library:react-dom@18.3.1",
|
|
5863
|
+
packageName: "react-dom",
|
|
5864
|
+
version: "18.3.1",
|
|
5865
|
+
globalVar: "ReactDOM",
|
|
5866
|
+
cdnPath: "react-dom/18.3.1/react-dom.production.min.js",
|
|
5867
|
+
moduleSpecifiers: [
|
|
5868
|
+
{ match: "exact", value: "react-dom", behavior: "namespace" },
|
|
5869
|
+
{ match: "exact", value: "react-dom/client", behavior: "namespace" }
|
|
5870
|
+
],
|
|
5871
|
+
loadStage: 1,
|
|
5872
|
+
// Depends on React (stage 0)
|
|
5873
|
+
enabled: true
|
|
5874
|
+
},
|
|
5875
|
+
{
|
|
5876
|
+
libraryKey: "three@0.170.0",
|
|
5877
|
+
assetKey: "library:three@0.170.0",
|
|
5878
|
+
packageName: "three",
|
|
5879
|
+
version: "0.170.0",
|
|
5880
|
+
globalVar: "THREE",
|
|
5881
|
+
cdnPath: "three/r170/three.min.js",
|
|
5882
|
+
moduleSpecifiers: [
|
|
5883
|
+
{ match: "exact", value: "three", behavior: "namespace" },
|
|
5884
|
+
{ match: "prefix", value: "three/examples/jsm/", behavior: "namespace" }
|
|
5885
|
+
],
|
|
5886
|
+
loadStage: 0,
|
|
5887
|
+
enabled: true
|
|
5888
|
+
},
|
|
5889
|
+
{
|
|
5890
|
+
libraryKey: "matter-js@0.19.0",
|
|
5891
|
+
assetKey: "library:matter-js@0.19.0",
|
|
5892
|
+
packageName: "matter-js",
|
|
5893
|
+
version: "0.19.0",
|
|
5894
|
+
globalVar: "Matter",
|
|
5895
|
+
cdnPath: "matter-js/0.19.0/matter.min.js",
|
|
5896
|
+
moduleSpecifiers: [{ match: "exact", value: "matter-js" }],
|
|
5897
|
+
loadStage: 0,
|
|
5898
|
+
enabled: true
|
|
5899
|
+
},
|
|
5900
|
+
{
|
|
5901
|
+
libraryKey: "inkjs@2.2.0",
|
|
5902
|
+
assetKey: "library:inkjs@2.2.0",
|
|
5903
|
+
packageName: "inkjs",
|
|
5904
|
+
version: "2.2.0",
|
|
5905
|
+
globalVar: "inkjs",
|
|
5906
|
+
cdnPath: "inkjs/2.2.0/ink.min.js",
|
|
5907
|
+
moduleSpecifiers: [{ match: "exact", value: "inkjs" }],
|
|
5908
|
+
loadStage: 0,
|
|
5909
|
+
enabled: true
|
|
5910
|
+
},
|
|
5911
|
+
{
|
|
5912
|
+
libraryKey: "zustand@5.0.3",
|
|
5913
|
+
assetKey: "library:zustand@5.0.3",
|
|
5914
|
+
packageName: "zustand",
|
|
5915
|
+
version: "5.0.3",
|
|
5916
|
+
globalVar: "zustand",
|
|
5917
|
+
cdnPath: "zustand/5.0.3/zustand.min.js",
|
|
5918
|
+
moduleSpecifiers: [
|
|
5919
|
+
{ match: "exact", value: "zustand" },
|
|
5920
|
+
{ match: "exact", value: "zustand/middleware" }
|
|
5921
|
+
],
|
|
5922
|
+
loadStage: 0,
|
|
5923
|
+
enabled: true
|
|
5924
|
+
},
|
|
5925
|
+
{
|
|
5926
|
+
libraryKey: "ammo.js@2024.11",
|
|
5927
|
+
assetKey: "library:ammo.js@2024.11",
|
|
5928
|
+
packageName: "ammo.js",
|
|
5929
|
+
version: "2024.11",
|
|
5930
|
+
globalVar: "Ammo",
|
|
5931
|
+
cdnPath: "ammo/2024.11/ammo.js",
|
|
5932
|
+
moduleSpecifiers: [
|
|
5933
|
+
{ match: "exact", value: "ammo.js" },
|
|
5934
|
+
{ match: "exact", value: "ammo.js/builds/ammo.wasm.js" }
|
|
5935
|
+
],
|
|
5936
|
+
loadStage: 0,
|
|
5937
|
+
enabled: false
|
|
5938
|
+
// Not ready yet - WASM loading needs additional work
|
|
5939
|
+
}
|
|
5940
|
+
];
|
|
5941
|
+
var EMBEDDED_LIBRARY_BY_KEY = EMBEDDED_LIBRARIES.reduce(
|
|
5942
|
+
(acc, lib) => {
|
|
5943
|
+
acc[lib.libraryKey] = lib;
|
|
5944
|
+
return acc;
|
|
5945
|
+
},
|
|
5946
|
+
{}
|
|
5947
|
+
);
|
|
5948
|
+
EMBEDDED_LIBRARIES.filter(
|
|
5949
|
+
(lib) => lib.enabled
|
|
5950
|
+
).flatMap(
|
|
5951
|
+
(lib) => lib.moduleSpecifiers.map((specifier) => ({
|
|
5952
|
+
...specifier,
|
|
5953
|
+
libraryKey: lib.libraryKey
|
|
5954
|
+
}))
|
|
5955
|
+
);
|
|
5956
|
+
function getLibraryDefinition(libraryKey) {
|
|
5957
|
+
const definition = EMBEDDED_LIBRARY_BY_KEY[libraryKey];
|
|
5958
|
+
if (!definition) {
|
|
5959
|
+
const availableKeys = Object.keys(EMBEDDED_LIBRARY_BY_KEY).join(", ");
|
|
5960
|
+
throw new Error(
|
|
5961
|
+
`Unsupported embedded library: ${libraryKey}. Available libraries: ${availableKeys}`
|
|
5962
|
+
);
|
|
5963
|
+
}
|
|
5964
|
+
return definition;
|
|
5965
|
+
}
|
|
5966
|
+
|
|
5967
|
+
// src/shared-assets/base64Utils.ts
|
|
5968
|
+
function base64ToArrayBuffer(base64) {
|
|
5969
|
+
const binaryString = atob(base64);
|
|
5970
|
+
const len = binaryString.length;
|
|
5971
|
+
const bytes = new Uint8Array(len);
|
|
5972
|
+
for (let i = 0; i < len; i++) {
|
|
5973
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
5974
|
+
}
|
|
5975
|
+
return bytes.buffer;
|
|
5976
|
+
}
|
|
5977
|
+
function base64ToUtf8(base64) {
|
|
5978
|
+
if (typeof TextDecoder !== "undefined") {
|
|
5979
|
+
const decoder = new TextDecoder("utf-8");
|
|
5980
|
+
const buffer = base64ToArrayBuffer(base64);
|
|
5981
|
+
return decoder.decode(new Uint8Array(buffer));
|
|
5982
|
+
}
|
|
5983
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.Buffer !== "undefined") {
|
|
5984
|
+
const BufferCtor = globalThis.Buffer;
|
|
5985
|
+
return BufferCtor.from(base64, "base64").toString("utf-8");
|
|
5986
|
+
}
|
|
5987
|
+
const binaryString = atob(base64);
|
|
5988
|
+
let result = "";
|
|
5989
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
5990
|
+
result += String.fromCharCode(binaryString.charCodeAt(i));
|
|
5991
|
+
}
|
|
5992
|
+
return decodeURIComponent(escape(result));
|
|
5993
|
+
}
|
|
5994
|
+
|
|
4934
5995
|
// src/shared-assets/RpcSharedAssetsApi.ts
|
|
4935
5996
|
var RpcSharedAssetsApi = class {
|
|
4936
5997
|
constructor(rpcClient, venusApi) {
|
|
@@ -4969,16 +6030,33 @@ var RpcSharedAssetsApi = class {
|
|
|
4969
6030
|
}
|
|
4970
6031
|
}
|
|
4971
6032
|
}
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
6033
|
+
async loadLibraryCode(libraryKey) {
|
|
6034
|
+
const definition = getLibraryDefinition(libraryKey);
|
|
6035
|
+
try {
|
|
6036
|
+
const response = await this.rpcClient.callT("H5_LOAD_EMBEDDED_ASSET" /* H5_LOAD_EMBEDDED_ASSET */, {
|
|
6037
|
+
assetKey: definition.assetKey
|
|
6038
|
+
});
|
|
6039
|
+
return base64ToUtf8(response.base64Data);
|
|
6040
|
+
} catch (err) {
|
|
6041
|
+
console.error(
|
|
6042
|
+
`[Venus Libraries] Failed to load ${libraryKey} from host via RPC:`,
|
|
6043
|
+
err
|
|
6044
|
+
);
|
|
6045
|
+
console.warn(
|
|
6046
|
+
`[Venus Libraries] Falling back to CDN for ${libraryKey}. This may indicate an asset packaging issue.`
|
|
6047
|
+
);
|
|
6048
|
+
try {
|
|
6049
|
+
const cdnUrl = this.venusApi.cdn.resolveSharedLibUrl(definition.cdnPath);
|
|
6050
|
+
const response = await this.venusApi.cdn.fetchFromCdn(cdnUrl);
|
|
6051
|
+
return await response.text();
|
|
6052
|
+
} catch (cdnError) {
|
|
6053
|
+
throw new Error(
|
|
6054
|
+
`Failed to load embedded library ${libraryKey}: RPC failed, CDN fallback failed: ${cdnError.message}`
|
|
6055
|
+
);
|
|
6056
|
+
}
|
|
6057
|
+
}
|
|
4979
6058
|
}
|
|
4980
|
-
|
|
4981
|
-
}
|
|
6059
|
+
};
|
|
4982
6060
|
|
|
4983
6061
|
// src/shared-assets/MockSharedAssetsApi.ts
|
|
4984
6062
|
var MockSharedAssetsApi = class {
|
|
@@ -4994,6 +6072,12 @@ var MockSharedAssetsApi = class {
|
|
|
4994
6072
|
const blob = await this.venusApi.cdn.fetchBlob(CharacterAssetsCdnPath);
|
|
4995
6073
|
return await blob.arrayBuffer();
|
|
4996
6074
|
}
|
|
6075
|
+
async loadLibraryCode(libraryKey) {
|
|
6076
|
+
const definition = getLibraryDefinition(libraryKey);
|
|
6077
|
+
const url = this.venusApi.cdn.resolveSharedLibUrl(definition.cdnPath);
|
|
6078
|
+
const response = await this.venusApi.cdn.fetchFromCdn(url);
|
|
6079
|
+
return await response.text();
|
|
6080
|
+
}
|
|
4997
6081
|
};
|
|
4998
6082
|
|
|
4999
6083
|
// src/game-preloader/MockPreloaderApi.ts
|
|
@@ -5073,116 +6157,44 @@ var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when ru
|
|
|
5073
6157
|
function createUnavailableRoomsApi() {
|
|
5074
6158
|
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
5075
6159
|
return {
|
|
5076
|
-
async
|
|
6160
|
+
async createRoom() {
|
|
5077
6161
|
throw roomsUnavailableError();
|
|
5078
6162
|
},
|
|
5079
|
-
async
|
|
6163
|
+
async joinOrCreateRoom() {
|
|
5080
6164
|
throw roomsUnavailableError();
|
|
5081
6165
|
},
|
|
5082
|
-
async
|
|
6166
|
+
async getUserRooms() {
|
|
5083
6167
|
throw roomsUnavailableError();
|
|
5084
6168
|
},
|
|
5085
|
-
async
|
|
6169
|
+
async joinRoomByCode() {
|
|
5086
6170
|
throw roomsUnavailableError();
|
|
5087
6171
|
},
|
|
5088
|
-
|
|
6172
|
+
subscribe() {
|
|
5089
6173
|
throw roomsUnavailableError();
|
|
5090
6174
|
},
|
|
5091
|
-
async
|
|
6175
|
+
async updateData() {
|
|
5092
6176
|
throw roomsUnavailableError();
|
|
5093
6177
|
},
|
|
5094
|
-
async
|
|
6178
|
+
async getData() {
|
|
5095
6179
|
throw roomsUnavailableError();
|
|
5096
6180
|
},
|
|
5097
|
-
async
|
|
6181
|
+
async sendMessage() {
|
|
5098
6182
|
throw roomsUnavailableError();
|
|
5099
6183
|
},
|
|
5100
|
-
async
|
|
6184
|
+
async leave() {
|
|
5101
6185
|
throw roomsUnavailableError();
|
|
5102
6186
|
},
|
|
5103
|
-
async
|
|
6187
|
+
async startGame() {
|
|
5104
6188
|
throw roomsUnavailableError();
|
|
5105
6189
|
},
|
|
5106
|
-
async
|
|
6190
|
+
async proposeMove() {
|
|
5107
6191
|
throw roomsUnavailableError();
|
|
5108
6192
|
},
|
|
5109
|
-
async
|
|
6193
|
+
async validateMove() {
|
|
5110
6194
|
throw roomsUnavailableError();
|
|
5111
6195
|
}
|
|
5112
6196
|
};
|
|
5113
6197
|
}
|
|
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
|
-
}
|
|
5186
6198
|
var MockHost = class {
|
|
5187
6199
|
constructor(venusApi) {
|
|
5188
6200
|
__publicField(this, "ads");
|
|
@@ -5237,7 +6249,7 @@ var MockHost = class {
|
|
|
5237
6249
|
this.haptics = new MockHapticsApi(venusApi);
|
|
5238
6250
|
this.features = new MockFeaturesApi();
|
|
5239
6251
|
this.lifecycle = this._mockLifecyclesApi;
|
|
5240
|
-
this.simulation =
|
|
6252
|
+
this.simulation = new MockSimulationApi();
|
|
5241
6253
|
this.rooms = createUnavailableRoomsApi();
|
|
5242
6254
|
this.logging = new MockLoggingApi();
|
|
5243
6255
|
this.iap = new MockIapApi();
|
|
@@ -5729,11 +6741,6 @@ var MockHost = class {
|
|
|
5729
6741
|
}
|
|
5730
6742
|
};
|
|
5731
6743
|
|
|
5732
|
-
// src/utils/idGenerator.ts
|
|
5733
|
-
function generateId() {
|
|
5734
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
5735
|
-
}
|
|
5736
|
-
|
|
5737
6744
|
// src/rpc/RpcClient.ts
|
|
5738
6745
|
var RpcClient = class {
|
|
5739
6746
|
constructor() {
|
|
@@ -5776,7 +6783,7 @@ var RpcClient = class {
|
|
|
5776
6783
|
}
|
|
5777
6784
|
async call(method, args, timeout = 5e3) {
|
|
5778
6785
|
return new Promise((resolve, reject) => {
|
|
5779
|
-
const id = generateId();
|
|
6786
|
+
const id = this.generateId();
|
|
5780
6787
|
this.addPendingCall(id, resolve, reject);
|
|
5781
6788
|
const request = {
|
|
5782
6789
|
type: "rpc-request",
|
|
@@ -5813,6 +6820,9 @@ var RpcClient = class {
|
|
|
5813
6820
|
getPendingCall(id) {
|
|
5814
6821
|
return this.pendingCalls.get(id);
|
|
5815
6822
|
}
|
|
6823
|
+
generateId() {
|
|
6824
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
6825
|
+
}
|
|
5816
6826
|
handleRpcResponse(response) {
|
|
5817
6827
|
const pending = this.getPendingCall(response.id);
|
|
5818
6828
|
if (!pending) {
|
|
@@ -5875,16 +6885,6 @@ var VenusTransport = class {
|
|
|
5875
6885
|
this.isProcessingMessage = false;
|
|
5876
6886
|
return;
|
|
5877
6887
|
}
|
|
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
|
-
}
|
|
5888
6888
|
const requestId = messageData.requestId;
|
|
5889
6889
|
if (!requestId) {
|
|
5890
6890
|
this.logWarn("No requestId. Ignoring message...");
|
|
@@ -6051,361 +7051,294 @@ var VenusTransport = class {
|
|
|
6051
7051
|
}
|
|
6052
7052
|
};
|
|
6053
7053
|
|
|
6054
|
-
// src/
|
|
6055
|
-
|
|
7054
|
+
// src/RemoteHost.ts
|
|
7055
|
+
init_rooms();
|
|
7056
|
+
|
|
7057
|
+
// src/rooms/RpcRoomsApi.ts
|
|
7058
|
+
init_VenusRoom();
|
|
7059
|
+
var RpcRoomsApi = class {
|
|
6056
7060
|
constructor(rpcClient) {
|
|
6057
7061
|
__publicField(this, "rpcClient");
|
|
6058
|
-
__publicField(this, "
|
|
6059
|
-
__publicField(this, "
|
|
7062
|
+
__publicField(this, "subscriptions");
|
|
7063
|
+
__publicField(this, "transportSubscription", null);
|
|
6060
7064
|
this.rpcClient = rpcClient;
|
|
6061
|
-
this.
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
isEnabled() {
|
|
6067
|
-
return true;
|
|
6068
|
-
}
|
|
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
|
-
}
|
|
6077
|
-
);
|
|
6078
|
-
}
|
|
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;
|
|
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
|
-
});
|
|
7065
|
+
this.subscriptions = {
|
|
7066
|
+
data: {},
|
|
7067
|
+
messages: {},
|
|
7068
|
+
gameEvents: {},
|
|
7069
|
+
allEvents: {}
|
|
6110
7070
|
};
|
|
6111
7071
|
}
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
validateOnly
|
|
6118
|
-
}
|
|
6119
|
-
);
|
|
6120
|
-
}
|
|
6121
|
-
async getAvailableItemsAsync(containerId, slotId) {
|
|
6122
|
-
const response = await this.rpcClient.call(
|
|
6123
|
-
"H5_SIMULATION_GET_AVAILABLE_ITEMS" /* H5_SIMULATION_GET_AVAILABLE_ITEMS */,
|
|
6124
|
-
{
|
|
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
|
|
6157
|
-
}
|
|
6158
|
-
);
|
|
6159
|
-
}
|
|
6160
|
-
async getSlotContainersAsync() {
|
|
6161
|
-
const response = await this.rpcClient.call(
|
|
6162
|
-
"H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
|
|
6163
|
-
{}
|
|
6164
|
-
);
|
|
6165
|
-
return response.containers || [];
|
|
7072
|
+
/**
|
|
7073
|
+
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
7074
|
+
*/
|
|
7075
|
+
getSubscriptions() {
|
|
7076
|
+
return this.subscriptions;
|
|
6166
7077
|
}
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
7078
|
+
/**
|
|
7079
|
+
* Set up room notification routing from the transport
|
|
7080
|
+
*/
|
|
7081
|
+
setupNotifications(transport) {
|
|
7082
|
+
const { setupRoomNotifications: setupRoomNotifications2 } = (init_rooms(), __toCommonJS(rooms_exports));
|
|
7083
|
+
this.transportSubscription = setupRoomNotifications2(
|
|
7084
|
+
transport,
|
|
7085
|
+
() => this.getSubscriptions()
|
|
6173
7086
|
);
|
|
6174
|
-
return Array.isArray(response) ? response : response.assignments || [];
|
|
6175
7087
|
}
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
this._simulationConfig = response.configuration;
|
|
7088
|
+
/**
|
|
7089
|
+
* Clean up subscriptions and resources
|
|
7090
|
+
*/
|
|
7091
|
+
dispose() {
|
|
7092
|
+
if (this.transportSubscription) {
|
|
7093
|
+
this.transportSubscription.unsubscribe();
|
|
7094
|
+
this.transportSubscription = null;
|
|
7095
|
+
console.log("[Venus Rooms] Cleaned up room notification subscription");
|
|
6185
7096
|
}
|
|
6186
|
-
return response;
|
|
6187
7097
|
}
|
|
6188
|
-
async
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
}
|
|
6192
|
-
const config = await this.rpcClient.call(
|
|
6193
|
-
"H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
|
|
7098
|
+
async createRoom(options) {
|
|
7099
|
+
const response = await this.rpcClient.call(
|
|
7100
|
+
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
6194
7101
|
{
|
|
6195
|
-
|
|
7102
|
+
options
|
|
6196
7103
|
}
|
|
6197
7104
|
);
|
|
6198
|
-
if (
|
|
6199
|
-
|
|
6200
|
-
return config;
|
|
7105
|
+
if (response.success === false) {
|
|
7106
|
+
throw new Error(response.error || "Failed to create room");
|
|
6201
7107
|
}
|
|
6202
|
-
|
|
7108
|
+
const roomData = response.roomData || response;
|
|
7109
|
+
const room = new VenusRoom(roomData);
|
|
7110
|
+
return room;
|
|
6203
7111
|
}
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
"
|
|
7112
|
+
async joinOrCreateRoom(options) {
|
|
7113
|
+
const response = await this.rpcClient.call(
|
|
7114
|
+
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
6207
7115
|
{
|
|
6208
|
-
|
|
6209
|
-
inputs,
|
|
6210
|
-
roomId: options?.roomId,
|
|
6211
|
-
batchAmount: options?.batchAmount,
|
|
6212
|
-
allowPartialBatch: options?.allowPartialBatch,
|
|
6213
|
-
entity: options?.entity
|
|
7116
|
+
options
|
|
6214
7117
|
}
|
|
6215
7118
|
);
|
|
7119
|
+
if (response.success === false) {
|
|
7120
|
+
throw new Error(response.error || "Failed to join or create room");
|
|
7121
|
+
}
|
|
7122
|
+
const data = response.value || response;
|
|
7123
|
+
const room = new VenusRoom(data.roomData);
|
|
7124
|
+
return {
|
|
7125
|
+
action: data.action,
|
|
7126
|
+
room,
|
|
7127
|
+
playersJoined: data.playersJoined
|
|
7128
|
+
};
|
|
6216
7129
|
}
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
});
|
|
6221
|
-
}
|
|
6222
|
-
getActiveRunsAsync(options) {
|
|
6223
|
-
return this.rpcClient.call(
|
|
6224
|
-
"H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
|
|
7130
|
+
async joinRoomByCode(roomCode) {
|
|
7131
|
+
const response = await this.rpcClient.call(
|
|
7132
|
+
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
6225
7133
|
{
|
|
6226
|
-
|
|
7134
|
+
roomCode
|
|
6227
7135
|
}
|
|
6228
7136
|
);
|
|
7137
|
+
if (response?.success === false) {
|
|
7138
|
+
throw new Error(response.error || "Failed to join room by code");
|
|
7139
|
+
}
|
|
7140
|
+
const roomData = response.roomData || response;
|
|
7141
|
+
const room = new VenusRoom(roomData);
|
|
7142
|
+
return room;
|
|
6229
7143
|
}
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
7144
|
+
// Get user's rooms with optional filtering
|
|
7145
|
+
async getUserRooms(includeArchived = false) {
|
|
7146
|
+
const response = await this.rpcClient.call(
|
|
7147
|
+
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
6233
7148
|
{
|
|
6234
|
-
|
|
6235
|
-
entity,
|
|
6236
|
-
inputs,
|
|
6237
|
-
roomId: options?.roomId ?? null,
|
|
6238
|
-
options
|
|
7149
|
+
includeArchived
|
|
6239
7150
|
}
|
|
6240
7151
|
);
|
|
7152
|
+
if (response?.success === false) {
|
|
7153
|
+
throw new Error(response.error || "Failed to get user rooms");
|
|
7154
|
+
}
|
|
7155
|
+
const rawRooms = response.rooms || [];
|
|
7156
|
+
const venusRooms = [];
|
|
7157
|
+
for (const roomData of rawRooms) {
|
|
7158
|
+
if (!roomData.id) {
|
|
7159
|
+
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
7160
|
+
continue;
|
|
7161
|
+
}
|
|
7162
|
+
try {
|
|
7163
|
+
const venusRoom = new VenusRoom(roomData);
|
|
7164
|
+
venusRooms.push(venusRoom);
|
|
7165
|
+
} catch (error) {
|
|
7166
|
+
console.warn(
|
|
7167
|
+
"getUserRooms: Failed to create VenusRoom object:",
|
|
7168
|
+
error,
|
|
7169
|
+
roomData
|
|
7170
|
+
);
|
|
7171
|
+
}
|
|
7172
|
+
}
|
|
7173
|
+
return venusRooms;
|
|
6241
7174
|
}
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
"
|
|
7175
|
+
async updateData(room, updates, merge = true) {
|
|
7176
|
+
const response = await this.rpcClient.call(
|
|
7177
|
+
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
6245
7178
|
{
|
|
6246
|
-
roomId:
|
|
6247
|
-
|
|
7179
|
+
roomId: room.id,
|
|
7180
|
+
updates,
|
|
7181
|
+
merge
|
|
6248
7182
|
}
|
|
6249
7183
|
);
|
|
7184
|
+
if (response?.success === false) {
|
|
7185
|
+
throw new Error(response.error || "Failed to update room data");
|
|
7186
|
+
}
|
|
7187
|
+
return response.data;
|
|
6250
7188
|
}
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
"
|
|
7189
|
+
async getData(room) {
|
|
7190
|
+
const response = await this.rpcClient.call(
|
|
7191
|
+
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
6254
7192
|
{
|
|
6255
|
-
|
|
6256
|
-
entity: recipe.entity,
|
|
6257
|
-
batchAmount: recipe.batchAmount
|
|
7193
|
+
roomId: room.id
|
|
6258
7194
|
}
|
|
6259
7195
|
);
|
|
7196
|
+
if (response?.success === false) {
|
|
7197
|
+
throw new Error(response.error || "Failed to get room data");
|
|
7198
|
+
}
|
|
7199
|
+
return response.data;
|
|
6260
7200
|
}
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
"
|
|
7201
|
+
async sendMessage(venusRoom, messageData) {
|
|
7202
|
+
const response = await this.rpcClient.call(
|
|
7203
|
+
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
6264
7204
|
{
|
|
6265
|
-
|
|
7205
|
+
roomId: venusRoom.id,
|
|
7206
|
+
message: messageData
|
|
6266
7207
|
}
|
|
6267
7208
|
);
|
|
7209
|
+
if (response?.success === false) {
|
|
7210
|
+
throw new Error(response.error || "Failed to send message");
|
|
7211
|
+
}
|
|
7212
|
+
return response.messageId;
|
|
6268
7213
|
}
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
"
|
|
7214
|
+
async leave(room) {
|
|
7215
|
+
const response = await this.rpcClient.call(
|
|
7216
|
+
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
6272
7217
|
{
|
|
6273
|
-
|
|
6274
|
-
context: options?.context,
|
|
6275
|
-
roomId: options?.roomId
|
|
7218
|
+
roomId: room.id
|
|
6276
7219
|
}
|
|
6277
7220
|
);
|
|
7221
|
+
if (response?.success === false) {
|
|
7222
|
+
throw new Error(response.error || "Failed to leave room");
|
|
7223
|
+
}
|
|
7224
|
+
return response;
|
|
6278
7225
|
}
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
"
|
|
7226
|
+
async startGame(room, gameConfig = {}, turnOrder = null) {
|
|
7227
|
+
const response = await this.rpcClient.call(
|
|
7228
|
+
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
6282
7229
|
{
|
|
6283
|
-
|
|
7230
|
+
roomId: room.id,
|
|
7231
|
+
gameConfig,
|
|
7232
|
+
turnOrder
|
|
6284
7233
|
}
|
|
6285
7234
|
);
|
|
7235
|
+
if (response?.success === false) {
|
|
7236
|
+
throw new Error(response.error || "Failed to start game");
|
|
7237
|
+
}
|
|
7238
|
+
return response.data;
|
|
6286
7239
|
}
|
|
6287
|
-
async
|
|
7240
|
+
async proposeMove(room, proposalPayload) {
|
|
6288
7241
|
const response = await this.rpcClient.call(
|
|
6289
|
-
"
|
|
7242
|
+
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
6290
7243
|
{
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
7244
|
+
roomId: room.id,
|
|
7245
|
+
gameSpecificState: proposalPayload.gameSpecificState,
|
|
7246
|
+
moveType: proposalPayload.moveType,
|
|
7247
|
+
clientContext: proposalPayload.clientContext,
|
|
7248
|
+
clientProposalId: proposalPayload.clientProposalId
|
|
6294
7249
|
}
|
|
6295
7250
|
);
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
handleSimulationUpdate(notification) {
|
|
6299
|
-
if (!notification || !notification.subscriptionId) {
|
|
6300
|
-
console.warn("[Venus SDK] Received malformed simulation update");
|
|
6301
|
-
return;
|
|
6302
|
-
}
|
|
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;
|
|
7251
|
+
if (response?.success === false) {
|
|
7252
|
+
throw new Error(response.error || "Failed to propose move");
|
|
6310
7253
|
}
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
7254
|
+
return response.data;
|
|
7255
|
+
}
|
|
7256
|
+
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
7257
|
+
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
7258
|
+
return { success: true, moveId, isValid, reason };
|
|
7259
|
+
}
|
|
7260
|
+
async roomSubscribeToGameEvents(room, callback) {
|
|
7261
|
+
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
7262
|
+
if (!this.subscriptions.gameEvents[room.id]) {
|
|
7263
|
+
this.subscriptions.gameEvents[room.id] = [];
|
|
6315
7264
|
}
|
|
7265
|
+
this.subscriptions.gameEvents[room.id].push(callback);
|
|
6316
7266
|
}
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
7267
|
+
subscribe(room, options = {}) {
|
|
7268
|
+
const subscriptionIds = [];
|
|
7269
|
+
const roomId = room.id;
|
|
7270
|
+
if (options.onData) {
|
|
7271
|
+
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
7272
|
+
if (!this.subscriptions.data[roomId]) {
|
|
7273
|
+
this.subscriptions.data[roomId] = [];
|
|
7274
|
+
}
|
|
7275
|
+
this.subscriptions.data[roomId].push(options.onData);
|
|
7276
|
+
subscriptionIds.push({
|
|
7277
|
+
type: "data",
|
|
7278
|
+
id: dataSubId,
|
|
7279
|
+
callback: options.onData
|
|
7280
|
+
});
|
|
7281
|
+
}
|
|
7282
|
+
if (options.onMessages) {
|
|
7283
|
+
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
7284
|
+
if (!this.subscriptions.messages[roomId]) {
|
|
7285
|
+
this.subscriptions.messages[roomId] = [];
|
|
7286
|
+
}
|
|
7287
|
+
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
7288
|
+
subscriptionIds.push({
|
|
7289
|
+
type: "messages",
|
|
7290
|
+
id: msgSubId,
|
|
7291
|
+
callback: options.onMessages
|
|
7292
|
+
});
|
|
6320
7293
|
}
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
7294
|
+
if (options.onMoves || options.onGameEvents) {
|
|
7295
|
+
const handler = options.onMoves || options.onGameEvents;
|
|
7296
|
+
if (handler) {
|
|
7297
|
+
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
7298
|
+
if (!this.subscriptions.gameEvents[roomId]) {
|
|
7299
|
+
this.subscriptions.gameEvents[roomId] = [];
|
|
7300
|
+
}
|
|
7301
|
+
this.subscriptions.gameEvents[roomId].push(handler);
|
|
7302
|
+
subscriptionIds.push({
|
|
7303
|
+
type: "gameEvents",
|
|
7304
|
+
id: gameSubId,
|
|
7305
|
+
callback: handler
|
|
7306
|
+
});
|
|
7307
|
+
}
|
|
6324
7308
|
}
|
|
6325
|
-
const
|
|
6326
|
-
if (
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
7309
|
+
const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
|
|
7310
|
+
if (needsSubscription) {
|
|
7311
|
+
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
7312
|
+
roomId,
|
|
7313
|
+
subscribeToData: !!options.onData,
|
|
7314
|
+
subscribeToMessages: !!options.onMessages,
|
|
7315
|
+
subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
|
|
7316
|
+
}).catch((error) => {
|
|
7317
|
+
console.error("Failed to set up room subscription:", error);
|
|
7318
|
+
});
|
|
6330
7319
|
}
|
|
7320
|
+
let called = false;
|
|
7321
|
+
return () => {
|
|
7322
|
+
if (called) return;
|
|
7323
|
+
called = true;
|
|
7324
|
+
subscriptionIds.forEach((sub) => {
|
|
7325
|
+
const bucket = this.subscriptions[sub.type];
|
|
7326
|
+
const callbacks = bucket && bucket[roomId] || [];
|
|
7327
|
+
const index = callbacks.indexOf(sub.callback);
|
|
7328
|
+
if (index > -1) callbacks.splice(index, 1);
|
|
7329
|
+
});
|
|
7330
|
+
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
7331
|
+
if (hasNoCallbacks) {
|
|
7332
|
+
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
7333
|
+
roomId
|
|
7334
|
+
}).catch((error) => {
|
|
7335
|
+
console.error("Failed to clean up room subscription:", error);
|
|
7336
|
+
});
|
|
7337
|
+
}
|
|
7338
|
+
};
|
|
6331
7339
|
}
|
|
6332
7340
|
};
|
|
6333
7341
|
|
|
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
|
-
|
|
6409
7342
|
// src/social/RpcSocialApi.ts
|
|
6410
7343
|
var RpcSocialApi = class {
|
|
6411
7344
|
constructor(rpcClient) {
|
|
@@ -6526,6 +7459,7 @@ var RemoteHost = class {
|
|
|
6526
7459
|
venusApi.isMock = () => false;
|
|
6527
7460
|
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
6528
7461
|
initializeRoomsApi(this.venusApi, this);
|
|
7462
|
+
console.log("[Venus SDK] Remote host created");
|
|
6529
7463
|
}
|
|
6530
7464
|
get isInitialized() {
|
|
6531
7465
|
return this._isInitialized;
|
|
@@ -6584,14 +7518,19 @@ var RemoteHost = class {
|
|
|
6584
7518
|
// src/Host.ts
|
|
6585
7519
|
function createHost(venusApi, isMock) {
|
|
6586
7520
|
if (isMock) {
|
|
7521
|
+
console.log("[Venus SDK] Creating Local Host");
|
|
6587
7522
|
return new MockHost(venusApi);
|
|
6588
7523
|
} else {
|
|
7524
|
+
console.log("[Venus SDK] Creating Remote Host");
|
|
6589
7525
|
return new RemoteHost(venusApi);
|
|
6590
7526
|
}
|
|
6591
7527
|
}
|
|
6592
7528
|
|
|
7529
|
+
// src/venus-api/index.js
|
|
7530
|
+
init_rooms();
|
|
7531
|
+
|
|
6593
7532
|
// src/version.ts
|
|
6594
|
-
var SDK_VERSION = "3.0.
|
|
7533
|
+
var SDK_VERSION = "3.1.0-beta.0";
|
|
6595
7534
|
|
|
6596
7535
|
// src/social/index.ts
|
|
6597
7536
|
function initializeSocial(venusApi, host) {
|
|
@@ -6652,6 +7591,67 @@ var VenusAPI2 = class {
|
|
|
6652
7591
|
height: 60
|
|
6653
7592
|
}
|
|
6654
7593
|
},
|
|
7594
|
+
// Complete theme structure (matching createH5Theme output)
|
|
7595
|
+
theme: {
|
|
7596
|
+
background: {
|
|
7597
|
+
default: "#131419",
|
|
7598
|
+
muted: "#1b1d25",
|
|
7599
|
+
dark: "#0d0e11"
|
|
7600
|
+
},
|
|
7601
|
+
text: {
|
|
7602
|
+
primary: "#ffffff",
|
|
7603
|
+
muted: "#808080",
|
|
7604
|
+
inverted: "#000000"
|
|
7605
|
+
},
|
|
7606
|
+
theme: {
|
|
7607
|
+
primary: "#f6c833",
|
|
7608
|
+
secondary: "#6366f1",
|
|
7609
|
+
background: "#131419",
|
|
7610
|
+
border: "#262626",
|
|
7611
|
+
card: "#1b1d25",
|
|
7612
|
+
"card-glass": "rgba(27, 29, 37, 0.8)"
|
|
7613
|
+
},
|
|
7614
|
+
typography: {
|
|
7615
|
+
fontFamily: {
|
|
7616
|
+
base: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7617
|
+
heading: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7618
|
+
mono: "monospace"
|
|
7619
|
+
},
|
|
7620
|
+
fontSize: {
|
|
7621
|
+
"2xs": "10px",
|
|
7622
|
+
xs: "12px",
|
|
7623
|
+
sm: "14px",
|
|
7624
|
+
md: "16px",
|
|
7625
|
+
lg: "18px",
|
|
7626
|
+
xl: "20px",
|
|
7627
|
+
"2xl": "24px",
|
|
7628
|
+
"3xl": "30px",
|
|
7629
|
+
"4xl": "36px",
|
|
7630
|
+
"5xl": "48px",
|
|
7631
|
+
"6xl": "60px"
|
|
7632
|
+
},
|
|
7633
|
+
fontWeight: {
|
|
7634
|
+
thin: "100",
|
|
7635
|
+
extralight: "200",
|
|
7636
|
+
light: "300",
|
|
7637
|
+
regular: "400",
|
|
7638
|
+
medium: "500",
|
|
7639
|
+
semibold: "600",
|
|
7640
|
+
bold: "700",
|
|
7641
|
+
extrabold: "800",
|
|
7642
|
+
black: "900",
|
|
7643
|
+
extrablack: "950"
|
|
7644
|
+
},
|
|
7645
|
+
lineHeight: {
|
|
7646
|
+
none: "1",
|
|
7647
|
+
tight: "1.25",
|
|
7648
|
+
snug: "1.375",
|
|
7649
|
+
normal: "1.5",
|
|
7650
|
+
relaxed: "1.625",
|
|
7651
|
+
loose: "2"
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
},
|
|
6655
7655
|
// Static locale data at top level
|
|
6656
7656
|
locale: "en-US",
|
|
6657
7657
|
languageCode: "en",
|
|
@@ -6782,6 +7782,58 @@ var VenusAPI2 = class {
|
|
|
6782
7782
|
deviceType: "phone",
|
|
6783
7783
|
hapticsEnabled: false,
|
|
6784
7784
|
haptics: { supported: false, enabled: false }
|
|
7785
|
+
},
|
|
7786
|
+
theme: {
|
|
7787
|
+
background: { default: "#131419", muted: "#1b1d25", dark: "#0d0e11" },
|
|
7788
|
+
text: { primary: "#ffffff", muted: "#808080", inverted: "#000000" },
|
|
7789
|
+
theme: {
|
|
7790
|
+
primary: "#f6c833",
|
|
7791
|
+
secondary: "#6366f1",
|
|
7792
|
+
background: "#131419",
|
|
7793
|
+
border: "#262626",
|
|
7794
|
+
card: "#1b1d25",
|
|
7795
|
+
"card-glass": "rgba(27, 29, 37, 0.8)"
|
|
7796
|
+
},
|
|
7797
|
+
typography: {
|
|
7798
|
+
fontFamily: {
|
|
7799
|
+
base: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7800
|
+
heading: "Plus Jakarta Sans, Roboto, sans-serif",
|
|
7801
|
+
mono: "monospace"
|
|
7802
|
+
},
|
|
7803
|
+
fontSize: {
|
|
7804
|
+
"2xs": "10px",
|
|
7805
|
+
xs: "12px",
|
|
7806
|
+
sm: "14px",
|
|
7807
|
+
md: "16px",
|
|
7808
|
+
lg: "18px",
|
|
7809
|
+
xl: "20px",
|
|
7810
|
+
"2xl": "24px",
|
|
7811
|
+
"3xl": "30px",
|
|
7812
|
+
"4xl": "36px",
|
|
7813
|
+
"5xl": "48px",
|
|
7814
|
+
"6xl": "60px"
|
|
7815
|
+
},
|
|
7816
|
+
fontWeight: {
|
|
7817
|
+
thin: "100",
|
|
7818
|
+
extralight: "200",
|
|
7819
|
+
light: "300",
|
|
7820
|
+
regular: "400",
|
|
7821
|
+
medium: "500",
|
|
7822
|
+
semibold: "600",
|
|
7823
|
+
bold: "700",
|
|
7824
|
+
extrabold: "800",
|
|
7825
|
+
black: "900",
|
|
7826
|
+
extrablack: "950"
|
|
7827
|
+
},
|
|
7828
|
+
lineHeight: {
|
|
7829
|
+
none: "1",
|
|
7830
|
+
tight: "1.25",
|
|
7831
|
+
snug: "1.375",
|
|
7832
|
+
normal: "1.5",
|
|
7833
|
+
relaxed: "1.625",
|
|
7834
|
+
loose: "2"
|
|
7835
|
+
}
|
|
7836
|
+
}
|
|
6785
7837
|
}
|
|
6786
7838
|
});
|
|
6787
7839
|
const originalConfig = this.config;
|
|
@@ -6810,6 +7862,7 @@ var VenusAPI2 = class {
|
|
|
6810
7862
|
initializeStorage(this, host);
|
|
6811
7863
|
initializeRoomsApi(this, host);
|
|
6812
7864
|
initializeAds(this, host);
|
|
7865
|
+
initializeTheme(this);
|
|
6813
7866
|
initializePopups(this, host);
|
|
6814
7867
|
initializeAnalytics(this, host);
|
|
6815
7868
|
initializeIap(this, host);
|
|
@@ -6891,9 +7944,13 @@ var VenusAPI2 = class {
|
|
|
6891
7944
|
// BOOTSTRAP METHODS
|
|
6892
7945
|
//---------------------------------------
|
|
6893
7946
|
_detectHostedEnvironment() {
|
|
7947
|
+
console.log("[Venus SDK] Detecting host environment...");
|
|
6894
7948
|
const isInIframe = window.self !== window.top;
|
|
6895
7949
|
const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
|
|
6896
7950
|
this._bootstrap.isInsideHostedEnvironment = isInIframe || hasReactNativeWebView;
|
|
7951
|
+
console.log(
|
|
7952
|
+
`[Venus SDK] isInIframe: ${isInIframe}, hasReactNativeWebView: ${hasReactNativeWebView}`
|
|
7953
|
+
);
|
|
6897
7954
|
}
|
|
6898
7955
|
isMobile() {
|
|
6899
7956
|
return typeof window.ReactNativeWebView !== "undefined";
|
|
@@ -6948,6 +8005,7 @@ instance.isAvailable = function() {
|
|
|
6948
8005
|
(async () => {
|
|
6949
8006
|
try {
|
|
6950
8007
|
await initializeNumbers(instance);
|
|
8008
|
+
console.log("[Venus SDK] Numbers system initialized");
|
|
6951
8009
|
} catch (error) {
|
|
6952
8010
|
console.error("[Venus SDK] Failed to initialize numbers system:", error);
|
|
6953
8011
|
}
|