@puzzmo/sdk 1.0.79 → 1.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contracts.d.ts +6 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/{createSimulator-CbTxfkRg.js → createSimulator-2M7vXzRZ.js} +14 -10
- package/dist/{createSimulator-CbTxfkRg.js.map → createSimulator-2M7vXzRZ.js.map} +1 -1
- package/dist/{createSimulator-Xu-DhjEi.cjs → createSimulator-B4QlohUV.cjs} +3 -3
- package/dist/{createSimulator-Xu-DhjEi.cjs.map → createSimulator-B4QlohUV.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +175 -127
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +27 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/simulator/createSimulator.d.ts.map +1 -1
- package/dist/simulator/index.cjs +1 -1
- package/dist/simulator/index.js +1 -1
- package/dist/simulator/standalone.cjs +1 -1
- package/dist/simulator/standalone.js +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -184,12 +184,12 @@ var h = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user
|
|
|
184
184
|
if (t) return t.host === "msn" ? "msn" : "iframe";
|
|
185
185
|
let n = e.find((e) => (e == null ? void 0 : e.type) === "app");
|
|
186
186
|
return (n == null ? void 0 : n.host) === "__embed" ? "simple_embed" : (n == null ? void 0 : n.host) === "app-embed" ? "app_embed" : (n == null ? void 0 : n.host) === "ios-app" ? "ios_native" : "puzzmo_com";
|
|
187
|
-
}, y = ["inputString"];
|
|
188
|
-
function
|
|
187
|
+
}, y = ["inputString"], b = ["omit"];
|
|
188
|
+
function x(e) {
|
|
189
189
|
let t = e >= 3600 * 1e3;
|
|
190
190
|
return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function S(e = 0, t = 0) {
|
|
193
193
|
let n = e, r = t, i = 0, a, o, s, c = () => {
|
|
194
194
|
var e;
|
|
195
195
|
if (o === void 0) return n + r;
|
|
@@ -236,12 +236,12 @@ function x(e = 0, t = 0) {
|
|
|
236
236
|
isRunning: () => o !== void 0 && s === void 0,
|
|
237
237
|
display: () => {
|
|
238
238
|
let e = c() - r;
|
|
239
|
-
return [
|
|
239
|
+
return [x(Math.max(0, e)), r === 0 ? "" : x(r)];
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
|
-
function
|
|
244
|
-
let e = /* @__PURE__ */ new Map();
|
|
243
|
+
function C() {
|
|
244
|
+
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
|
|
245
245
|
return typeof window < "u" && window.addEventListener("message", (t) => {
|
|
246
246
|
var n;
|
|
247
247
|
if (!(!(t == null || (n = t.data) == null) && n.type)) return;
|
|
@@ -252,20 +252,30 @@ function S() {
|
|
|
252
252
|
r !== "TIMER_TICK" && r !== "TIMER_SYNC" && console.log("[Puzzmo SDK] received:", r, e), i.forEach((t) => t(e));
|
|
253
253
|
}
|
|
254
254
|
}), {
|
|
255
|
-
sendMessage: (e,
|
|
256
|
-
var
|
|
257
|
-
let
|
|
255
|
+
sendMessage: (e, n) => {
|
|
256
|
+
var r, i, a;
|
|
257
|
+
let o = {
|
|
258
258
|
type: e,
|
|
259
|
-
json:
|
|
259
|
+
json: n,
|
|
260
260
|
_: "p",
|
|
261
261
|
__: "mp",
|
|
262
262
|
private: !0
|
|
263
263
|
};
|
|
264
|
-
"parent" in window && window.parent !== window && window.parent.postMessage(
|
|
264
|
+
"parent" in window && window.parent !== window && window.parent.postMessage(o, "*"), window.postMessage(o, "*"), "webkit" in window && !((r = window.webkit) == null || (r = r.messageHandlers) == null) && r.app && window.webkit.messageHandlers.app.postMessage(o), "puzzmoMessageString" in window && window.puzzmoMessageString(JSON.stringify(o)), "ReactNativeWebView" in window && (i = window.ReactNativeWebView) != null && i.postMessage && window.ReactNativeWebView.postMessage(JSON.stringify(o)), e !== "TIMER_TICK" && e !== "TIMER_SYNC" && console.log("[Puzzmo SDK] sent:", e, n), (a = t.get(e)) == null || a.forEach((t) => {
|
|
265
|
+
try {
|
|
266
|
+
t(n);
|
|
267
|
+
} catch (t) {
|
|
268
|
+
console.error(`[Puzzmo SDK] a watcher of ${e} threw:`, t);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
265
271
|
},
|
|
266
272
|
onMessage: (t, n) => (e.has(t) || e.set(t, /* @__PURE__ */ new Set()), e.get(t).add(n), () => {
|
|
267
273
|
var r;
|
|
268
274
|
(r = e.get(t)) == null || r.delete(n);
|
|
275
|
+
}),
|
|
276
|
+
onSend: (e, n) => (t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(n), () => {
|
|
277
|
+
var r;
|
|
278
|
+
(r = t.get(e)) == null || r.delete(n);
|
|
269
279
|
})
|
|
270
280
|
};
|
|
271
281
|
}
|
|
@@ -273,9 +283,9 @@ function S() {
|
|
|
273
283
|
* The host<->game contract this SDK speaks, declared in READY and READY_GAME_LOADED: games read
|
|
274
284
|
* `game` and `session`, and handle `session` being absent. Hosts on "1.0" always send a session.
|
|
275
285
|
*/
|
|
276
|
-
var
|
|
286
|
+
var w = "1.1", T = C(), E = 1e4;
|
|
277
287
|
/** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
|
|
278
|
-
const
|
|
288
|
+
const D = (r = {}) => {
|
|
279
289
|
var i;
|
|
280
290
|
let a = null, s = null, c = () => {
|
|
281
291
|
var e;
|
|
@@ -295,55 +305,55 @@ const E = (r = {}) => {
|
|
|
295
305
|
}, h = null, g = 0, _ = 0, v = !1, b = () => {
|
|
296
306
|
var e, t;
|
|
297
307
|
return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
|
|
298
|
-
},
|
|
299
|
-
if (
|
|
300
|
-
|
|
308
|
+
}, x = !1, C = (e) => {
|
|
309
|
+
if (x) return;
|
|
310
|
+
x = !0;
|
|
301
311
|
let t = a ? "the host sent no play session, so there is no gameplay to save to" : "it was called before gameReady() resolved";
|
|
302
312
|
console.warn(`[Puzzmo SDK] ${e}() was ignored: ${t}`);
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
},
|
|
306
|
-
|
|
307
|
-
if (
|
|
308
|
-
let [e, t] =
|
|
309
|
-
|
|
310
|
-
}, 500),
|
|
311
|
-
|
|
313
|
+
}, D = /* @__PURE__ */ new Map(), M = null, N = [], P = {}, F = () => t(t({}, M), P), I = null, L = !1, R = (e, t) => {
|
|
314
|
+
L || I == null || I.trackEvent(e, t);
|
|
315
|
+
}, z = S(), B = null, V = null, H = () => {
|
|
316
|
+
B || (B = setInterval(() => {
|
|
317
|
+
if (z.isPaused()) return;
|
|
318
|
+
let [e, t] = z.display();
|
|
319
|
+
T.sendMessage("TIMER_TICK", { display: [e, t] });
|
|
320
|
+
}, 500), V = setInterval(() => {
|
|
321
|
+
z.isPaused() || T.sendMessage("TIMER_SYNC", Math.floor(z.timeWithoutPenaltySecs()));
|
|
312
322
|
}, 1e4));
|
|
313
|
-
},
|
|
314
|
-
|
|
315
|
-
},
|
|
316
|
-
let n =
|
|
323
|
+
}, U = () => {
|
|
324
|
+
B && (clearInterval(B), B = null), V && (clearInterval(V), V = null);
|
|
325
|
+
}, W = (e, t) => {
|
|
326
|
+
let n = D.get(e);
|
|
317
327
|
n && n.forEach((e) => e(t));
|
|
318
328
|
};
|
|
319
|
-
|
|
320
|
-
|
|
329
|
+
T.onMessage("START_GAME", () => {
|
|
330
|
+
z._init(), H(), W("start");
|
|
321
331
|
});
|
|
322
|
-
let
|
|
323
|
-
let e =
|
|
324
|
-
|
|
325
|
-
},
|
|
326
|
-
let e =
|
|
327
|
-
|
|
332
|
+
let G = () => {
|
|
333
|
+
let e = z.isPaused();
|
|
334
|
+
z._pause(), z.isPaused() !== e && W("pause");
|
|
335
|
+
}, K = () => {
|
|
336
|
+
let e = z.isPaused();
|
|
337
|
+
z._resume(), z.isPaused() !== e && W("resume");
|
|
328
338
|
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}),
|
|
332
|
-
let
|
|
333
|
-
|
|
334
|
-
let t =
|
|
335
|
-
t && (
|
|
339
|
+
T.onMessage("PAUSE_GAME", G), T.onMessage("RESUME_GAME", K), T.onMessage("SETTINGS_UPDATE", (e) => {
|
|
340
|
+
M = t(t({}, M), e), W("settingsUpdate", F());
|
|
341
|
+
}), T.onMessage("KEYBOARD_KEY_PRESS", (e) => W("keyboardKeyPress", e)), T.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => W("keyboardCursorChange", e)), T.onMessage("KEYBOARD_CURSOR_END", () => W("keyboardCursorEnd")), T.onMessage("ACHIEVEMENTS_UNLOCKED", (e) => W("achievementsUnlocked", e));
|
|
342
|
+
let q = /* @__PURE__ */ new Map(), J = 0;
|
|
343
|
+
T.onMessage("PUZZLE_DATA", (e) => {
|
|
344
|
+
let t = q.get(e.nonce);
|
|
345
|
+
t && (q.delete(e.nonce), "failed" in e ? t.reject(Error(e.error)) : t.resolve({
|
|
336
346
|
puzzleKey: e.puzzle.key,
|
|
337
347
|
puzzleString: e.puzzle.puzzle
|
|
338
348
|
}));
|
|
339
|
-
}),
|
|
340
|
-
|
|
341
|
-
}),
|
|
349
|
+
}), T.onMessage("RETRY_PUZZLE", () => {
|
|
350
|
+
z._reset(), U(), W("retry");
|
|
351
|
+
}), T.onMessage("READY_DATA", (e) => {
|
|
342
352
|
var t;
|
|
343
353
|
let n = o(e);
|
|
344
354
|
a = n;
|
|
345
355
|
let r = (t = n.session) == null ? void 0 : t.gameplay;
|
|
346
|
-
if (
|
|
356
|
+
if (M === null) {
|
|
347
357
|
var i, c;
|
|
348
358
|
let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
|
|
349
359
|
if (typeof t == "string") try {
|
|
@@ -351,46 +361,47 @@ const E = (r = {}) => {
|
|
|
351
361
|
} catch (e) {
|
|
352
362
|
t = null;
|
|
353
363
|
}
|
|
354
|
-
|
|
364
|
+
M = (c = t) == null ? {} : c;
|
|
355
365
|
}
|
|
356
366
|
if (r) {
|
|
357
367
|
var l, u;
|
|
358
368
|
let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((u = r.additionalTimeAddedSecs) == null ? 0 : u) * 1e3;
|
|
359
|
-
|
|
369
|
+
z._reset(e, t);
|
|
360
370
|
}
|
|
361
|
-
if (!
|
|
371
|
+
if (!I) {
|
|
362
372
|
var p;
|
|
363
|
-
|
|
373
|
+
I = d(n), L = (p = r == null ? void 0 : r.completed) == null ? !1 : p, I && f((e) => I.trackLinkClick(e));
|
|
364
374
|
}
|
|
365
375
|
s && (s(n), s = null);
|
|
366
376
|
});
|
|
367
|
-
let
|
|
368
|
-
timeMs: () =>
|
|
369
|
-
timeSecs: () =>
|
|
370
|
-
addedTimeMs: () =>
|
|
371
|
-
addedTimeSecs: () =>
|
|
372
|
-
timeWithoutPenaltySecs: () =>
|
|
373
|
-
display: () =>
|
|
374
|
-
addPenalty: (e) =>
|
|
375
|
-
setPenalty: (e) =>
|
|
376
|
-
isPaused: () =>
|
|
377
|
-
isRunning: () =>
|
|
378
|
-
pause:
|
|
379
|
-
resume:
|
|
380
|
-
},
|
|
381
|
-
send: (e, t) =>
|
|
382
|
-
on: (e, t) =>
|
|
383
|
-
|
|
377
|
+
let Y = {
|
|
378
|
+
timeMs: () => z.timeMs(),
|
|
379
|
+
timeSecs: () => z.timeSecs(),
|
|
380
|
+
addedTimeMs: () => z.addedTimeMs(),
|
|
381
|
+
addedTimeSecs: () => z.addedTimeSecs(),
|
|
382
|
+
timeWithoutPenaltySecs: () => z.timeWithoutPenaltySecs(),
|
|
383
|
+
display: () => z.display(),
|
|
384
|
+
addPenalty: (e) => z.addPenalty(e),
|
|
385
|
+
setPenalty: (e) => z.setPenalty(e),
|
|
386
|
+
isPaused: () => z.isPaused(),
|
|
387
|
+
isRunning: () => z.isRunning(),
|
|
388
|
+
pause: G,
|
|
389
|
+
resume: K
|
|
390
|
+
}, X = {
|
|
391
|
+
send: (e, t) => T.sendMessage(e, t),
|
|
392
|
+
on: (e, t) => T.onMessage(e, t),
|
|
393
|
+
onSend: T.onSend,
|
|
394
|
+
timer: Y,
|
|
384
395
|
bootstrap: () => a
|
|
385
|
-
},
|
|
386
|
-
for (let e of (i = r.plugins) == null ? [] : i)
|
|
396
|
+
}, Z = {};
|
|
397
|
+
for (let e of (i = r.plugins) == null ? [] : i) Z[e.name] = e.setup(X);
|
|
387
398
|
return {
|
|
388
|
-
timer:
|
|
389
|
-
plugins:
|
|
399
|
+
timer: Y,
|
|
400
|
+
plugins: Z,
|
|
390
401
|
gameReady: function() {
|
|
391
402
|
var e = n(function* () {
|
|
392
403
|
var e, n;
|
|
393
|
-
if (
|
|
404
|
+
if (T.sendMessage("READY", { runtimeContract: w }), !a) {
|
|
394
405
|
var i;
|
|
395
406
|
let e = (i = r.timeout) == null ? 5e3 : i;
|
|
396
407
|
yield new Promise((t, n) => {
|
|
@@ -415,41 +426,41 @@ const E = (r = {}) => {
|
|
|
415
426
|
};
|
|
416
427
|
}(),
|
|
417
428
|
gameLoaded: (e = {}) => {
|
|
418
|
-
|
|
429
|
+
T.sendMessage("READY_GAME_LOADED", {
|
|
419
430
|
state: e,
|
|
420
|
-
gameRuntimeContract:
|
|
431
|
+
gameRuntimeContract: w,
|
|
421
432
|
embedRuntimeContract: "1.0"
|
|
422
|
-
}),
|
|
433
|
+
}), R("READY_GAME_LOADED");
|
|
423
434
|
},
|
|
424
|
-
on: (e, t) => (
|
|
435
|
+
on: (e, t) => (D.has(e) || D.set(e, /* @__PURE__ */ new Set()), D.get(e).add(t), () => {
|
|
425
436
|
var n;
|
|
426
|
-
(n =
|
|
437
|
+
(n = D.get(e)) == null || n.delete(t);
|
|
427
438
|
}),
|
|
428
439
|
off: (e, t) => {
|
|
429
440
|
var n;
|
|
430
|
-
(n =
|
|
441
|
+
(n = D.get(e)) == null || n.delete(t);
|
|
431
442
|
},
|
|
432
443
|
updateGameState: (e, t) => {
|
|
433
444
|
var n, r;
|
|
434
445
|
let i = l();
|
|
435
|
-
if (!i) return
|
|
436
|
-
|
|
446
|
+
if (!i) return C("updateGameState");
|
|
447
|
+
T.sendMessage("UPLOAD_NEW_GAME_STATE", {
|
|
437
448
|
id: i,
|
|
438
449
|
input: {
|
|
439
450
|
boardState: e,
|
|
440
|
-
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ?
|
|
441
|
-
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ?
|
|
451
|
+
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? z.timeWithoutPenaltySecs() : n,
|
|
452
|
+
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? z.addedTimeSecs() : r,
|
|
442
453
|
collabUserReferences: []
|
|
443
454
|
}
|
|
444
|
-
}),
|
|
455
|
+
}), R("UPLOAD_NEW_GAME_STATE");
|
|
445
456
|
},
|
|
446
457
|
gameCompleted: (n, r) => {
|
|
447
458
|
var i, o, s, c, u;
|
|
448
|
-
|
|
459
|
+
z._conclude(), U();
|
|
449
460
|
let { inputString: d } = n, f = t(t({}, e(n, y)), {}, {
|
|
450
461
|
boardState: d == null ? n.boardState : d,
|
|
451
|
-
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ?
|
|
452
|
-
additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ?
|
|
462
|
+
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? z.timeWithoutPenaltySecs() : i,
|
|
463
|
+
additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ? z.addedTimeSecs() : o
|
|
453
464
|
}), p = (s = r == null ? void 0 : r.deeds) == null ? [] : s;
|
|
454
465
|
p.push({
|
|
455
466
|
id: "points",
|
|
@@ -459,26 +470,26 @@ const E = (r = {}) => {
|
|
|
459
470
|
value: Math.round((c = f.elapsedTimeSecs) == null ? 0 : c) + Math.round((u = f.additionalTimeAddedSecs) == null ? 0 : u)
|
|
460
471
|
});
|
|
461
472
|
let m = l(), h = a && !a.session && a.appRuntimeContract === "1.1";
|
|
462
|
-
m || h ? (
|
|
473
|
+
m || h ? (T.sendMessage("GAME_COMPLETED", {
|
|
463
474
|
id: m == null ? void 0 : m,
|
|
464
475
|
input: f,
|
|
465
476
|
config: r
|
|
466
|
-
}),
|
|
477
|
+
}), R("GAME_COMPLETED", { input: f })) : C("gameCompleted");
|
|
467
478
|
},
|
|
468
479
|
showCompletionScreen: (e) => {
|
|
469
|
-
|
|
480
|
+
T.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
|
|
470
481
|
results: e,
|
|
471
482
|
showRetry: !0
|
|
472
483
|
});
|
|
473
484
|
},
|
|
474
485
|
hitCheckpoint: (e, t, n) => {
|
|
475
486
|
var r;
|
|
476
|
-
if (!l()) return
|
|
487
|
+
if (!l()) return C("hitCheckpoint");
|
|
477
488
|
let i = (r = p()) == null ? "" : r, a = {
|
|
478
|
-
elapsedTimeSecs:
|
|
479
|
-
additionalTimeAddedSecs:
|
|
489
|
+
elapsedTimeSecs: z.timeWithoutPenaltySecs(),
|
|
490
|
+
additionalTimeAddedSecs: z.addedTimeSecs()
|
|
480
491
|
};
|
|
481
|
-
|
|
492
|
+
T.sendMessage("HIT_CHECKPOINT", {
|
|
482
493
|
checkpointName: e,
|
|
483
494
|
gameplay: {
|
|
484
495
|
inputStr: i,
|
|
@@ -490,41 +501,44 @@ const E = (r = {}) => {
|
|
|
490
501
|
},
|
|
491
502
|
completeRepeatableRun: (e, n) => {
|
|
492
503
|
var r, i;
|
|
493
|
-
let a =
|
|
504
|
+
let a = z.timeWithoutPenaltySecs(), o = a >= g ? a - g : a;
|
|
494
505
|
g = a;
|
|
495
506
|
let s = Math.round((r = e == null ? void 0 : e.elapsedTimeSecs) == null ? o : r), c = [...((i = n == null ? void 0 : n.deeds) == null ? [] : i).filter((e) => e.id !== "time"), {
|
|
496
507
|
id: "time",
|
|
497
508
|
value: s
|
|
498
509
|
}], l = e == null ? void 0 : e.puzzleKey;
|
|
499
|
-
|
|
510
|
+
T.sendMessage("COMPLETE_REPEATABLE_RUN", { input: t({
|
|
500
511
|
deedValues: c,
|
|
501
512
|
elapsedTimeSecs: s
|
|
502
|
-
}, l ? { puzzleKey: l } : {}) }),
|
|
513
|
+
}, l ? { puzzleKey: l } : {}) }), R("COMPLETE_REPEATABLE_RUN", { elapsedTimeSecs: s });
|
|
503
514
|
},
|
|
504
515
|
rounds: {
|
|
505
516
|
start: (e) => {
|
|
506
|
-
_ = 0,
|
|
517
|
+
_ = 0, T.sendMessage("START_REPEATABLE_ROUND", t({ reason: e.reason }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
|
|
507
518
|
},
|
|
508
519
|
resume: (e) => {
|
|
509
|
-
_ = e.events.length,
|
|
520
|
+
_ = e.events.length, T.sendMessage("RESUME_REPEATABLE_ROUND", t({ events: e.events.map((e) => [...e]) }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
|
|
510
521
|
},
|
|
511
522
|
log: (...e) => {
|
|
512
|
-
e.length && (
|
|
523
|
+
e.length && (T.sendMessage("APPEND_REPEATABLE_ROUND_LOG", {
|
|
513
524
|
from: _,
|
|
514
525
|
events: e.map((e) => [...e])
|
|
515
526
|
}), _ += e.length);
|
|
516
527
|
}
|
|
517
528
|
},
|
|
529
|
+
table: { updateGameState: (e, n) => {
|
|
530
|
+
T.sendMessage("UPDATE_TABLE_GAME_STATE", t({ inputString: e }, (n == null ? void 0 : n.puzzleString) === void 0 ? {} : { puzzleString: n.puzzleString }));
|
|
531
|
+
} },
|
|
518
532
|
requestPuzzle: (e) => new Promise((t, n) => {
|
|
519
|
-
let r = `puzzle-${++
|
|
520
|
-
|
|
521
|
-
},
|
|
533
|
+
let r = `puzzle-${++J}`, i = setTimeout(() => {
|
|
534
|
+
q.delete(r) && n(/* @__PURE__ */ Error(`Timeout waiting for PUZZLE_DATA after ${E}ms`));
|
|
535
|
+
}, E), a = (e) => (t) => {
|
|
522
536
|
clearTimeout(i), e(t);
|
|
523
537
|
};
|
|
524
|
-
|
|
538
|
+
q.set(r, {
|
|
525
539
|
resolve: a(t),
|
|
526
540
|
reject: a(n)
|
|
527
|
-
}),
|
|
541
|
+
}), T.sendMessage("REQUEST_PUZZLE", {
|
|
528
542
|
nonce: r,
|
|
529
543
|
buckets: e != null && e.buckets ? [...e.buckets] : void 0,
|
|
530
544
|
exclude: e != null && e.exclude ? [...e.exclude] : void 0
|
|
@@ -541,34 +555,40 @@ const E = (r = {}) => {
|
|
|
541
555
|
},
|
|
542
556
|
set: (e, t = 1) => {
|
|
543
557
|
let n = new TextEncoder().encode(e).length;
|
|
544
|
-
if (n >
|
|
558
|
+
if (n > j) throw Error(`[sdk.storage] State is ${n} bytes, over the ${j} byte cap`);
|
|
545
559
|
if (!Number.isInteger(t) || t < 1) throw Error("[sdk.storage] stateVersion must be a positive integer");
|
|
546
560
|
a && !a.repeatable && !v && (v = !0, console.warn("[sdk.storage] Only repeat play saves storage for now; this write lasts until the page reloads")), h = {
|
|
547
561
|
state: e,
|
|
548
562
|
stateVersion: t
|
|
549
|
-
},
|
|
563
|
+
}, T.sendMessage("UPDATE_GAME_USER_STATE", {
|
|
550
564
|
state: e,
|
|
551
565
|
stateVersion: t
|
|
552
566
|
});
|
|
553
567
|
}
|
|
554
568
|
},
|
|
555
569
|
settings: {
|
|
556
|
-
initialize: (e) =>
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
570
|
+
initialize: (e) => {
|
|
571
|
+
let n = A(e, k(a));
|
|
572
|
+
N = n.components, P = n.locked, M = t(t({}, O(N)), M);
|
|
573
|
+
let r = F();
|
|
574
|
+
return T.sendMessage("INITIALIZE_SETTINGS", {
|
|
575
|
+
components: N,
|
|
576
|
+
settings: r
|
|
577
|
+
}), r;
|
|
563
578
|
},
|
|
564
|
-
|
|
579
|
+
get: F,
|
|
580
|
+
update: (e) => {
|
|
581
|
+
let n = Object.entries(e == null ? {} : e).filter(([e]) => !(e in P));
|
|
582
|
+
return M = t(t({}, M), Object.fromEntries(n)), T.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: M }), F();
|
|
583
|
+
},
|
|
584
|
+
components: () => N
|
|
565
585
|
},
|
|
566
586
|
keyboard: {
|
|
567
587
|
show: (e) => {
|
|
568
|
-
|
|
588
|
+
T.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
|
|
569
589
|
},
|
|
570
590
|
hide: () => {
|
|
571
|
-
|
|
591
|
+
T.sendMessage("KEYBOARD_UPDATE_CONFIG", {
|
|
572
592
|
layout: [],
|
|
573
593
|
symbols: {},
|
|
574
594
|
highlight: [],
|
|
@@ -581,22 +601,50 @@ const E = (r = {}) => {
|
|
|
581
601
|
},
|
|
582
602
|
haptics: { play: (e, t) => {
|
|
583
603
|
var n;
|
|
584
|
-
|
|
604
|
+
T.sendMessage("SENSORY_EVENT", {
|
|
585
605
|
id: (n = t == null ? void 0 : t.id) == null ? e : n,
|
|
586
606
|
haptic: e
|
|
587
607
|
});
|
|
588
608
|
} },
|
|
589
|
-
_hostAPI:
|
|
609
|
+
_hostAPI: T
|
|
590
610
|
};
|
|
591
611
|
};
|
|
592
612
|
/** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
|
|
593
|
-
function
|
|
613
|
+
function O(e) {
|
|
594
614
|
let t = {};
|
|
595
|
-
for (let n of e) n.type === "split" ? Object.assign(t,
|
|
615
|
+
for (let n of e) n.type === "split" ? Object.assign(t, O(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
|
|
596
616
|
return t;
|
|
597
617
|
}
|
|
618
|
+
/** The settings overrides an embed's host context holds for this game, under the game's slug */
|
|
619
|
+
function k(e) {
|
|
620
|
+
var t, n;
|
|
621
|
+
let r = e == null || (t = e.hostContext) == null ? void 0 : t.find((e) => e.type === "embed"), i = e == null || (n = e.game) == null ? void 0 : n.slug;
|
|
622
|
+
if (!r || !i) return [];
|
|
623
|
+
let a = r[i];
|
|
624
|
+
return Array.isArray(a == null ? void 0 : a.settingsUIOverrides) ? a.settingsUIOverrides : [];
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Applies an embed's overrides to the components they match by `id`, recursing into split groups.
|
|
628
|
+
* `omit` marks the component `hidden`, and `locked` holds the value each omitted setting is kept at.
|
|
629
|
+
*/
|
|
630
|
+
function A(n, r) {
|
|
631
|
+
let i = {};
|
|
632
|
+
if (!r.length) return {
|
|
633
|
+
components: n,
|
|
634
|
+
locked: i
|
|
635
|
+
};
|
|
636
|
+
let a = (n, o) => {
|
|
637
|
+
var s;
|
|
638
|
+
let c = (s = r.find((e) => e.id === n.id)) == null ? { id: n.id } : s, { omit: l } = c, u = e(c, b), d = o || !!l, f = t(t(t({}, n), u), d ? { hidden: !0 } : {});
|
|
639
|
+
return f.type === "split" ? t(t({}, f), {}, { content: f.content.map((e) => a(e, d)) }) : (d && "name" in f && (i[f.name] = f.defaultValue), f);
|
|
640
|
+
};
|
|
641
|
+
return {
|
|
642
|
+
components: n.map((e) => a(e, !1)),
|
|
643
|
+
locked: i
|
|
644
|
+
};
|
|
645
|
+
}
|
|
598
646
|
/** The largest state `sdk.storage.set()` takes, matching the API's cap */
|
|
599
|
-
var
|
|
647
|
+
var j = 64 * 1024;
|
|
600
648
|
/**
|
|
601
649
|
* A standard QWERTY layout with Enter and Backspace — a reasonable default for
|
|
602
650
|
* any game that needs text input. Customize from here by spreading and overriding.
|
|
@@ -609,7 +657,7 @@ var O = 64 * 1024;
|
|
|
609
657
|
* // Extend with dynamic disabled letters
|
|
610
658
|
* sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
|
|
611
659
|
*/
|
|
612
|
-
const
|
|
660
|
+
const M = {
|
|
613
661
|
layout: [
|
|
614
662
|
"qwertyuiop",
|
|
615
663
|
"asdfghjkl",
|
|
@@ -625,7 +673,7 @@ const k = {
|
|
|
625
673
|
xl: [],
|
|
626
674
|
l: ["↵", "⌫"],
|
|
627
675
|
supportsDragCursor: !1
|
|
628
|
-
},
|
|
676
|
+
}, N = (e) => {
|
|
629
677
|
let n = {};
|
|
630
678
|
for (let a of e) for (let e of a.keys) {
|
|
631
679
|
var r, i;
|
|
@@ -635,11 +683,11 @@ const k = {
|
|
|
635
683
|
return n;
|
|
636
684
|
};
|
|
637
685
|
/** Custom error class for workshop import failures */
|
|
638
|
-
var
|
|
686
|
+
var P = class extends Error {
|
|
639
687
|
constructor(e, t, n) {
|
|
640
688
|
super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
|
|
641
689
|
}
|
|
642
690
|
};
|
|
643
|
-
export {
|
|
691
|
+
export { P as EditorImportError, D as createPuzzmoSDK, M as defaultKeyboardConfig, N as keyStylesFromRules };
|
|
644
692
|
|
|
645
693
|
//# sourceMappingURL=index.js.map
|