@puzzmo/sdk 1.0.87 → 1.0.89
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 +5 -0
- 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 +67 -45
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +10 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/tableStatus.spec.d.ts +2 -0
- package/dist/tableStatus.spec.d.ts.map +1 -0
- package/dist/types.d.ts +15 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -302,12 +302,12 @@ const D = (r = {}) => {
|
|
|
302
302
|
}, m = () => {
|
|
303
303
|
var e;
|
|
304
304
|
return (e = a == null ? void 0 : a.theme) == null ? null : e;
|
|
305
|
-
}, h = null, g = 0, _ =
|
|
305
|
+
}, h = null, g = 0, _ = null, v = null, b = 0, x = !1, C = !1, D = () => {
|
|
306
306
|
var e, t;
|
|
307
307
|
return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
|
|
308
|
-
},
|
|
309
|
-
if (
|
|
310
|
-
|
|
308
|
+
}, A = !1, j = (e) => {
|
|
309
|
+
if (A) return;
|
|
310
|
+
A = !0;
|
|
311
311
|
let t = a ? "the host sent no play session, so there is no gameplay to save to" : "it was called before gameReady() resolved";
|
|
312
312
|
console.warn(`[Puzzmo SDK] ${e}() was ignored: ${t}`);
|
|
313
313
|
}, M = /* @__PURE__ */ new Map(), N = null, P = [], F = {}, I = () => t(t({}, N), F), L = null, R = !1, z = (e, t) => {
|
|
@@ -327,33 +327,52 @@ const D = (r = {}) => {
|
|
|
327
327
|
n && n.forEach((e) => e(t));
|
|
328
328
|
};
|
|
329
329
|
T.onMessage("START_GAME", () => {
|
|
330
|
-
B._init(), U(), G("start");
|
|
330
|
+
B._init(), U(), G("start"), q();
|
|
331
331
|
});
|
|
332
|
-
let
|
|
332
|
+
let ne = () => {
|
|
333
333
|
let e = B.isPaused();
|
|
334
334
|
B._pause(), B.isPaused() !== e && G("pause");
|
|
335
|
-
},
|
|
335
|
+
}, re = () => {
|
|
336
336
|
let e = B.isPaused();
|
|
337
337
|
B._resume(), B.isPaused() !== e && G("resume");
|
|
338
|
+
}, K = (e) => {
|
|
339
|
+
var n;
|
|
340
|
+
let r = B.timeWithoutPenaltySecs(), i = (n = _) == null ? g : n;
|
|
341
|
+
return t({
|
|
342
|
+
secs: Math.max(0, Math.floor(r >= i ? r - i : r)),
|
|
343
|
+
running: !B.isPaused()
|
|
344
|
+
}, e ? { stat: {
|
|
345
|
+
value: e.value,
|
|
346
|
+
label: e.label
|
|
347
|
+
} } : {});
|
|
348
|
+
}, q = () => {
|
|
349
|
+
v && T.sendMessage("UPDATE_TABLE_GAME_STATE", {
|
|
350
|
+
inputString: v.inputString,
|
|
351
|
+
status: K(v.stat)
|
|
352
|
+
});
|
|
353
|
+
}, J = () => {
|
|
354
|
+
ne(), q();
|
|
355
|
+
}, Y = () => {
|
|
356
|
+
re(), q();
|
|
338
357
|
};
|
|
339
|
-
T.onMessage("PAUSE_GAME",
|
|
358
|
+
T.onMessage("PAUSE_GAME", J), T.onMessage("RESUME_GAME", Y), T.onMessage("SETTINGS_UPDATE", (e) => {
|
|
340
359
|
N = t(t({}, N), e), G("settingsUpdate", I());
|
|
341
360
|
}), T.onMessage("KEYBOARD_KEY_PRESS", (e) => G("keyboardKeyPress", e)), T.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => G("keyboardCursorChange", e)), T.onMessage("KEYBOARD_CURSOR_END", () => G("keyboardCursorEnd")), T.onMessage("ACHIEVEMENTS_UNLOCKED", (e) => G("achievementsUnlocked", e)), T.onMessage("REPEATABLE_ROUND_LOST", () => {
|
|
342
|
-
|
|
361
|
+
x && (x = !1, G("roundLost"));
|
|
343
362
|
});
|
|
344
|
-
let
|
|
363
|
+
let X = /* @__PURE__ */ new Map(), ie = 0;
|
|
345
364
|
T.onMessage("PUZZLE_DATA", (e) => {
|
|
346
|
-
let t =
|
|
347
|
-
t && (
|
|
365
|
+
let t = X.get(e.nonce);
|
|
366
|
+
t && (X.delete(e.nonce), "failed" in e ? t.reject(Error(e.error)) : t.resolve({
|
|
348
367
|
puzzleKey: e.puzzle.key,
|
|
349
368
|
puzzleString: e.puzzle.puzzle
|
|
350
369
|
}));
|
|
351
370
|
});
|
|
352
|
-
let
|
|
371
|
+
let Z = null, ae = 0;
|
|
353
372
|
T.onMessage("CONFIRM_ANSWER", (e) => {
|
|
354
|
-
if (!
|
|
355
|
-
let { resolve: t } =
|
|
356
|
-
|
|
373
|
+
if (!Z || Z.nonce !== e.nonce) return;
|
|
374
|
+
let { resolve: t } = Z;
|
|
375
|
+
Z = null, t(e.confirmed === !0);
|
|
357
376
|
}), T.onMessage("RETRY_PUZZLE", () => {
|
|
358
377
|
B._reset(), W(), G("retry");
|
|
359
378
|
}), T.onMessage("READY_DATA", (e) => {
|
|
@@ -393,16 +412,16 @@ const D = (r = {}) => {
|
|
|
393
412
|
setPenalty: (e) => B.setPenalty(e),
|
|
394
413
|
isPaused: () => B.isPaused(),
|
|
395
414
|
isRunning: () => B.isRunning(),
|
|
396
|
-
pause:
|
|
397
|
-
resume:
|
|
398
|
-
},
|
|
415
|
+
pause: J,
|
|
416
|
+
resume: Y
|
|
417
|
+
}, oe = {
|
|
399
418
|
send: (e, t) => T.sendMessage(e, t),
|
|
400
419
|
on: (e, t) => T.onMessage(e, t),
|
|
401
420
|
onSend: T.onSend,
|
|
402
421
|
timer: Q,
|
|
403
422
|
bootstrap: () => a
|
|
404
423
|
}, $ = {};
|
|
405
|
-
for (let e of (i = r.plugins) == null ? [] : i) $[e.name] = e.setup(
|
|
424
|
+
for (let e of (i = r.plugins) == null ? [] : i) $[e.name] = e.setup(oe);
|
|
406
425
|
return {
|
|
407
426
|
timer: Q,
|
|
408
427
|
plugins: $,
|
|
@@ -425,7 +444,7 @@ const D = (r = {}) => {
|
|
|
425
444
|
puzzleKey: a != null && a.repeatable ? (e = (n = a.repeatablePuzzle) == null ? void 0 : n.key) == null ? null : e : null,
|
|
426
445
|
inputString: o,
|
|
427
446
|
theme: m(),
|
|
428
|
-
completed:
|
|
447
|
+
completed: D(),
|
|
429
448
|
readyData: a
|
|
430
449
|
}), {}, { boardState: o });
|
|
431
450
|
});
|
|
@@ -451,7 +470,7 @@ const D = (r = {}) => {
|
|
|
451
470
|
updateGameState: (e, t) => {
|
|
452
471
|
var n, r;
|
|
453
472
|
let i = l();
|
|
454
|
-
if (!i) return
|
|
473
|
+
if (!i) return j("updateGameState");
|
|
455
474
|
T.sendMessage("UPLOAD_NEW_GAME_STATE", {
|
|
456
475
|
id: i,
|
|
457
476
|
input: {
|
|
@@ -482,7 +501,7 @@ const D = (r = {}) => {
|
|
|
482
501
|
id: m == null ? void 0 : m,
|
|
483
502
|
input: f,
|
|
484
503
|
config: r
|
|
485
|
-
}), z("GAME_COMPLETED", { input: f })) :
|
|
504
|
+
}), z("GAME_COMPLETED", { input: f })) : j("gameCompleted");
|
|
486
505
|
},
|
|
487
506
|
showCompletionScreen: (e) => {
|
|
488
507
|
T.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
|
|
@@ -492,7 +511,7 @@ const D = (r = {}) => {
|
|
|
492
511
|
},
|
|
493
512
|
hitCheckpoint: (e, t, n) => {
|
|
494
513
|
var r;
|
|
495
|
-
if (!l()) return
|
|
514
|
+
if (!l()) return j("hitCheckpoint");
|
|
496
515
|
let i = (r = p()) == null ? "" : r, a = {
|
|
497
516
|
elapsedTimeSecs: B.timeWithoutPenaltySecs(),
|
|
498
517
|
additionalTimeAddedSecs: B.addedTimeSecs()
|
|
@@ -522,10 +541,13 @@ const D = (r = {}) => {
|
|
|
522
541
|
},
|
|
523
542
|
rounds: {
|
|
524
543
|
start: (e) => {
|
|
525
|
-
|
|
544
|
+
b = 0, _ = B.timeWithoutPenaltySecs(), x = !1, T.sendMessage("START_REPEATABLE_ROUND", t({ reason: e.reason }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
|
|
526
545
|
},
|
|
527
546
|
resume: (e) => {
|
|
528
|
-
|
|
547
|
+
var n;
|
|
548
|
+
b = e.events.length;
|
|
549
|
+
let r = Number((n = e.events[e.events.length - 1]) == null ? void 0 : n[0]) || 0;
|
|
550
|
+
_ = B.timeWithoutPenaltySecs() - r / 1e3, x = !0, T.sendMessage("RESUME_REPEATABLE_ROUND", t({ events: e.events.map((e) => [...e]) }, e.puzzleKey ? { puzzleKey: e.puzzleKey } : {}));
|
|
529
551
|
},
|
|
530
552
|
inProgress: () => {
|
|
531
553
|
let e = a == null ? void 0 : a.repeatableOpenRound;
|
|
@@ -538,21 +560,21 @@ const D = (r = {}) => {
|
|
|
538
560
|
},
|
|
539
561
|
log: (...e) => {
|
|
540
562
|
e.length && (T.sendMessage("APPEND_REPEATABLE_ROUND_LOG", {
|
|
541
|
-
from:
|
|
563
|
+
from: b,
|
|
542
564
|
events: e.map((e) => [...e])
|
|
543
|
-
}),
|
|
565
|
+
}), b += e.length);
|
|
544
566
|
}
|
|
545
567
|
},
|
|
546
568
|
table: { updateGameState: (e, n) => {
|
|
547
|
-
T.sendMessage("UPDATE_TABLE_GAME_STATE", t({ inputString: e }, (n == null ? void 0 : n.puzzleString) === void 0 ? {} : { puzzleString: n.puzzleString }));
|
|
569
|
+
v = t({ inputString: e }, n != null && n.stat ? { stat: n.stat } : {}), T.sendMessage("UPDATE_TABLE_GAME_STATE", t(t({ inputString: e }, (n == null ? void 0 : n.puzzleString) === void 0 ? {} : { puzzleString: n.puzzleString }), {}, { status: K(n == null ? void 0 : n.stat) }));
|
|
548
570
|
} },
|
|
549
571
|
requestPuzzle: (e) => new Promise((t, n) => {
|
|
550
|
-
let r = `puzzle-${++
|
|
551
|
-
|
|
572
|
+
let r = `puzzle-${++ie}`, i = setTimeout(() => {
|
|
573
|
+
X.delete(r) && n(/* @__PURE__ */ Error(`Timeout waiting for PUZZLE_DATA after ${E}ms`));
|
|
552
574
|
}, E), a = (e) => (t) => {
|
|
553
575
|
clearTimeout(i), e(t);
|
|
554
576
|
};
|
|
555
|
-
|
|
577
|
+
X.set(r, {
|
|
556
578
|
resolve: a(t),
|
|
557
579
|
reject: a(n)
|
|
558
580
|
}), T.sendMessage("REQUEST_PUZZLE", {
|
|
@@ -571,9 +593,9 @@ const D = (r = {}) => {
|
|
|
571
593
|
console.warn("[Puzzmo SDK] confirm() was answered no: this host draws no confirm dialog, check canConfirm() first"), t(!1);
|
|
572
594
|
return;
|
|
573
595
|
}
|
|
574
|
-
|
|
575
|
-
let r = `confirm-${++
|
|
576
|
-
|
|
596
|
+
Z == null || Z.resolve(!1);
|
|
597
|
+
let r = `confirm-${++ae}`;
|
|
598
|
+
Z = {
|
|
577
599
|
nonce: r,
|
|
578
600
|
resolve: t
|
|
579
601
|
};
|
|
@@ -597,9 +619,9 @@ const D = (r = {}) => {
|
|
|
597
619
|
},
|
|
598
620
|
set: (e, t = 1) => {
|
|
599
621
|
let n = new TextEncoder().encode(e).length;
|
|
600
|
-
if (n >
|
|
622
|
+
if (n > k) throw Error(`[sdk.storage] State is ${n} bytes, over the ${k} byte cap`);
|
|
601
623
|
if (!Number.isInteger(t) || t < 1) throw Error("[sdk.storage] stateVersion must be a positive integer");
|
|
602
|
-
a && !a.repeatable && !
|
|
624
|
+
a && !a.repeatable && !C && (C = !0, console.warn("[sdk.storage] Only repeat play saves storage for now; this write lasts until the page reloads")), h = {
|
|
603
625
|
state: e,
|
|
604
626
|
stateVersion: t
|
|
605
627
|
}, T.sendMessage("UPDATE_GAME_USER_STATE", {
|
|
@@ -610,7 +632,7 @@ const D = (r = {}) => {
|
|
|
610
632
|
},
|
|
611
633
|
settings: {
|
|
612
634
|
initialize: (e) => {
|
|
613
|
-
let n =
|
|
635
|
+
let n = te(e, ee(a));
|
|
614
636
|
P = n.components, F = n.locked, N = t(t({}, O(P)), N);
|
|
615
637
|
let r = I();
|
|
616
638
|
return T.sendMessage("INITIALIZE_SETTINGS", {
|
|
@@ -658,7 +680,7 @@ function O(e) {
|
|
|
658
680
|
return t;
|
|
659
681
|
}
|
|
660
682
|
/** The settings overrides an embed's host context holds for this game, under the game's slug */
|
|
661
|
-
function
|
|
683
|
+
function ee(e) {
|
|
662
684
|
var t, n;
|
|
663
685
|
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;
|
|
664
686
|
if (!r || !i) return [];
|
|
@@ -669,7 +691,7 @@ function k(e) {
|
|
|
669
691
|
* Applies an embed's overrides to the components they match by `id`, recursing into split groups.
|
|
670
692
|
* `omit` marks the component `hidden`, and `locked` holds the value each omitted setting is kept at.
|
|
671
693
|
*/
|
|
672
|
-
function
|
|
694
|
+
function te(n, r) {
|
|
673
695
|
let i = {};
|
|
674
696
|
if (!r.length) return {
|
|
675
697
|
components: n,
|
|
@@ -686,7 +708,7 @@ function A(n, r) {
|
|
|
686
708
|
};
|
|
687
709
|
}
|
|
688
710
|
/** The largest state `sdk.storage.set()` takes, matching the API's cap */
|
|
689
|
-
var
|
|
711
|
+
var k = 64 * 1024;
|
|
690
712
|
/**
|
|
691
713
|
* A standard QWERTY layout with Enter and Backspace — a reasonable default for
|
|
692
714
|
* any game that needs text input. Customize from here by spreading and overriding.
|
|
@@ -699,7 +721,7 @@ var j = 64 * 1024;
|
|
|
699
721
|
* // Extend with dynamic disabled letters
|
|
700
722
|
* sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
|
|
701
723
|
*/
|
|
702
|
-
const
|
|
724
|
+
const A = {
|
|
703
725
|
layout: [
|
|
704
726
|
"qwertyuiop",
|
|
705
727
|
"asdfghjkl",
|
|
@@ -715,7 +737,7 @@ const M = {
|
|
|
715
737
|
xl: [],
|
|
716
738
|
l: ["↵", "⌫"],
|
|
717
739
|
supportsDragCursor: !1
|
|
718
|
-
},
|
|
740
|
+
}, j = (e) => {
|
|
719
741
|
let n = {};
|
|
720
742
|
for (let a of e) for (let e of a.keys) {
|
|
721
743
|
var r, i;
|
|
@@ -725,11 +747,11 @@ const M = {
|
|
|
725
747
|
return n;
|
|
726
748
|
};
|
|
727
749
|
/** Custom error class for workshop import failures */
|
|
728
|
-
var
|
|
750
|
+
var M = class extends Error {
|
|
729
751
|
constructor(e, t, n) {
|
|
730
752
|
super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
|
|
731
753
|
}
|
|
732
754
|
};
|
|
733
|
-
export {
|
|
755
|
+
export { M as EditorImportError, D as createPuzzmoSDK, A as defaultKeyboardConfig, j as keyStylesFromRules };
|
|
734
756
|
|
|
735
757
|
//# sourceMappingURL=index.js.map
|