@puzzmo/sdk 1.0.69 → 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/analytics.d.ts +4 -0
- package/dist/analytics.d.ts.map +1 -1
- 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/gameTracker.d.ts.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 +170 -158
- 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
|
@@ -70,8 +70,9 @@ var s = (e) => {
|
|
|
70
70
|
};
|
|
71
71
|
}();
|
|
72
72
|
const l = (e) => {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
var n;
|
|
74
|
+
let r = {
|
|
75
|
+
context: t(t({}, e), {}, { deviceType: (n = e.deviceType) == null ? u() : n }),
|
|
75
76
|
updateCount: 0,
|
|
76
77
|
startTime: /* @__PURE__ */ new Date(),
|
|
77
78
|
tracked: {
|
|
@@ -82,31 +83,49 @@ const l = (e) => {
|
|
|
82
83
|
}
|
|
83
84
|
};
|
|
84
85
|
return {
|
|
85
|
-
trackEvent: (e,
|
|
86
|
-
let
|
|
86
|
+
trackEvent: (e, t) => {
|
|
87
|
+
let n = ((/* @__PURE__ */ new Date()).getTime() - r.startTime.getTime()) / 1e3;
|
|
87
88
|
switch (e) {
|
|
88
89
|
case "READY_GAME_LOADED":
|
|
89
|
-
|
|
90
|
+
r.tracked.pageView || (c(r.context, "page_view"), r.tracked.pageView = !0);
|
|
90
91
|
break;
|
|
91
92
|
case "UPLOAD_NEW_GAME_STATE":
|
|
92
|
-
|
|
93
|
+
r.updateCount++, r.updateCount > 2 && !r.tracked.gameplayActive && (c(r.context, "gameplay_active"), r.tracked.gameplayActive = !0), n > 30 && (r.tracked.gameplayActive || (c(r.context, "gameplay_active"), r.tracked.gameplayActive = !0), r.tracked.active30s || (c(r.context, "active_30s"), r.tracked.active30s = !0));
|
|
93
94
|
break;
|
|
94
95
|
case "GAME_COMPLETED":
|
|
95
|
-
!
|
|
96
|
+
!r.tracked.completed && t != null && t.input && (c(r.context, "completed", {}, t.input.elapsedTimeSecs), r.tracked.completed = !0);
|
|
96
97
|
break;
|
|
97
98
|
}
|
|
98
99
|
},
|
|
99
100
|
trackLinkClick: (e) => {
|
|
100
|
-
c(
|
|
101
|
+
c(r.context, "link_click", e);
|
|
101
102
|
}
|
|
102
103
|
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The kind of device the game runs on, judged by the whole device rather than the game's frame. A copy of
|
|
107
|
+
* detectDeviceType in @puzzmo-com/clickhouse/deviceType, kept dependency-free for the published SDK.
|
|
108
|
+
*/
|
|
109
|
+
var u = () => {
|
|
110
|
+
var e, t, n;
|
|
111
|
+
if (typeof navigator > "u" || typeof window > "u") return "unknown";
|
|
112
|
+
let r = navigator.userAgent;
|
|
113
|
+
if (/iPad/.test(r) || /Macintosh/.test(r) && navigator.maxTouchPoints > 1) return "tablet";
|
|
114
|
+
let i = (e = navigator.userAgentData) == null ? void 0 : e.mobile;
|
|
115
|
+
return /iPhone|iPod/.test(r) || i ? "mobile" : /Android/.test(r) ? /Mobile/.test(r) ? "mobile" : "tablet" : /Mobile|Windows Phone/.test(r) ? "mobile" : (t = (n = window).matchMedia) != null && t.call(n, "(pointer: coarse)").matches ? Math.min(screen.width, screen.height) < 600 ? "mobile" : "tablet" : "desktop";
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Build the analytics tracker for a game, or null when analytics shouldn't run
|
|
119
|
+
* (the game doesn't bring its own runtime, no browser, running on localhost, or
|
|
120
|
+
* missing bootstrap data).
|
|
121
|
+
*/
|
|
122
|
+
const d = (e) => {
|
|
123
|
+
if (!_(e)) return null;
|
|
124
|
+
let t = p();
|
|
106
125
|
if (!t.enabled) return null;
|
|
107
|
-
let n =
|
|
126
|
+
let n = m(e, t.apiRoot);
|
|
108
127
|
return n ? l(n) : null;
|
|
109
|
-
},
|
|
128
|
+
}, f = (e) => {
|
|
110
129
|
if (typeof document > "u") return () => {};
|
|
111
130
|
let t = (t) => {
|
|
112
131
|
var n, r;
|
|
@@ -122,7 +141,7 @@ const l = (e) => {
|
|
|
122
141
|
return document.addEventListener("click", t), () => document.removeEventListener("click", t);
|
|
123
142
|
};
|
|
124
143
|
/** Picks the events endpoint, and disables analytics entirely on localhost (dev + simulator). */
|
|
125
|
-
var
|
|
144
|
+
var p = () => {
|
|
126
145
|
if (typeof window > "u" || !window.location) return {
|
|
127
146
|
apiRoot: "",
|
|
128
147
|
enabled: !1
|
|
@@ -137,40 +156,40 @@ var f = () => {
|
|
|
137
156
|
};
|
|
138
157
|
};
|
|
139
158
|
/** Derive the analytics context from the host's bootstrap data, or null if a game isn't present. */
|
|
140
|
-
const
|
|
159
|
+
const m = (e, t) => {
|
|
141
160
|
var n, r, i, a, o, s, c, l;
|
|
142
161
|
let u = e == null ? void 0 : e.session;
|
|
143
162
|
if (!u) return null;
|
|
144
|
-
let d = u.gameplay, f = u.puzzle, p = (n = e == null ? void 0 : e.hostContext) == null ? [] : n,
|
|
163
|
+
let d = u.gameplay, f = u.puzzle, p = (n = e == null ? void 0 : e.hostContext) == null ? [] : n, m = p.find((e) => (e == null ? void 0 : e.type) === "embed");
|
|
145
164
|
return {
|
|
146
165
|
gameSlug: (e == null || (r = e.game) == null ? void 0 : r.slug) || "unknown",
|
|
147
166
|
puzzleID: f.id,
|
|
148
167
|
gameplayOwnerID: d.ownerID || (e == null || (i = e.userState) == null ? void 0 : i.id) || "unknown",
|
|
149
168
|
apiRoot: t,
|
|
150
|
-
userType:
|
|
151
|
-
runtimeType:
|
|
169
|
+
userType: h(e == null || (a = e.currentUser) == null ? void 0 : a.type),
|
|
170
|
+
runtimeType: v(p),
|
|
152
171
|
userID: e == null || (o = e.currentUser) == null ? void 0 : o.id,
|
|
153
172
|
teamSlug: ((s = f.team) == null ? void 0 : s.slug) || void 0,
|
|
154
|
-
partnerSlug: (
|
|
173
|
+
partnerSlug: (m == null || (c = m.partner) == null ? void 0 : c.slug) || (e == null ? void 0 : e.partnerSlug) || void 0,
|
|
155
174
|
dailyDateKey: (l = f.mostRecentDaily) == null || (l = l.daily) == null ? void 0 : l.dateKey,
|
|
156
|
-
embedID: (
|
|
175
|
+
embedID: (m == null ? void 0 : m.embedID) || void 0
|
|
157
176
|
};
|
|
158
177
|
};
|
|
159
178
|
/** Map the user's subscription tier to the analytics user bucket. */
|
|
160
|
-
var
|
|
179
|
+
var h = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", g = 512, _ = (e) => {
|
|
161
180
|
var t, n;
|
|
162
|
-
return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) &
|
|
163
|
-
},
|
|
181
|
+
return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) & g) === g;
|
|
182
|
+
}, v = (e) => {
|
|
164
183
|
let t = e.find((e) => (e == null ? void 0 : e.type) === "embed");
|
|
165
184
|
if (t) return t.host === "msn" ? "msn" : "iframe";
|
|
166
185
|
let n = e.find((e) => (e == null ? void 0 : e.type) === "app");
|
|
167
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";
|
|
168
|
-
},
|
|
169
|
-
function
|
|
187
|
+
}, y = ["inputString"];
|
|
188
|
+
function b(e) {
|
|
170
189
|
let t = e >= 3600 * 1e3;
|
|
171
190
|
return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
|
|
172
191
|
}
|
|
173
|
-
function
|
|
192
|
+
function x(e = 0, t = 0) {
|
|
174
193
|
let n = e, r = t, i = 0, a, o, s, c = () => {
|
|
175
194
|
var e;
|
|
176
195
|
if (o === void 0) return n + r;
|
|
@@ -217,11 +236,11 @@ function b(e = 0, t = 0) {
|
|
|
217
236
|
isRunning: () => o !== void 0 && s === void 0,
|
|
218
237
|
display: () => {
|
|
219
238
|
let e = c() - r;
|
|
220
|
-
return [
|
|
239
|
+
return [b(Math.max(0, e)), r === 0 ? "" : b(r)];
|
|
221
240
|
}
|
|
222
241
|
};
|
|
223
242
|
}
|
|
224
|
-
function
|
|
243
|
+
function S() {
|
|
225
244
|
let e = /* @__PURE__ */ new Map();
|
|
226
245
|
return typeof window < "u" && window.addEventListener("message", (t) => {
|
|
227
246
|
var n;
|
|
@@ -251,13 +270,12 @@ function x() {
|
|
|
251
270
|
};
|
|
252
271
|
}
|
|
253
272
|
/**
|
|
254
|
-
* The host<->game contract this SDK
|
|
255
|
-
*
|
|
256
|
-
* 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.
|
|
257
275
|
*/
|
|
258
|
-
var
|
|
276
|
+
var C = "1.1", w = S();
|
|
259
277
|
/** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
|
|
260
|
-
const
|
|
278
|
+
const T = (r = {}) => {
|
|
261
279
|
var i;
|
|
262
280
|
let a = null, s = null, c = () => {
|
|
263
281
|
var e;
|
|
@@ -265,7 +283,7 @@ const w = (r = {}) => {
|
|
|
265
283
|
}, l = () => {
|
|
266
284
|
var e, t;
|
|
267
285
|
return (e = (t = c()) == null ? void 0 : t.id) == null ? null : e;
|
|
268
|
-
},
|
|
286
|
+
}, u = () => {
|
|
269
287
|
var e, t;
|
|
270
288
|
return (e = a == null || (t = a.session) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
|
|
271
289
|
}, p = () => {
|
|
@@ -277,42 +295,47 @@ const w = (r = {}) => {
|
|
|
277
295
|
}, h = () => {
|
|
278
296
|
var e, t;
|
|
279
297
|
return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
|
|
280
|
-
}, g =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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();
|
|
309
|
+
w.sendMessage("TIMER_TICK", { display: [e, t] });
|
|
310
|
+
}, 500), A = setInterval(() => {
|
|
311
|
+
O.isPaused() || w.sendMessage("TIMER_SYNC", Math.floor(O.timeWithoutPenaltySecs()));
|
|
289
312
|
}, 1e4));
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
},
|
|
293
|
-
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);
|
|
294
317
|
n && n.forEach((e) => e(t));
|
|
295
318
|
};
|
|
296
|
-
|
|
297
|
-
|
|
319
|
+
w.onMessage("START_GAME", () => {
|
|
320
|
+
O._init(), j(), N("start");
|
|
298
321
|
});
|
|
299
|
-
let
|
|
300
|
-
let e =
|
|
301
|
-
|
|
302
|
-
},
|
|
303
|
-
let e =
|
|
304
|
-
|
|
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");
|
|
305
328
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}),
|
|
309
|
-
|
|
310
|
-
}),
|
|
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");
|
|
333
|
+
}), w.onMessage("READY_DATA", (e) => {
|
|
311
334
|
var t;
|
|
312
335
|
let n = o(e);
|
|
313
336
|
a = n;
|
|
314
337
|
let r = (t = n.session) == null ? void 0 : t.gameplay;
|
|
315
|
-
if (
|
|
338
|
+
if (b === null) {
|
|
316
339
|
var i, c;
|
|
317
340
|
let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
|
|
318
341
|
if (typeof t == "string") try {
|
|
@@ -320,142 +343,131 @@ const w = (r = {}) => {
|
|
|
320
343
|
} catch (e) {
|
|
321
344
|
t = null;
|
|
322
345
|
}
|
|
323
|
-
|
|
346
|
+
b = (c = t) == null ? {} : c;
|
|
324
347
|
}
|
|
325
348
|
if (r) {
|
|
326
|
-
var l,
|
|
327
|
-
let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((
|
|
328
|
-
|
|
349
|
+
var l, u;
|
|
350
|
+
let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((u = r.additionalTimeAddedSecs) == null ? 0 : u) * 1e3;
|
|
351
|
+
O._reset(e, t);
|
|
329
352
|
}
|
|
330
|
-
if (!
|
|
353
|
+
if (!S) {
|
|
331
354
|
var p;
|
|
332
|
-
|
|
355
|
+
S = d(n), T = (p = r == null ? void 0 : r.completed) == null ? !1 : p, S && f((e) => S.trackLinkClick(e));
|
|
333
356
|
}
|
|
334
357
|
s && (s(n), s = null);
|
|
335
358
|
});
|
|
336
|
-
let
|
|
337
|
-
timeMs: () =>
|
|
338
|
-
timeSecs: () =>
|
|
339
|
-
addedTimeMs: () =>
|
|
340
|
-
addedTimeSecs: () =>
|
|
341
|
-
timeWithoutPenaltySecs: () =>
|
|
342
|
-
display: () =>
|
|
343
|
-
addPenalty: (e) =>
|
|
344
|
-
setPenalty: (e) =>
|
|
345
|
-
isPaused: () =>
|
|
346
|
-
isRunning: () =>
|
|
347
|
-
pause:
|
|
348
|
-
resume:
|
|
349
|
-
},
|
|
350
|
-
send: (e, t) =>
|
|
351
|
-
on: (e, t) =>
|
|
352
|
-
timer:
|
|
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 = {
|
|
373
|
+
send: (e, t) => w.sendMessage(e, t),
|
|
374
|
+
on: (e, t) => w.onMessage(e, t),
|
|
375
|
+
timer: I,
|
|
353
376
|
bootstrap: () => a
|
|
354
|
-
},
|
|
355
|
-
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);
|
|
356
379
|
return {
|
|
357
|
-
timer:
|
|
358
|
-
plugins:
|
|
380
|
+
timer: I,
|
|
381
|
+
plugins: R,
|
|
359
382
|
gameReady: function() {
|
|
360
383
|
var e = n(function* () {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
let e =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
completed: h(),
|
|
370
|
-
readyData: a
|
|
371
|
-
};
|
|
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
|
+
});
|
|
372
392
|
}
|
|
373
|
-
let
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}, t);
|
|
378
|
-
});
|
|
379
|
-
let n = f();
|
|
380
|
-
if (!n) throw Error("READY_DATA received but no puzzle data found");
|
|
381
|
-
let i = p();
|
|
382
|
-
return {
|
|
383
|
-
puzzleString: n,
|
|
384
|
-
inputString: i,
|
|
385
|
-
boardState: i,
|
|
393
|
+
let n = p();
|
|
394
|
+
return t(t({}, {
|
|
395
|
+
puzzleString: u(),
|
|
396
|
+
inputString: n,
|
|
386
397
|
theme: m(),
|
|
387
398
|
completed: h(),
|
|
388
399
|
readyData: a
|
|
389
|
-
};
|
|
400
|
+
}), {}, { boardState: n });
|
|
390
401
|
});
|
|
391
402
|
return function() {
|
|
392
403
|
return e.apply(this, arguments);
|
|
393
404
|
};
|
|
394
405
|
}(),
|
|
395
406
|
gameLoaded: (e = {}) => {
|
|
396
|
-
|
|
407
|
+
w.sendMessage("READY_GAME_LOADED", {
|
|
397
408
|
state: e,
|
|
398
|
-
gameRuntimeContract:
|
|
409
|
+
gameRuntimeContract: C,
|
|
399
410
|
embedRuntimeContract: "1.0"
|
|
400
|
-
}),
|
|
411
|
+
}), D("READY_GAME_LOADED");
|
|
401
412
|
},
|
|
402
|
-
on: (e, t) => (
|
|
413
|
+
on: (e, t) => (v.has(e) || v.set(e, /* @__PURE__ */ new Set()), v.get(e).add(t), () => {
|
|
403
414
|
var n;
|
|
404
|
-
(n =
|
|
415
|
+
(n = v.get(e)) == null || n.delete(t);
|
|
405
416
|
}),
|
|
406
417
|
off: (e, t) => {
|
|
407
418
|
var n;
|
|
408
|
-
(n =
|
|
419
|
+
(n = v.get(e)) == null || n.delete(t);
|
|
409
420
|
},
|
|
410
421
|
updateGameState: (e, t) => {
|
|
411
422
|
var n, r;
|
|
412
423
|
let i = l();
|
|
413
|
-
i
|
|
424
|
+
if (!i) return _("updateGameState");
|
|
425
|
+
w.sendMessage("UPLOAD_NEW_GAME_STATE", {
|
|
414
426
|
id: i,
|
|
415
427
|
input: {
|
|
416
428
|
boardState: e,
|
|
417
|
-
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ?
|
|
418
|
-
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,
|
|
419
431
|
collabUserReferences: []
|
|
420
432
|
}
|
|
421
|
-
}),
|
|
433
|
+
}), D("UPLOAD_NEW_GAME_STATE");
|
|
422
434
|
},
|
|
423
435
|
gameCompleted: (n, r) => {
|
|
424
|
-
var i,
|
|
425
|
-
|
|
426
|
-
let { inputString:
|
|
427
|
-
boardState:
|
|
428
|
-
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ?
|
|
429
|
-
additionalTimeAddedSecs: (
|
|
430
|
-
}),
|
|
431
|
-
|
|
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({
|
|
432
444
|
id: "points",
|
|
433
445
|
value: n.pointsAwarded
|
|
434
|
-
}),
|
|
446
|
+
}), p.push({
|
|
435
447
|
id: "time",
|
|
436
|
-
value: Math.round((
|
|
448
|
+
value: Math.round((c = f.elapsedTimeSecs) == null ? 0 : c) + Math.round((u = f.additionalTimeAddedSecs) == null ? 0 : u)
|
|
437
449
|
});
|
|
438
|
-
let
|
|
439
|
-
|
|
440
|
-
id:
|
|
441
|
-
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,
|
|
442
454
|
config: r
|
|
443
|
-
}),
|
|
455
|
+
}), D("GAME_COMPLETED", { input: f })) : _("gameCompleted");
|
|
444
456
|
},
|
|
445
457
|
showCompletionScreen: (e) => {
|
|
446
|
-
|
|
458
|
+
w.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
|
|
447
459
|
results: e,
|
|
448
460
|
showRetry: !0
|
|
449
461
|
});
|
|
450
462
|
},
|
|
451
463
|
hitCheckpoint: (e, t, n) => {
|
|
452
464
|
var r;
|
|
453
|
-
if (!l()) return;
|
|
465
|
+
if (!l()) return _("hitCheckpoint");
|
|
454
466
|
let i = (r = p()) == null ? "" : r, a = {
|
|
455
|
-
elapsedTimeSecs:
|
|
456
|
-
additionalTimeAddedSecs:
|
|
467
|
+
elapsedTimeSecs: O.timeWithoutPenaltySecs(),
|
|
468
|
+
additionalTimeAddedSecs: O.addedTimeSecs()
|
|
457
469
|
};
|
|
458
|
-
|
|
470
|
+
w.sendMessage("HIT_CHECKPOINT", {
|
|
459
471
|
checkpointName: e,
|
|
460
472
|
gameplay: {
|
|
461
473
|
inputStr: i,
|
|
@@ -466,22 +478,22 @@ const w = (r = {}) => {
|
|
|
466
478
|
});
|
|
467
479
|
},
|
|
468
480
|
settings: {
|
|
469
|
-
initialize: (e) => (
|
|
481
|
+
initialize: (e) => (b = t(t({}, E(e)), b), w.sendMessage("INITIALIZE_SETTINGS", {
|
|
470
482
|
components: e,
|
|
471
|
-
settings:
|
|
472
|
-
}),
|
|
483
|
+
settings: b
|
|
484
|
+
}), b),
|
|
473
485
|
get: () => {
|
|
474
486
|
var e;
|
|
475
|
-
return (e =
|
|
487
|
+
return (e = b) == null ? {} : e;
|
|
476
488
|
},
|
|
477
|
-
update: (e) => (
|
|
489
|
+
update: (e) => (b = t(t({}, b), e), w.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: b }), b)
|
|
478
490
|
},
|
|
479
491
|
keyboard: {
|
|
480
492
|
show: (e) => {
|
|
481
|
-
|
|
493
|
+
w.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
|
|
482
494
|
},
|
|
483
495
|
hide: () => {
|
|
484
|
-
|
|
496
|
+
w.sendMessage("KEYBOARD_UPDATE_CONFIG", {
|
|
485
497
|
layout: [],
|
|
486
498
|
symbols: {},
|
|
487
499
|
highlight: [],
|
|
@@ -494,18 +506,18 @@ const w = (r = {}) => {
|
|
|
494
506
|
},
|
|
495
507
|
haptics: { play: (e, t) => {
|
|
496
508
|
var n;
|
|
497
|
-
|
|
509
|
+
w.sendMessage("SENSORY_EVENT", {
|
|
498
510
|
id: (n = t == null ? void 0 : t.id) == null ? e : n,
|
|
499
511
|
haptic: e
|
|
500
512
|
});
|
|
501
513
|
} },
|
|
502
|
-
_hostAPI:
|
|
514
|
+
_hostAPI: w
|
|
503
515
|
};
|
|
504
516
|
};
|
|
505
517
|
/** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
|
|
506
|
-
function
|
|
518
|
+
function E(e) {
|
|
507
519
|
let t = {};
|
|
508
|
-
for (let n of e) n.type === "split" ? Object.assign(t,
|
|
520
|
+
for (let n of e) n.type === "split" ? Object.assign(t, E(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
|
|
509
521
|
return t;
|
|
510
522
|
}
|
|
511
523
|
/**
|
|
@@ -520,7 +532,7 @@ function T(e) {
|
|
|
520
532
|
* // Extend with dynamic disabled letters
|
|
521
533
|
* sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
|
|
522
534
|
*/
|
|
523
|
-
const
|
|
535
|
+
const D = {
|
|
524
536
|
layout: [
|
|
525
537
|
"qwertyuiop",
|
|
526
538
|
"asdfghjkl",
|
|
@@ -536,7 +548,7 @@ const E = {
|
|
|
536
548
|
xl: [],
|
|
537
549
|
l: ["↵", "⌫"],
|
|
538
550
|
supportsDragCursor: !1
|
|
539
|
-
},
|
|
551
|
+
}, O = (e) => {
|
|
540
552
|
let n = {};
|
|
541
553
|
for (let a of e) for (let e of a.keys) {
|
|
542
554
|
var r, i;
|
|
@@ -546,11 +558,11 @@ const E = {
|
|
|
546
558
|
return n;
|
|
547
559
|
};
|
|
548
560
|
/** Custom error class for workshop import failures */
|
|
549
|
-
var
|
|
561
|
+
var k = class extends Error {
|
|
550
562
|
constructor(e, t, n) {
|
|
551
563
|
super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
|
|
552
564
|
}
|
|
553
565
|
};
|
|
554
|
-
export {
|
|
566
|
+
export { k as EditorImportError, T as createPuzzmoSDK, D as defaultKeyboardConfig, O as keyStylesFromRules };
|
|
555
567
|
|
|
556
568
|
//# sourceMappingURL=index.js.map
|