@puzzmo/sdk 1.0.60 → 1.0.61
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.d.ts +8 -0
- package/dist/bootstrapPayload.d.ts.map +1 -0
- package/dist/contracts.d.ts +1 -1
- package/dist/{createSimulator-Dory7qUL.js → createSimulator-CdInpCHG.js} +220 -202
- package/dist/{createSimulator-Dory7qUL.js.map → createSimulator-CdInpCHG.js.map} +1 -1
- package/dist/{createSimulator-kGIstLy9.cjs → createSimulator-PNeBoNux.cjs} +22 -22
- package/dist/{createSimulator-kGIstLy9.cjs.map → createSimulator-PNeBoNux.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 +229 -179
- package/dist/index.js.map +1 -1
- package/dist/inputs/index.cjs +1 -1
- package/dist/inputs/index.js +1 -1
- package/dist/pico8/index.cjs +1 -1
- package/dist/pico8/index.js +2 -2
- 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 +99 -50
- package/dist/types.d.ts.map +1 -1
- package/dist/vite.cjs +3 -3
- package/dist/vite.js +26 -26
- package/package.json +1 -1
- /package/dist/{asyncToGenerator-Dn36a-ch.js → asyncToGenerator-BotOOyB7.js} +0 -0
- /package/dist/{asyncToGenerator-DANjdFmB.cjs → asyncToGenerator-DIL7svO7.cjs} +0 -0
- /package/dist/{objectSpread2-C8x7fbpH.js → objectSpread2-BQwrzeNG.js} +0 -0
- /package/dist/{objectSpread2-DLgRiGrq.cjs → objectSpread2-CCAs_T0X.cjs} +0 -0
- /package/dist/{objectWithoutProperties-BVU0RRck.js → objectWithoutProperties-Bjd1IAMi.js} +0 -0
- /package/dist/{objectWithoutProperties-ChRmjIUS.cjs → objectWithoutProperties-Ee8z5QMa.cjs} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,14 +1,60 @@
|
|
|
1
|
-
import { t as e } from "./
|
|
2
|
-
import { t } from "./
|
|
3
|
-
import { t as n } from "./
|
|
4
|
-
var r =
|
|
5
|
-
|
|
1
|
+
import { t as e } from "./objectWithoutProperties-Bjd1IAMi.js";
|
|
2
|
+
import { t } from "./objectSpread2-BQwrzeNG.js";
|
|
3
|
+
import { t as n } from "./asyncToGenerator-BotOOyB7.js";
|
|
4
|
+
var r = ["startOrFindGameplay"], i = ["puzzle"], a = ["game", "viewerMetadata"];
|
|
5
|
+
/**
|
|
6
|
+
* Fills in `game` and `session` when READY_DATA comes from a host which only sends the older
|
|
7
|
+
* `startOrFindGameplay` nesting, so the SDK and games only ever see the new shape. A copy of
|
|
8
|
+
* upgradeBootstrapGameData in @puzzmo-com/shared, which the SDK can't depend on.
|
|
9
|
+
*/
|
|
10
|
+
const o = (n) => {
|
|
11
|
+
var o, c, l;
|
|
12
|
+
let { startOrFindGameplay: u } = n, d = e(n, r);
|
|
13
|
+
if (d.game) return d;
|
|
14
|
+
let f = u == null ? void 0 : u.gamePlayed, p = s((o = f == null || (c = f.puzzle) == null ? void 0 : c.game) == null ? {} : o);
|
|
15
|
+
if (!f) return t(t({}, d), {}, { game: p });
|
|
16
|
+
let { puzzle: m } = f, h = e(f, i), { game: g, viewerMetadata: _ } = m, v = e(m, a);
|
|
17
|
+
return t(t({}, d), {}, {
|
|
18
|
+
game: p,
|
|
19
|
+
session: {
|
|
20
|
+
gameplay: h,
|
|
21
|
+
puzzle: v
|
|
22
|
+
},
|
|
23
|
+
viewerMetadata: (l = d.viewerMetadata) == null ? _ : l
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
/** Builds the game from the flattened fields older hosts put on `puzzle.game`, with no version IDs */
|
|
27
|
+
var s = (e) => {
|
|
28
|
+
var t, n, r, i, a, o, s, c;
|
|
29
|
+
let l = e.flagsArr;
|
|
30
|
+
return {
|
|
31
|
+
id: (t = e.id) == null ? "" : t,
|
|
32
|
+
slug: (n = e.slug) == null ? "" : n,
|
|
33
|
+
stableSlug: (r = (i = e.stableSlug) == null ? e.slug : i) == null ? "" : r,
|
|
34
|
+
displayName: (a = e.displayName) == null ? "" : a,
|
|
35
|
+
version: {
|
|
36
|
+
id: "",
|
|
37
|
+
label: null,
|
|
38
|
+
featuresArr: (o = e.featuresArr) == null ? [0] : o,
|
|
39
|
+
flagsArr: Array.isArray(l) ? l : typeof l == "number" ? [l] : [0],
|
|
40
|
+
runtime: {
|
|
41
|
+
id: "",
|
|
42
|
+
version: e.assetsSha || e.assetsBaseURL ? {
|
|
43
|
+
id: "",
|
|
44
|
+
assetsSha: (s = e.assetsSha) == null ? "" : s,
|
|
45
|
+
assetsBaseURL: (c = e.assetsBaseURL) == null ? "" : c
|
|
46
|
+
} : null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, c = function() {
|
|
51
|
+
var e = n(function* (e, n, r, i) {
|
|
6
52
|
try {
|
|
7
|
-
let a =
|
|
53
|
+
let a = t(t({}, e), {}, {
|
|
8
54
|
eventType: n,
|
|
9
55
|
elapsedTimeOnComplete: i,
|
|
10
56
|
metadata: r
|
|
11
|
-
}), o = yield fetch(`${
|
|
57
|
+
}), o = yield fetch(`${e.apiRoot}events`, {
|
|
12
58
|
method: "POST",
|
|
13
59
|
headers: { "Content-Type": "application/json" },
|
|
14
60
|
body: JSON.stringify(a),
|
|
@@ -19,11 +65,11 @@ var r = function() {
|
|
|
19
65
|
console.warn(`Analytics event error: ${n}`, e);
|
|
20
66
|
}
|
|
21
67
|
});
|
|
22
|
-
return function(
|
|
23
|
-
return
|
|
68
|
+
return function(t, n, r, i) {
|
|
69
|
+
return e.apply(this, arguments);
|
|
24
70
|
};
|
|
25
71
|
}();
|
|
26
|
-
const
|
|
72
|
+
const l = (e) => {
|
|
27
73
|
let t = {
|
|
28
74
|
context: e,
|
|
29
75
|
updateCount: 0,
|
|
@@ -37,30 +83,30 @@ const i = (e) => {
|
|
|
37
83
|
};
|
|
38
84
|
return {
|
|
39
85
|
trackEvent: (e, n) => {
|
|
40
|
-
let
|
|
86
|
+
let r = ((/* @__PURE__ */ new Date()).getTime() - t.startTime.getTime()) / 1e3;
|
|
41
87
|
switch (e) {
|
|
42
88
|
case "READY_GAME_LOADED":
|
|
43
|
-
t.tracked.pageView || (
|
|
89
|
+
t.tracked.pageView || (c(t.context, "page_view"), t.tracked.pageView = !0);
|
|
44
90
|
break;
|
|
45
91
|
case "UPLOAD_NEW_GAME_STATE":
|
|
46
|
-
t.updateCount++, t.updateCount > 2 && !t.tracked.gameplayActive && (
|
|
92
|
+
t.updateCount++, t.updateCount > 2 && !t.tracked.gameplayActive && (c(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), r > 30 && (t.tracked.gameplayActive || (c(t.context, "gameplay_active"), t.tracked.gameplayActive = !0), t.tracked.active30s || (c(t.context, "active_30s"), t.tracked.active30s = !0));
|
|
47
93
|
break;
|
|
48
94
|
case "GAME_COMPLETED":
|
|
49
|
-
!t.tracked.completed && n != null && n.input && (
|
|
95
|
+
!t.tracked.completed && n != null && n.input && (c(t.context, "completed", {}, n.input.elapsedTimeSecs), t.tracked.completed = !0);
|
|
50
96
|
break;
|
|
51
97
|
}
|
|
52
98
|
},
|
|
53
99
|
trackLinkClick: (e) => {
|
|
54
|
-
|
|
100
|
+
c(t.context, "link_click", e);
|
|
55
101
|
}
|
|
56
102
|
};
|
|
57
|
-
},
|
|
58
|
-
if (!
|
|
59
|
-
let t =
|
|
103
|
+
}, u = (e) => {
|
|
104
|
+
if (!g(e)) return null;
|
|
105
|
+
let t = f();
|
|
60
106
|
if (!t.enabled) return null;
|
|
61
|
-
let n =
|
|
62
|
-
return n ?
|
|
63
|
-
},
|
|
107
|
+
let n = p(e, t.apiRoot);
|
|
108
|
+
return n ? l(n) : null;
|
|
109
|
+
}, d = (e) => {
|
|
64
110
|
if (typeof document > "u") return () => {};
|
|
65
111
|
let t = (t) => {
|
|
66
112
|
var n, r;
|
|
@@ -76,7 +122,7 @@ const i = (e) => {
|
|
|
76
122
|
return document.addEventListener("click", t), () => document.removeEventListener("click", t);
|
|
77
123
|
};
|
|
78
124
|
/** Picks the events endpoint, and disables analytics entirely on localhost (dev + simulator). */
|
|
79
|
-
var
|
|
125
|
+
var f = () => {
|
|
80
126
|
if (typeof window > "u" || !window.location) return {
|
|
81
127
|
apiRoot: "",
|
|
82
128
|
enabled: !1
|
|
@@ -89,38 +135,37 @@ var s = () => {
|
|
|
89
135
|
apiRoot: e.includes("staging") ? "https://api-staging.puzzmo.com/" : "https://api.puzzmo.com/",
|
|
90
136
|
enabled: !0
|
|
91
137
|
};
|
|
92
|
-
},
|
|
93
|
-
var n, r, i, a, o, s, c,
|
|
94
|
-
let
|
|
95
|
-
if (!
|
|
96
|
-
let
|
|
138
|
+
}, p = (e, t) => {
|
|
139
|
+
var n, r, i, a, o, s, c, l, u;
|
|
140
|
+
let d = e == null ? void 0 : e.session;
|
|
141
|
+
if (!d) return null;
|
|
142
|
+
let f = d.gameplay, p = d.puzzle, h = (n = e == null ? void 0 : e.hostContext) == null ? [] : n;
|
|
97
143
|
return {
|
|
98
|
-
gameSlug: (
|
|
99
|
-
puzzleID:
|
|
100
|
-
gameplayOwnerID:
|
|
144
|
+
gameSlug: (e == null || (r = e.game) == null ? void 0 : r.slug) || "unknown",
|
|
145
|
+
puzzleID: p.id,
|
|
146
|
+
gameplayOwnerID: f.ownerID || (e == null || (i = e.userState) == null ? void 0 : i.id) || "unknown",
|
|
101
147
|
apiRoot: t,
|
|
102
|
-
userType:
|
|
103
|
-
runtimeType:
|
|
104
|
-
userID: e == null || (
|
|
105
|
-
teamSlug: ((
|
|
106
|
-
partnerSlug: ((
|
|
107
|
-
dailyDateKey: (
|
|
108
|
-
embedID: ((
|
|
148
|
+
userType: m(e == null || (a = e.currentUser) == null ? void 0 : a.type),
|
|
149
|
+
runtimeType: _(h),
|
|
150
|
+
userID: e == null || (o = e.currentUser) == null ? void 0 : o.id,
|
|
151
|
+
teamSlug: ((s = p.team) == null ? void 0 : s.slug) || void 0,
|
|
152
|
+
partnerSlug: ((c = h.find((e) => (e == null ? void 0 : e.type) === "embed")) == null || (c = c.partner) == null ? void 0 : c.slug) || void 0,
|
|
153
|
+
dailyDateKey: (l = p.mostRecentDaily) == null || (l = l.daily) == null ? void 0 : l.dateKey,
|
|
154
|
+
embedID: ((u = h.find((e) => (e == null ? void 0 : e.type) === "embed")) == null ? void 0 : u.embedID) || void 0
|
|
109
155
|
};
|
|
110
|
-
},
|
|
156
|
+
}, m = (e) => !e || e === "Unverified" ? "anon" : e === "Paid" ? "paid" : "user", h = 512, g = (e) => {
|
|
111
157
|
var t, n;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, f = (e) => {
|
|
158
|
+
return (((t = e == null || (n = e.game) == null ? void 0 : n.version.flagsArr[0]) == null ? 0 : t) & h) === h;
|
|
159
|
+
}, _ = (e) => {
|
|
115
160
|
if (e.find((e) => (e == null ? void 0 : e.type) === "embed")) return "iframe";
|
|
116
161
|
let t = e.find((e) => (e == null ? void 0 : e.type) === "app");
|
|
117
162
|
return (t == null ? void 0 : t.host) === "__embed" ? "simple_embed" : (t == null ? void 0 : t.host) === "app-embed" ? "app_embed" : (t == null ? void 0 : t.host) === "ios-app" ? "ios_native" : "puzzmo_com";
|
|
118
|
-
},
|
|
119
|
-
function
|
|
163
|
+
}, v = ["inputString"];
|
|
164
|
+
function y(e) {
|
|
120
165
|
let t = e >= 3600 * 1e3;
|
|
121
166
|
return new Date(e).toISOString().slice(t ? 11 : 14, -1).split(".")[0];
|
|
122
167
|
}
|
|
123
|
-
function
|
|
168
|
+
function b(e = 0, t = 0) {
|
|
124
169
|
let n = e, r = t, i = 0, a, o, s, c = () => {
|
|
125
170
|
var e;
|
|
126
171
|
if (o === void 0) return n + r;
|
|
@@ -167,11 +212,11 @@ function h(e = 0, t = 0) {
|
|
|
167
212
|
isRunning: () => o !== void 0 && s === void 0,
|
|
168
213
|
display: () => {
|
|
169
214
|
let e = c() - r;
|
|
170
|
-
return [
|
|
215
|
+
return [y(Math.max(0, e)), r === 0 ? "" : y(r)];
|
|
171
216
|
}
|
|
172
217
|
};
|
|
173
218
|
}
|
|
174
|
-
function
|
|
219
|
+
function x() {
|
|
175
220
|
let e = /* @__PURE__ */ new Map();
|
|
176
221
|
return typeof window < "u" && window.addEventListener("message", (t) => {
|
|
177
222
|
var n;
|
|
@@ -200,137 +245,142 @@ function g() {
|
|
|
200
245
|
})
|
|
201
246
|
};
|
|
202
247
|
}
|
|
203
|
-
|
|
248
|
+
/**
|
|
249
|
+
* The host<->game contract this SDK is built against, declared in READY and READY_GAME_LOADED.
|
|
250
|
+
* Stays "1.0" until every host supporting "1.1" is deployed: an older puzzmo.com reloads when it
|
|
251
|
+
* sees a contract it doesn't know.
|
|
252
|
+
*/
|
|
253
|
+
var S = "1.0", C = x();
|
|
204
254
|
/** Creates a Puzzmo SDK instance for communicating with the Puzzmo host */
|
|
205
|
-
const
|
|
255
|
+
const w = (r = {}) => {
|
|
206
256
|
var i;
|
|
207
|
-
let
|
|
257
|
+
let a = null, s = null, c = () => {
|
|
208
258
|
var e;
|
|
209
|
-
return
|
|
210
|
-
},
|
|
259
|
+
return a == null || (e = a.session) == null ? void 0 : e.gameplay;
|
|
260
|
+
}, l = () => {
|
|
211
261
|
var e, t;
|
|
212
|
-
return (e = (t =
|
|
213
|
-
}, d = () => {
|
|
214
|
-
var e, t;
|
|
215
|
-
return (e = (t = l()) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
|
|
262
|
+
return (e = (t = c()) == null ? void 0 : t.id) == null ? null : e;
|
|
216
263
|
}, f = () => {
|
|
217
264
|
var e, t;
|
|
218
|
-
return (e = (t =
|
|
265
|
+
return (e = a == null || (t = a.session) == null ? void 0 : t.puzzle.puzzle) == null ? null : e;
|
|
266
|
+
}, p = () => {
|
|
267
|
+
var e, t;
|
|
268
|
+
return (e = (t = c()) == null ? void 0 : t.boardState) == null ? null : e;
|
|
219
269
|
}, m = () => {
|
|
220
270
|
var e;
|
|
221
|
-
return (e =
|
|
222
|
-
},
|
|
271
|
+
return (e = a == null ? void 0 : a.theme) == null ? null : e;
|
|
272
|
+
}, h = () => {
|
|
223
273
|
var e, t;
|
|
224
|
-
return (e = (t =
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
let [e, t] =
|
|
231
|
-
|
|
232
|
-
}, 500),
|
|
233
|
-
|
|
274
|
+
return (e = (t = c()) == null ? void 0 : t.completed) == null ? !1 : e;
|
|
275
|
+
}, g = /* @__PURE__ */ new Map(), _ = null, y = null, x = !1, w = (e, t) => {
|
|
276
|
+
x || y == null || y.trackEvent(e, t);
|
|
277
|
+
}, E = b(), D = null, O = null, k = () => {
|
|
278
|
+
D || (D = setInterval(() => {
|
|
279
|
+
if (E.isPaused()) return;
|
|
280
|
+
let [e, t] = E.display();
|
|
281
|
+
C.sendMessage("TIMER_TICK", { display: [e, t] });
|
|
282
|
+
}, 500), O = setInterval(() => {
|
|
283
|
+
E.isPaused() || C.sendMessage("TIMER_SYNC", Math.floor(E.timeWithoutPenaltySecs()));
|
|
234
284
|
}, 1e4));
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
},
|
|
238
|
-
let n =
|
|
285
|
+
}, A = () => {
|
|
286
|
+
D && (clearInterval(D), D = null), O && (clearInterval(O), O = null);
|
|
287
|
+
}, j = (e, t) => {
|
|
288
|
+
let n = g.get(e);
|
|
239
289
|
n && n.forEach((e) => e(t));
|
|
240
290
|
};
|
|
241
|
-
|
|
242
|
-
|
|
291
|
+
C.onMessage("START_GAME", () => {
|
|
292
|
+
E._init(), k(), j("start");
|
|
243
293
|
});
|
|
244
|
-
let
|
|
245
|
-
let e =
|
|
246
|
-
|
|
247
|
-
},
|
|
248
|
-
let e =
|
|
249
|
-
|
|
294
|
+
let M = () => {
|
|
295
|
+
let e = E.isPaused();
|
|
296
|
+
E._pause(), E.isPaused() !== e && j("pause");
|
|
297
|
+
}, N = () => {
|
|
298
|
+
let e = E.isPaused();
|
|
299
|
+
E._resume(), E.isPaused() !== e && j("resume");
|
|
250
300
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}),
|
|
254
|
-
|
|
255
|
-
}),
|
|
301
|
+
C.onMessage("PAUSE_GAME", M), C.onMessage("RESUME_GAME", N), C.onMessage("SETTINGS_UPDATE", (e) => {
|
|
302
|
+
_ = t(t({}, _), e), j("settingsUpdate", _);
|
|
303
|
+
}), C.onMessage("KEYBOARD_KEY_PRESS", (e) => j("keyboardKeyPress", e)), C.onMessage("KEYBOARD_CURSOR_CHANGE", (e) => j("keyboardCursorChange", e)), C.onMessage("KEYBOARD_CURSOR_END", () => j("keyboardCursorEnd")), C.onMessage("RETRY_PUZZLE", () => {
|
|
304
|
+
E._reset(), A(), j("retry");
|
|
305
|
+
}), C.onMessage("READY_DATA", (e) => {
|
|
256
306
|
var t;
|
|
257
|
-
let n = e;
|
|
258
|
-
|
|
259
|
-
let r = (t = n.
|
|
260
|
-
if (
|
|
261
|
-
var i,
|
|
262
|
-
let e =
|
|
307
|
+
let n = o(e);
|
|
308
|
+
a = n;
|
|
309
|
+
let r = (t = n.session) == null ? void 0 : t.gameplay;
|
|
310
|
+
if (_ === null) {
|
|
311
|
+
var i, c;
|
|
312
|
+
let e = n.game.slug, t = e ? (i = n.userState) == null || (i = i.gameSettings) == null ? void 0 : i[e] : null;
|
|
263
313
|
if (typeof t == "string") try {
|
|
264
314
|
t = JSON.parse(t);
|
|
265
315
|
} catch (e) {
|
|
266
316
|
t = null;
|
|
267
317
|
}
|
|
268
|
-
|
|
318
|
+
_ = (c = t) == null ? {} : c;
|
|
269
319
|
}
|
|
270
320
|
if (r) {
|
|
271
|
-
var
|
|
272
|
-
let e = ((
|
|
273
|
-
|
|
321
|
+
var l, f;
|
|
322
|
+
let e = ((l = r.elapsedTimeSecs) == null ? 0 : l) * 1e3, t = ((f = r.additionalTimeAddedSecs) == null ? 0 : f) * 1e3;
|
|
323
|
+
E._reset(e, t);
|
|
274
324
|
}
|
|
275
|
-
if (!
|
|
325
|
+
if (!y) {
|
|
276
326
|
var p;
|
|
277
|
-
|
|
327
|
+
y = u(n), x = (p = r == null ? void 0 : r.completed) == null ? !1 : p, y && d((e) => y.trackLinkClick(e));
|
|
278
328
|
}
|
|
279
|
-
|
|
329
|
+
s && (s(n), s = null);
|
|
280
330
|
});
|
|
281
|
-
let
|
|
282
|
-
timeMs: () =>
|
|
283
|
-
timeSecs: () =>
|
|
284
|
-
addedTimeMs: () =>
|
|
285
|
-
addedTimeSecs: () =>
|
|
286
|
-
timeWithoutPenaltySecs: () =>
|
|
287
|
-
display: () =>
|
|
288
|
-
addPenalty: (e) =>
|
|
289
|
-
setPenalty: (e) =>
|
|
290
|
-
isPaused: () =>
|
|
291
|
-
isRunning: () =>
|
|
292
|
-
pause:
|
|
293
|
-
resume:
|
|
294
|
-
},
|
|
295
|
-
send: (e, t) =>
|
|
296
|
-
on: (e, t) =>
|
|
297
|
-
timer:
|
|
298
|
-
bootstrap: () =>
|
|
299
|
-
},
|
|
300
|
-
for (let e of (i = r.plugins) == null ? [] : i)
|
|
331
|
+
let P = {
|
|
332
|
+
timeMs: () => E.timeMs(),
|
|
333
|
+
timeSecs: () => E.timeSecs(),
|
|
334
|
+
addedTimeMs: () => E.addedTimeMs(),
|
|
335
|
+
addedTimeSecs: () => E.addedTimeSecs(),
|
|
336
|
+
timeWithoutPenaltySecs: () => E.timeWithoutPenaltySecs(),
|
|
337
|
+
display: () => E.display(),
|
|
338
|
+
addPenalty: (e) => E.addPenalty(e),
|
|
339
|
+
setPenalty: (e) => E.setPenalty(e),
|
|
340
|
+
isPaused: () => E.isPaused(),
|
|
341
|
+
isRunning: () => E.isRunning(),
|
|
342
|
+
pause: M,
|
|
343
|
+
resume: N
|
|
344
|
+
}, F = {
|
|
345
|
+
send: (e, t) => C.sendMessage(e, t),
|
|
346
|
+
on: (e, t) => C.onMessage(e, t),
|
|
347
|
+
timer: P,
|
|
348
|
+
bootstrap: () => a
|
|
349
|
+
}, I = {};
|
|
350
|
+
for (let e of (i = r.plugins) == null ? [] : i) I[e.name] = e.setup(F);
|
|
301
351
|
return {
|
|
302
|
-
timer:
|
|
303
|
-
plugins:
|
|
352
|
+
timer: P,
|
|
353
|
+
plugins: I,
|
|
304
354
|
gameReady: function() {
|
|
305
|
-
var e =
|
|
355
|
+
var e = n(function* () {
|
|
306
356
|
var e;
|
|
307
|
-
if (
|
|
308
|
-
let e =
|
|
357
|
+
if (C.sendMessage("READY", { runtimeContract: S }), f()) {
|
|
358
|
+
let e = p();
|
|
309
359
|
return {
|
|
310
|
-
puzzleString:
|
|
360
|
+
puzzleString: f(),
|
|
311
361
|
inputString: e,
|
|
312
362
|
boardState: e,
|
|
313
363
|
theme: m(),
|
|
314
|
-
completed:
|
|
315
|
-
readyData:
|
|
364
|
+
completed: h(),
|
|
365
|
+
readyData: a
|
|
316
366
|
};
|
|
317
367
|
}
|
|
318
368
|
let t = (e = r.timeout) == null ? 5e3 : e;
|
|
319
369
|
yield new Promise((e, n) => {
|
|
320
|
-
|
|
321
|
-
|
|
370
|
+
s = e, setTimeout(() => {
|
|
371
|
+
s && (s = null, n(/* @__PURE__ */ Error(`Timeout waiting for READY_DATA after ${t}ms`)));
|
|
322
372
|
}, t);
|
|
323
373
|
});
|
|
324
|
-
let n =
|
|
374
|
+
let n = f();
|
|
325
375
|
if (!n) throw Error("READY_DATA received but no puzzle data found");
|
|
326
|
-
let i =
|
|
376
|
+
let i = p();
|
|
327
377
|
return {
|
|
328
378
|
puzzleString: n,
|
|
329
379
|
inputString: i,
|
|
330
380
|
boardState: i,
|
|
331
381
|
theme: m(),
|
|
332
|
-
completed:
|
|
333
|
-
readyData:
|
|
382
|
+
completed: h(),
|
|
383
|
+
readyData: a
|
|
334
384
|
};
|
|
335
385
|
});
|
|
336
386
|
return function() {
|
|
@@ -338,69 +388,69 @@ const v = (r = {}) => {
|
|
|
338
388
|
};
|
|
339
389
|
}(),
|
|
340
390
|
gameLoaded: (e = {}) => {
|
|
341
|
-
|
|
391
|
+
C.sendMessage("READY_GAME_LOADED", {
|
|
342
392
|
state: e,
|
|
343
|
-
gameRuntimeContract:
|
|
393
|
+
gameRuntimeContract: S,
|
|
344
394
|
embedRuntimeContract: "1.0"
|
|
345
|
-
}),
|
|
395
|
+
}), w("READY_GAME_LOADED");
|
|
346
396
|
},
|
|
347
|
-
on: (e, t) => (
|
|
397
|
+
on: (e, t) => (g.has(e) || g.set(e, /* @__PURE__ */ new Set()), g.get(e).add(t), () => {
|
|
348
398
|
var n;
|
|
349
|
-
(n =
|
|
399
|
+
(n = g.get(e)) == null || n.delete(t);
|
|
350
400
|
}),
|
|
351
401
|
off: (e, t) => {
|
|
352
402
|
var n;
|
|
353
|
-
(n =
|
|
403
|
+
(n = g.get(e)) == null || n.delete(t);
|
|
354
404
|
},
|
|
355
405
|
updateGameState: (e, t) => {
|
|
356
406
|
var n, r;
|
|
357
|
-
let i =
|
|
358
|
-
i && (
|
|
407
|
+
let i = l();
|
|
408
|
+
i && (C.sendMessage("UPLOAD_NEW_GAME_STATE", {
|
|
359
409
|
id: i,
|
|
360
410
|
input: {
|
|
361
411
|
boardState: e,
|
|
362
|
-
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ?
|
|
363
|
-
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ?
|
|
412
|
+
elapsedTimeSecs: (n = t == null ? void 0 : t.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : n,
|
|
413
|
+
additionalTimeAddedSecs: (r = t == null ? void 0 : t.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : r,
|
|
364
414
|
collabUserReferences: []
|
|
365
415
|
}
|
|
366
|
-
}),
|
|
416
|
+
}), w("UPLOAD_NEW_GAME_STATE"));
|
|
367
417
|
},
|
|
368
|
-
gameCompleted: (
|
|
418
|
+
gameCompleted: (n, r) => {
|
|
369
419
|
var i, a, o, s, c;
|
|
370
|
-
|
|
371
|
-
let { inputString:
|
|
372
|
-
boardState:
|
|
373
|
-
elapsedTimeSecs: (i =
|
|
374
|
-
additionalTimeAddedSecs: (a =
|
|
420
|
+
E._conclude(), A();
|
|
421
|
+
let { inputString: u } = n, d = t(t({}, e(n, v)), {}, {
|
|
422
|
+
boardState: u == null ? n.boardState : u,
|
|
423
|
+
elapsedTimeSecs: (i = n.elapsedTimeSecs) == null ? E.timeWithoutPenaltySecs() : i,
|
|
424
|
+
additionalTimeAddedSecs: (a = n.additionalTimeAddedSecs) == null ? E.addedTimeSecs() : a
|
|
375
425
|
}), f = (o = r == null ? void 0 : r.deeds) == null ? [] : o;
|
|
376
426
|
f.push({
|
|
377
427
|
id: "points",
|
|
378
|
-
value:
|
|
428
|
+
value: n.pointsAwarded
|
|
379
429
|
}), f.push({
|
|
380
430
|
id: "time",
|
|
381
431
|
value: Math.round((s = d.elapsedTimeSecs) == null ? 0 : s) + Math.round((c = d.additionalTimeAddedSecs) == null ? 0 : c)
|
|
382
432
|
});
|
|
383
|
-
let
|
|
384
|
-
|
|
385
|
-
id:
|
|
433
|
+
let p = l();
|
|
434
|
+
p && (C.sendMessage("GAME_COMPLETED", {
|
|
435
|
+
id: p,
|
|
386
436
|
input: d,
|
|
387
437
|
config: r
|
|
388
|
-
}),
|
|
438
|
+
}), w("GAME_COMPLETED", { input: d }));
|
|
389
439
|
},
|
|
390
440
|
showCompletionScreen: (e) => {
|
|
391
|
-
|
|
441
|
+
C.sendMessage("SHOW_GAME_COMPLETE_SCREEN", {
|
|
392
442
|
results: e,
|
|
393
443
|
showRetry: !0
|
|
394
444
|
});
|
|
395
445
|
},
|
|
396
446
|
hitCheckpoint: (e, t, n) => {
|
|
397
447
|
var r;
|
|
398
|
-
if (!
|
|
399
|
-
let i = (r =
|
|
400
|
-
elapsedTimeSecs:
|
|
401
|
-
additionalTimeAddedSecs:
|
|
448
|
+
if (!l()) return;
|
|
449
|
+
let i = (r = p()) == null ? "" : r, a = {
|
|
450
|
+
elapsedTimeSecs: E.timeWithoutPenaltySecs(),
|
|
451
|
+
additionalTimeAddedSecs: E.addedTimeSecs()
|
|
402
452
|
};
|
|
403
|
-
|
|
453
|
+
C.sendMessage("HIT_CHECKPOINT", {
|
|
404
454
|
checkpointName: e,
|
|
405
455
|
gameplay: {
|
|
406
456
|
inputStr: i,
|
|
@@ -411,22 +461,22 @@ const v = (r = {}) => {
|
|
|
411
461
|
});
|
|
412
462
|
},
|
|
413
463
|
settings: {
|
|
414
|
-
initialize: (
|
|
415
|
-
components:
|
|
416
|
-
settings:
|
|
417
|
-
}),
|
|
464
|
+
initialize: (e) => (_ = t(t({}, T(e)), _), C.sendMessage("INITIALIZE_SETTINGS", {
|
|
465
|
+
components: e,
|
|
466
|
+
settings: _
|
|
467
|
+
}), _),
|
|
418
468
|
get: () => {
|
|
419
469
|
var e;
|
|
420
|
-
return (e =
|
|
470
|
+
return (e = _) == null ? {} : e;
|
|
421
471
|
},
|
|
422
|
-
update: (
|
|
472
|
+
update: (e) => (_ = t(t({}, _), e), C.sendMessage("UPDATE_SETTINGS_FROM_EMBED", { settings: _ }), _)
|
|
423
473
|
},
|
|
424
474
|
keyboard: {
|
|
425
475
|
show: (e) => {
|
|
426
|
-
|
|
476
|
+
C.sendMessage("KEYBOARD_UPDATE_CONFIG", e);
|
|
427
477
|
},
|
|
428
478
|
hide: () => {
|
|
429
|
-
|
|
479
|
+
C.sendMessage("KEYBOARD_UPDATE_CONFIG", {
|
|
430
480
|
layout: [],
|
|
431
481
|
symbols: {},
|
|
432
482
|
highlight: [],
|
|
@@ -439,18 +489,18 @@ const v = (r = {}) => {
|
|
|
439
489
|
},
|
|
440
490
|
haptics: { play: (e, t) => {
|
|
441
491
|
var n;
|
|
442
|
-
|
|
492
|
+
C.sendMessage("SENSORY_EVENT", {
|
|
443
493
|
id: (n = t == null ? void 0 : t.id) == null ? e : n,
|
|
444
494
|
haptic: e
|
|
445
495
|
});
|
|
446
496
|
} },
|
|
447
|
-
_hostAPI:
|
|
497
|
+
_hostAPI: C
|
|
448
498
|
};
|
|
449
499
|
};
|
|
450
500
|
/** Walks settings UI components (recursing into split groups) collecting name → defaultValue pairs */
|
|
451
|
-
function
|
|
501
|
+
function T(e) {
|
|
452
502
|
let t = {};
|
|
453
|
-
for (let n of e) n.type === "split" ? Object.assign(t,
|
|
503
|
+
for (let n of e) n.type === "split" ? Object.assign(t, T(n.content)) : "name" in n && (t[n.name] = n.defaultValue);
|
|
454
504
|
return t;
|
|
455
505
|
}
|
|
456
506
|
/**
|
|
@@ -465,7 +515,7 @@ function y(e) {
|
|
|
465
515
|
* // Extend with dynamic disabled letters
|
|
466
516
|
* sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
|
|
467
517
|
*/
|
|
468
|
-
const
|
|
518
|
+
const E = {
|
|
469
519
|
layout: [
|
|
470
520
|
"qwertyuiop",
|
|
471
521
|
"asdfghjkl",
|
|
@@ -481,21 +531,21 @@ const b = {
|
|
|
481
531
|
xl: [],
|
|
482
532
|
l: ["↵", "⌫"],
|
|
483
533
|
supportsDragCursor: !1
|
|
484
|
-
},
|
|
534
|
+
}, D = (e) => {
|
|
485
535
|
let n = {};
|
|
486
|
-
for (let a of
|
|
536
|
+
for (let a of e) for (let e of a.keys) {
|
|
487
537
|
var r, i;
|
|
488
|
-
let o = {}, s =
|
|
489
|
-
Object.keys(s).length && (o.text = s), Object.keys(c).length && (o.background = c), n[
|
|
538
|
+
let o = {}, s = t(t({}, (r = n[e]) == null ? void 0 : r.text), a.text), c = t(t({}, (i = n[e]) == null ? void 0 : i.background), a.background);
|
|
539
|
+
Object.keys(s).length && (o.text = s), Object.keys(c).length && (o.background = c), n[e] = o;
|
|
490
540
|
}
|
|
491
541
|
return n;
|
|
492
542
|
};
|
|
493
543
|
/** Custom error class for workshop import failures */
|
|
494
|
-
var
|
|
544
|
+
var O = class extends Error {
|
|
495
545
|
constructor(e, t, n) {
|
|
496
546
|
super(t), this.type = e, this.originalError = n, this.name = "EditorImportError";
|
|
497
547
|
}
|
|
498
548
|
};
|
|
499
|
-
export {
|
|
549
|
+
export { O as EditorImportError, w as createPuzzmoSDK, E as defaultKeyboardConfig, D as keyStylesFromRules };
|
|
500
550
|
|
|
501
551
|
//# sourceMappingURL=index.js.map
|