@puzzmo/sdk 1.0.70 → 1.0.71
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/bootstrapPayload.spec.d.ts +2 -0
- package/dist/bootstrapPayload.spec.d.ts.map +1 -0
- package/dist/{createSimulator-DUZOd1Hx.js → createSimulator-treFHkmV.js} +19 -18
- package/dist/{createSimulator-DUZOd1Hx.js.map → createSimulator-treFHkmV.js.map} +1 -1
- package/dist/{createSimulator-Ce3StrQI.cjs → createSimulator-uk8H5md8.cjs} +2 -2
- package/dist/{createSimulator-Ce3StrQI.cjs.map → createSimulator-uk8H5md8.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +100 -107
- package/dist/index.js.map +1 -1
- package/dist/pico8/index.cjs.map +1 -1
- package/dist/pico8/index.d.ts +2 -2
- package/dist/pico8/index.d.ts.map +1 -1
- package/dist/pico8/index.js.map +1 -1
- package/dist/sdk.d.ts +13 -6
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.session.spec.d.ts +2 -0
- package/dist/sdk.session.spec.d.ts.map +1 -0
- 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/simulator/types.d.ts +5 -0
- package/dist/simulator/types.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +5 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -270,11 +270,10 @@ function S() {
|
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
|
-
* The host<->game contract this SDK
|
|
274
|
-
*
|
|
275
|
-
* sees a contract it doesn't know.
|
|
273
|
+
* The host<->game contract this SDK speaks, declared in READY and READY_GAME_LOADED: games read
|
|
274
|
+
* `game` and `session`, and handle `session` being absent. Hosts on "1.0" always send a session.
|
|
276
275
|
*/
|
|
277
|
-
var C = "1.
|
|
276
|
+
var C = "1.1", w = S();
|
|
278
277
|
/** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
|
|
279
278
|
const T = (r = {}) => {
|
|
280
279
|
var i;
|
|
@@ -296,42 +295,47 @@ const T = (r = {}) => {
|
|
|
296
295
|
}, h = () => {
|
|
297
296
|
var e, t;
|
|
298
297
|
return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
|
|
299
|
-
}, g =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
298
|
+
}, g = !1, _ = (e) => {
|
|
299
|
+
if (g) return;
|
|
300
|
+
g = !0;
|
|
301
|
+
let t = a ? "the host sent no play session, so there is no gameplay to save to" : "it was called before gameReady() resolved";
|
|
302
|
+
console.warn(`[Puzzmo SDK] ${e}() was ignored: ${t}`);
|
|
303
|
+
}, v = /* @__PURE__ */ new Map(), b = null, S = null, T = !1, D = (e, t) => {
|
|
304
|
+
T || S == null || S.trackEvent(e, t);
|
|
305
|
+
}, O = x(), k = null, A = null, j = () => {
|
|
306
|
+
k || (k = setInterval(() => {
|
|
307
|
+
if (O.isPaused()) return;
|
|
308
|
+
let [e, t] = O.display();
|
|
305
309
|
w.sendMessage("TIMER_TICK", { display: [e, t] });
|
|
306
|
-
}, 500),
|
|
307
|
-
|
|
310
|
+
}, 500), A = setInterval(() => {
|
|
311
|
+
O.isPaused() || w.sendMessage("TIMER_SYNC", Math.floor(O.timeWithoutPenaltySecs()));
|
|
308
312
|
}, 1e4));
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
},
|
|
312
|
-
let n =
|
|
313
|
+
}, M = () => {
|
|
314
|
+
k && (clearInterval(k), k = null), A && (clearInterval(A), A = null);
|
|
315
|
+
}, N = (e, t) => {
|
|
316
|
+
let n = v.get(e);
|
|
313
317
|
n && n.forEach((e) => e(t));
|
|
314
318
|
};
|
|
315
319
|
w.onMessage("START_GAME", () => {
|
|
316
|
-
|
|
320
|
+
O._init(), j(), N("start");
|
|
317
321
|
});
|
|
318
|
-
let
|
|
319
|
-
let e =
|
|
320
|
-
|
|
321
|
-
},
|
|
322
|
-
let e =
|
|
323
|
-
|
|
322
|
+
let P = () => {
|
|
323
|
+
let e = O.isPaused();
|
|
324
|
+
O._pause(), O.isPaused() !== e && N("pause");
|
|
325
|
+
}, F = () => {
|
|
326
|
+
let e = O.isPaused();
|
|
327
|
+
O._resume(), O.isPaused() !== e && N("resume");
|
|
324
328
|
};
|
|
325
|
-
w.onMessage("PAUSE_GAME",
|
|
326
|
-
|
|
327
|
-
}), w.onMessage("KEYBOARD_KEY_PRESS", (e) =>
|
|
328
|
-
|
|
329
|
+
w.onMessage("PAUSE_GAME", P), w.onMessage("RESUME_GAME", F), w.onMessage("SETTINGS_UPDATE", (e) => {
|
|
330
|
+
b = t(t({}, b), e), N("settingsUpdate", b);
|
|
331
|
+
}), w.onMessage("KEYBOARD_KEY_PRESS", (e) => N("keyboardKeyPress", e)), w.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => N("keyboardCursorChange", e)), w.onMessage("KEYBOARD_CURSOR_END", () => N("keyboardCursorEnd")), w.onMessage("RETRY_PUZZLE", () => {
|
|
332
|
+
O._reset(), M(), N("retry");
|
|
329
333
|
}), w.onMessage("READY_DATA", (e) => {
|
|
330
334
|
var t;
|
|
331
335
|
let n = o(e);
|
|
332
336
|
a = n;
|
|
333
337
|
let r = (t = n.session) == null ? void 0 : t.gameplay;
|
|
334
|
-
if (
|
|
338
|
+
if (b === null) {
|
|
335
339
|
var i, c;
|
|
336
340
|
let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
|
|
337
341
|
if (typeof t == "string") try {
|
|
@@ -339,73 +343,61 @@ const T = (r = {}) => {
|
|
|
339
343
|
} catch (e) {
|
|
340
344
|
t = null;
|
|
341
345
|
}
|
|
342
|
-
|
|
346
|
+
b = (c = t) == null ? {} : c;
|
|
343
347
|
}
|
|
344
348
|
if (r) {
|
|
345
349
|
var l, u;
|
|
346
350
|
let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((u = r.additionalTimeAddedSecs) == null ? 0 : u) * 1e3;
|
|
347
|
-
|
|
351
|
+
O._reset(e, t);
|
|
348
352
|
}
|
|
349
|
-
if (!
|
|
353
|
+
if (!S) {
|
|
350
354
|
var p;
|
|
351
|
-
|
|
355
|
+
S = d(n), T = (p = r == null ? void 0 : r.completed) == null ? !1 : p, S && f((e) => S.trackLinkClick(e));
|
|
352
356
|
}
|
|
353
357
|
s && (s(n), s = null);
|
|
354
358
|
});
|
|
355
|
-
let
|
|
356
|
-
timeMs: () =>
|
|
357
|
-
timeSecs: () =>
|
|
358
|
-
addedTimeMs: () =>
|
|
359
|
-
addedTimeSecs: () =>
|
|
360
|
-
timeWithoutPenaltySecs: () =>
|
|
361
|
-
display: () =>
|
|
362
|
-
addPenalty: (e) =>
|
|
363
|
-
setPenalty: (e) =>
|
|
364
|
-
isPaused: () =>
|
|
365
|
-
isRunning: () =>
|
|
366
|
-
pause:
|
|
367
|
-
resume:
|
|
368
|
-
},
|
|
359
|
+
let I = {
|
|
360
|
+
timeMs: () => O.timeMs(),
|
|
361
|
+
timeSecs: () => O.timeSecs(),
|
|
362
|
+
addedTimeMs: () => O.addedTimeMs(),
|
|
363
|
+
addedTimeSecs: () => O.addedTimeSecs(),
|
|
364
|
+
timeWithoutPenaltySecs: () => O.timeWithoutPenaltySecs(),
|
|
365
|
+
display: () => O.display(),
|
|
366
|
+
addPenalty: (e) => O.addPenalty(e),
|
|
367
|
+
setPenalty: (e) => O.setPenalty(e),
|
|
368
|
+
isPaused: () => O.isPaused(),
|
|
369
|
+
isRunning: () => O.isRunning(),
|
|
370
|
+
pause: P,
|
|
371
|
+
resume: F
|
|
372
|
+
}, L = {
|
|
369
373
|
send: (e, t) => w.sendMessage(e, t),
|
|
370
374
|
on: (e, t) => w.onMessage(e, t),
|
|
371
|
-
timer:
|
|
375
|
+
timer: I,
|
|
372
376
|
bootstrap: () => a
|
|
373
|
-
},
|
|
374
|
-
for (let e of (i = r.plugins) == null ? [] : i)
|
|
377
|
+
}, R = {};
|
|
378
|
+
for (let e of (i = r.plugins) == null ? [] : i) R[e.name] = e.setup(L);
|
|
375
379
|
return {
|
|
376
|
-
timer:
|
|
377
|
-
plugins:
|
|
380
|
+
timer: I,
|
|
381
|
+
plugins: R,
|
|
378
382
|
gameReady: function() {
|
|
379
383
|
var e = n(function* () {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
let e =
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
completed: h(),
|
|
389
|
-
readyData: a
|
|
390
|
-
};
|
|
384
|
+
if (w.sendMessage("READY", { runtimeContract: C }), !a) {
|
|
385
|
+
var e;
|
|
386
|
+
let t = (e = r.timeout) == null ? 5e3 : e;
|
|
387
|
+
yield new Promise((e, n) => {
|
|
388
|
+
s = e, setTimeout(() => {
|
|
389
|
+
s && (s = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
|
|
390
|
+
}, t);
|
|
391
|
+
});
|
|
391
392
|
}
|
|
392
|
-
let
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}, t);
|
|
397
|
-
});
|
|
398
|
-
let n = u();
|
|
399
|
-
if (!n) throw Error("READY_DATA received but no puzzle data found");
|
|
400
|
-
let i = p();
|
|
401
|
-
return {
|
|
402
|
-
puzzleString: n,
|
|
403
|
-
inputString: i,
|
|
404
|
-
boardState: i,
|
|
393
|
+
let n = p();
|
|
394
|
+
return t(t({}, {
|
|
395
|
+
puzzleString: u(),
|
|
396
|
+
inputString: n,
|
|
405
397
|
theme: m(),
|
|
406
398
|
completed: h(),
|
|
407
399
|
readyData: a
|
|
408
|
-
};
|
|
400
|
+
}), {}, { boardState: n });
|
|
409
401
|
});
|
|
410
402
|
return function() {
|
|
411
403
|
return e.apply(this, arguments);
|
|
@@ -416,50 +408,51 @@ const T = (r = {}) => {
|
|
|
416
408
|
state: e,
|
|
417
409
|
gameRuntimeContract: C,
|
|
418
410
|
embedRuntimeContract: "1.0"
|
|
419
|
-
}),
|
|
411
|
+
}), D("READY_GAME_LOADED");
|
|
420
412
|
},
|
|
421
|
-
on: (e, t) => (
|
|
413
|
+
on: (e, t) => (v.has(e) || v.set(e, /* @__PURE__ */ new Set()), v.get(e).add(t), () => {
|
|
422
414
|
var n;
|
|
423
|
-
(n =
|
|
415
|
+
(n = v.get(e)) == null || n.delete(t);
|
|
424
416
|
}),
|
|
425
417
|
off: (e, t) => {
|
|
426
418
|
var n;
|
|
427
|
-
(n =
|
|
419
|
+
(n = v.get(e)) == null || n.delete(t);
|
|
428
420
|
},
|
|
429
421
|
updateGameState: (e, t) => {
|
|
430
422
|
var n, r;
|
|
431
423
|
let i = l();
|
|
432
|
-
i
|
|
424
|
+
if (!i) return _("updateGameState");
|
|
425
|
+
w.sendMessage("UPLOAD_NEW_GAME_STATE", {
|
|
433
426
|
id: i,
|
|
434
427
|
input: {
|
|
435
428
|
boardState: e,
|
|
436
|
-
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ?
|
|
437
|
-
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ?
|
|
429
|
+
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? O.timeWithoutPenaltySecs() : n,
|
|
430
|
+
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? O.addedTimeSecs() : r,
|
|
438
431
|
collabUserReferences: []
|
|
439
432
|
}
|
|
440
|
-
}),
|
|
433
|
+
}), D("UPLOAD_NEW_GAME_STATE");
|
|
441
434
|
},
|
|
442
435
|
gameCompleted: (n, r) => {
|
|
443
|
-
var i,
|
|
444
|
-
|
|
445
|
-
let { inputString:
|
|
446
|
-
boardState:
|
|
447
|
-
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ?
|
|
448
|
-
additionalTimeAddedSecs: (
|
|
449
|
-
}),
|
|
450
|
-
|
|
436
|
+
var i, o, s, c, u;
|
|
437
|
+
O._conclude(), M();
|
|
438
|
+
let { inputString: d } = n, f = t(t({}, e(n, y)), {}, {
|
|
439
|
+
boardState: d == null ? n.boardState : d,
|
|
440
|
+
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? O.timeWithoutPenaltySecs() : i,
|
|
441
|
+
additionalTimeAddedSecs: (o = n.additionalTimeAddedSecs) == null ? O.addedTimeSecs() : o
|
|
442
|
+
}), p = (s = r == null ? void 0 : r.deeds) == null ? [] : s;
|
|
443
|
+
p.push({
|
|
451
444
|
id: "points",
|
|
452
445
|
value: n.pointsAwarded
|
|
453
|
-
}),
|
|
446
|
+
}), p.push({
|
|
454
447
|
id: "time",
|
|
455
|
-
value: Math.round((
|
|
448
|
+
value: Math.round((c = f.elapsedTimeSecs) == null ? 0 : c) + Math.round((u = f.additionalTimeAddedSecs) == null ? 0 : u)
|
|
456
449
|
});
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
id:
|
|
460
|
-
input:
|
|
450
|
+
let m = l(), h = a && !a.session && a.appRuntimeContract === "1.1";
|
|
451
|
+
m || h ? (w.sendMessage("GAME_COMPLETED", {
|
|
452
|
+
id: m == null ? void 0 : m,
|
|
453
|
+
input: f,
|
|
461
454
|
config: r
|
|
462
|
-
}),
|
|
455
|
+
}), D("GAME_COMPLETED", { input: f })) : _("gameCompleted");
|
|
463
456
|
},
|
|
464
457
|
showCompletionScreen: (e) => {
|
|
465
458
|
w.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
|
|
@@ -469,10 +462,10 @@ const T = (r = {}) => {
|
|
|
469
462
|
},
|
|
470
463
|
hitCheckpoint: (e, t, n) => {
|
|
471
464
|
var r;
|
|
472
|
-
if (!l()) return;
|
|
465
|
+
if (!l()) return _("hitCheckpoint");
|
|
473
466
|
let i = (r = p()) == null ? "" : r, a = {
|
|
474
|
-
elapsedTimeSecs:
|
|
475
|
-
additionalTimeAddedSecs:
|
|
467
|
+
elapsedTimeSecs: O.timeWithoutPenaltySecs(),
|
|
468
|
+
additionalTimeAddedSecs: O.addedTimeSecs()
|
|
476
469
|
};
|
|
477
470
|
w.sendMessage("HIT_CHECKPOINT", {
|
|
478
471
|
checkpointName: e,
|
|
@@ -485,15 +478,15 @@ const T = (r = {}) => {
|
|
|
485
478
|
});
|
|
486
479
|
},
|
|
487
480
|
settings: {
|
|
488
|
-
initialize: (e) => (
|
|
481
|
+
initialize: (e) => (b = t(t({}, E(e)), b), w.sendMessage("INITIALIZE_SETTINGS", {
|
|
489
482
|
components: e,
|
|
490
|
-
settings:
|
|
491
|
-
}),
|
|
483
|
+
settings: b
|
|
484
|
+
}), b),
|
|
492
485
|
get: () => {
|
|
493
486
|
var e;
|
|
494
|
-
return (e =
|
|
487
|
+
return (e = b) == null ? {} : e;
|
|
495
488
|
},
|
|
496
|
-
update: (e) => (
|
|
489
|
+
update: (e) => (b = t(t({}, b), e), w.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: b }), b)
|
|
497
490
|
},
|
|
498
491
|
keyboard: {
|
|
499
492
|
show: (e) => {
|