@puzzmo/sdk 1.0.58 → 1.0.60
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/{createSimulator-5inYnxKU.js → createSimulator-Dory7qUL.js} +2 -2
- package/dist/{createSimulator-5inYnxKU.js.map → createSimulator-Dory7qUL.js.map} +1 -1
- package/dist/{createSimulator-BCzgWYMQ.cjs → createSimulator-kGIstLy9.cjs} +2 -2
- package/dist/{createSimulator-BCzgWYMQ.cjs.map → createSimulator-kGIstLy9.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/inputs/index.cjs +1 -1
- package/dist/inputs/index.js +1 -1
- package/dist/lua-C3M-mB0u.js +11 -0
- package/dist/lua-C3M-mB0u.js.map +1 -0
- package/dist/lua-D5xtGGen.cjs +135 -0
- package/dist/lua-D5xtGGen.cjs.map +1 -0
- package/dist/{objectSpread2-COovHPnD.js → objectSpread2-C8x7fbpH.js} +1 -1
- package/dist/{objectSpread2-CuluYLUL.cjs → objectSpread2-DLgRiGrq.cjs} +1 -1
- package/dist/pico8/channel.d.ts +45 -0
- package/dist/pico8/channel.d.ts.map +1 -0
- package/dist/pico8/index.cjs +2 -0
- package/dist/pico8/index.cjs.map +1 -0
- package/dist/pico8/index.d.ts +85 -0
- package/dist/pico8/index.d.ts.map +1 -0
- package/dist/pico8/index.js +450 -0
- package/dist/pico8/index.js.map +1 -0
- package/dist/pico8/lua.d.ts +9 -0
- package/dist/pico8/lua.d.ts.map +1 -0
- package/dist/pico8/palette.d.ts +17 -0
- package/dist/pico8/palette.d.ts.map +1 -0
- package/dist/pico8/pico8.spec.d.ts +2 -0
- package/dist/pico8/pico8.spec.d.ts.map +1 -0
- package/dist/pico8/protocol.d.ts +61 -0
- package/dist/pico8/protocol.d.ts.map +1 -0
- package/dist/pico8/vitePlugin.d.ts +42 -0
- package/dist/pico8/vitePlugin.d.ts.map +1 -0
- 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/vite.cjs +7 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +215 -47
- package/dist/vite.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { n as e, t } from "../objectSpread2-C8x7fbpH.js";
|
|
2
|
+
import { t as n } from "../asyncToGenerator-Dn36a-ch.js";
|
|
3
|
+
import { t as r } from "../lua-C3M-mB0u.js";
|
|
4
|
+
const i = 60, a = 16, o = {
|
|
5
|
+
HELLO: 1,
|
|
6
|
+
PALETTE: 2,
|
|
7
|
+
READY: 3,
|
|
8
|
+
START: 4,
|
|
9
|
+
PAUSE: 5,
|
|
10
|
+
RETRY: 6,
|
|
11
|
+
PUZZLE_PART: 7,
|
|
12
|
+
PROGRESS_PART: 8
|
|
13
|
+
}, s = {
|
|
14
|
+
BOOT: 1,
|
|
15
|
+
LOADED: 2,
|
|
16
|
+
FINISHED: 3,
|
|
17
|
+
SAVE_PART: 4,
|
|
18
|
+
SAVE: 5,
|
|
19
|
+
DEED: 6,
|
|
20
|
+
COMPLETE: 7
|
|
21
|
+
};
|
|
22
|
+
var c = (e) => Math.max(0, Math.min(255, Math.round(e) || 0)), l = class {
|
|
23
|
+
/**
|
|
24
|
+
* @param mem The shared 128 bytes
|
|
25
|
+
* @param myBase Offset of the half this end writes
|
|
26
|
+
* @param peerBase Offset of the half this end reads
|
|
27
|
+
* @param resendAfter Ticks to wait for an ack before writing a message again
|
|
28
|
+
*/
|
|
29
|
+
constructor(t, n, r, i = 20) {
|
|
30
|
+
e(this, "inSeq", 0), e(this, "outSeq", 0), e(this, "pending", null), e(this, "wait", 0), e(this, "queue", []), this.mem = t, this.myBase = n, this.peerBase = r, this.resendAfter = i;
|
|
31
|
+
}
|
|
32
|
+
/** Queues a message. They go out one per tick, in order. */
|
|
33
|
+
send(e, t = []) {
|
|
34
|
+
if (t.length > 60) throw Error(`PICO-8 payloads are at most 60 bytes, op ${e} has ${t.length}`);
|
|
35
|
+
this.queue.push({
|
|
36
|
+
op: c(e),
|
|
37
|
+
payload: Array.from(t, c)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Messages still to be delivered, including one waiting on an ack. */
|
|
41
|
+
get backlog() {
|
|
42
|
+
return this.queue.length + (this.pending ? 1 : 0);
|
|
43
|
+
}
|
|
44
|
+
/** Reads at most one message and writes at most one. Call once per frame. */
|
|
45
|
+
tick() {
|
|
46
|
+
var e;
|
|
47
|
+
let t = [], n = this.read(this.peerBase);
|
|
48
|
+
if (this.inSeq !== 0 && this.write(this.myBase + 3, this.inSeq), n !== 0 && n !== this.inSeq) {
|
|
49
|
+
this.inSeq = n, this.write(this.myBase + 3, n);
|
|
50
|
+
let e = Math.min(this.read(this.peerBase + 2), 60), r = [];
|
|
51
|
+
for (let t = 0; t < e; t++) r.push(this.read(this.peerBase + 4 + t));
|
|
52
|
+
t.push({
|
|
53
|
+
op: this.read(this.peerBase + 1),
|
|
54
|
+
payload: r
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.pending && this.read(this.peerBase + 3) === this.outSeq && (this.pending = null);
|
|
58
|
+
let r = this.pending;
|
|
59
|
+
if (r) {
|
|
60
|
+
if (++this.wait < this.resendAfter) return t;
|
|
61
|
+
} else {
|
|
62
|
+
var i;
|
|
63
|
+
if (r = (i = this.queue.shift()) == null ? null : i, !r) return t;
|
|
64
|
+
this.outSeq = this.outSeq % 255 + 1;
|
|
65
|
+
}
|
|
66
|
+
for (let t = 0; t < 60; t++) this.write(this.myBase + 4 + t, (e = r.payload[t]) == null ? 0 : e);
|
|
67
|
+
return this.write(this.myBase + 1, r.op), this.write(this.myBase + 2, r.payload.length), this.write(this.myBase, this.outSeq), this.pending = r, this.wait = 0, t;
|
|
68
|
+
}
|
|
69
|
+
read(e) {
|
|
70
|
+
let t = this.mem[e];
|
|
71
|
+
return typeof t == "number" && t >= 0 ? t & 255 : 0;
|
|
72
|
+
}
|
|
73
|
+
write(e, t) {
|
|
74
|
+
this.mem[e] = c(t);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/** PICO-8's 32 hardware colours as `[r, g, b, id]`: the 16 standard ones, then the 16 extras at 128..143. */
|
|
78
|
+
const u = [
|
|
79
|
+
[
|
|
80
|
+
0,
|
|
81
|
+
0,
|
|
82
|
+
0,
|
|
83
|
+
0
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
29,
|
|
87
|
+
43,
|
|
88
|
+
83,
|
|
89
|
+
1
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
126,
|
|
93
|
+
37,
|
|
94
|
+
83,
|
|
95
|
+
2
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
0,
|
|
99
|
+
135,
|
|
100
|
+
81,
|
|
101
|
+
3
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
171,
|
|
105
|
+
82,
|
|
106
|
+
54,
|
|
107
|
+
4
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
95,
|
|
111
|
+
87,
|
|
112
|
+
79,
|
|
113
|
+
5
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
194,
|
|
117
|
+
195,
|
|
118
|
+
199,
|
|
119
|
+
6
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
255,
|
|
123
|
+
241,
|
|
124
|
+
232,
|
|
125
|
+
7
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
255,
|
|
129
|
+
0,
|
|
130
|
+
77,
|
|
131
|
+
8
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
255,
|
|
135
|
+
163,
|
|
136
|
+
0,
|
|
137
|
+
9
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
255,
|
|
141
|
+
236,
|
|
142
|
+
39,
|
|
143
|
+
10
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
0,
|
|
147
|
+
228,
|
|
148
|
+
54,
|
|
149
|
+
11
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
41,
|
|
153
|
+
173,
|
|
154
|
+
255,
|
|
155
|
+
12
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
131,
|
|
159
|
+
118,
|
|
160
|
+
156,
|
|
161
|
+
13
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
255,
|
|
165
|
+
119,
|
|
166
|
+
168,
|
|
167
|
+
14
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
255,
|
|
171
|
+
204,
|
|
172
|
+
170,
|
|
173
|
+
15
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
41,
|
|
177
|
+
24,
|
|
178
|
+
20,
|
|
179
|
+
128
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
17,
|
|
183
|
+
29,
|
|
184
|
+
53,
|
|
185
|
+
129
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
66,
|
|
189
|
+
33,
|
|
190
|
+
54,
|
|
191
|
+
130
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
18,
|
|
195
|
+
83,
|
|
196
|
+
89,
|
|
197
|
+
131
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
116,
|
|
201
|
+
47,
|
|
202
|
+
41,
|
|
203
|
+
132
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
73,
|
|
207
|
+
51,
|
|
208
|
+
59,
|
|
209
|
+
133
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
162,
|
|
213
|
+
136,
|
|
214
|
+
121,
|
|
215
|
+
134
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
243,
|
|
219
|
+
239,
|
|
220
|
+
125,
|
|
221
|
+
135
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
190,
|
|
225
|
+
18,
|
|
226
|
+
80,
|
|
227
|
+
136
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
255,
|
|
231
|
+
108,
|
|
232
|
+
36,
|
|
233
|
+
137
|
|
234
|
+
],
|
|
235
|
+
[
|
|
236
|
+
168,
|
|
237
|
+
231,
|
|
238
|
+
46,
|
|
239
|
+
138
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
0,
|
|
243
|
+
181,
|
|
244
|
+
67,
|
|
245
|
+
139
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
6,
|
|
249
|
+
90,
|
|
250
|
+
181,
|
|
251
|
+
140
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
117,
|
|
255
|
+
70,
|
|
256
|
+
101,
|
|
257
|
+
141
|
|
258
|
+
],
|
|
259
|
+
[
|
|
260
|
+
255,
|
|
261
|
+
110,
|
|
262
|
+
89,
|
|
263
|
+
142
|
|
264
|
+
],
|
|
265
|
+
[
|
|
266
|
+
255,
|
|
267
|
+
157,
|
|
268
|
+
129,
|
|
269
|
+
143
|
|
270
|
+
]
|
|
271
|
+
];
|
|
272
|
+
var d = (e) => {
|
|
273
|
+
let t = e.replace("#", "");
|
|
274
|
+
return /^[0-9a-f]{6}/i.test(t) ? [
|
|
275
|
+
parseInt(t.slice(0, 2), 16),
|
|
276
|
+
parseInt(t.slice(2, 4), 16),
|
|
277
|
+
parseInt(t.slice(4, 6), 16)
|
|
278
|
+
] : null;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* The hardware colour closest to `hex`, weighted towards green the way eyes are. `exclude` skips colours which are
|
|
282
|
+
* already taken. Returns null for anything which isn't a hex colour.
|
|
283
|
+
*/
|
|
284
|
+
function f(e, t) {
|
|
285
|
+
let n = d(e);
|
|
286
|
+
if (!n) return null;
|
|
287
|
+
let r = null, i = Infinity;
|
|
288
|
+
for (let [e, a, o, s] of u) {
|
|
289
|
+
if (t != null && t.has(s)) continue;
|
|
290
|
+
let c = 2 * Math.pow(e - n[0], 2) + 4 * Math.pow(a - n[1], 2) + 3 * Math.pow(o - n[2], 2);
|
|
291
|
+
c < i && (i = c, r = s);
|
|
292
|
+
}
|
|
293
|
+
return r;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Resolves up to 16 colours into the 16 hardware ids the cart feeds to `pal()`. Hex colours are matched to the
|
|
297
|
+
* nearest hardware colour which an earlier hex colour hasn't already claimed, because two theme colours landing on
|
|
298
|
+
* the same PICO-8 colour usually means something drawn on top of the other one disappears. Numbers are used as-is,
|
|
299
|
+
* and a missing entry keeps PICO-8's default for that slot.
|
|
300
|
+
*/
|
|
301
|
+
function p(e) {
|
|
302
|
+
let t = /* @__PURE__ */ new Set(), n = [];
|
|
303
|
+
for (let i = 0; i < 16; i++) {
|
|
304
|
+
let a = e[i];
|
|
305
|
+
if (typeof a == "number") n.push(a);
|
|
306
|
+
else if (typeof a == "string") {
|
|
307
|
+
var r;
|
|
308
|
+
let e = (r = f(a, t)) == null ? i : r;
|
|
309
|
+
t.add(e), n.push(e);
|
|
310
|
+
} else n.push(i);
|
|
311
|
+
}
|
|
312
|
+
return n;
|
|
313
|
+
}
|
|
314
|
+
/** The page's `pico8_gpio` array, with every slot a number. PICO-8's exported page declares it, older ones may not. */
|
|
315
|
+
var m = () => {
|
|
316
|
+
let e = globalThis, t = e.pico8_gpio && e.pico8_gpio.length >= 128 ? e.pico8_gpio : e.pico8_gpio = Array(128);
|
|
317
|
+
for (let e = 0; e < 128; e++) typeof t[e] != "number" && (t[e] = 0);
|
|
318
|
+
return t;
|
|
319
|
+
}, h = (e) => Array.from(e, (e) => {
|
|
320
|
+
let t = e.charCodeAt(0);
|
|
321
|
+
return t < 256 ? t : 63;
|
|
322
|
+
}), g = (e) => String.fromCharCode(...e), _ = (e) => {
|
|
323
|
+
let t = [];
|
|
324
|
+
for (let n = 0; n < e.length; n += 60) t.push(e.slice(n, n + 60));
|
|
325
|
+
return t;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Runs a PICO-8 cart as a Puzzmo game, with the whole game written in Lua. It waits for the puzzle, hands it to the
|
|
329
|
+
* cart as `pz.puzzle` (and the player's saved progress as `pz.progress`), and turns the cart's `pz_save()`,
|
|
330
|
+
* `pz_deed()` and `pz_complete()` into the SDK calls Puzzmo needs.
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { createPuzzmoSDK } from "@puzzmo/sdk"
|
|
334
|
+
* import { createPico8Game } from "@puzzmo/sdk/pico8"
|
|
335
|
+
*
|
|
336
|
+
* createPico8Game(createPuzzmoSDK())
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
function v(e) {
|
|
340
|
+
return y.apply(this, arguments);
|
|
341
|
+
}
|
|
342
|
+
function y() {
|
|
343
|
+
return y = n(function* (e, n = {}) {
|
|
344
|
+
let { puzzleString: r, inputString: i, completed: a } = yield e.gameReady();
|
|
345
|
+
return b(t(t({}, n), {}, {
|
|
346
|
+
sdk: e,
|
|
347
|
+
completed: a,
|
|
348
|
+
puzzleString: r,
|
|
349
|
+
inputString: i
|
|
350
|
+
}));
|
|
351
|
+
}), y.apply(this, arguments);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Connects a PICO-8 cart to the Puzzmo SDK over PICO-8's GPIO bytes. Most games want `createPico8Game`, which calls
|
|
355
|
+
* this for you. The cart's half is `puzzmo.lua`, which the
|
|
356
|
+
* `puzzmoPico8()` vite plugin writes next to your cart.
|
|
357
|
+
*
|
|
358
|
+
* The bridge runs the SDK lifecycle for you: it answers the cart's boot with the puzzle and progress, calls
|
|
359
|
+
* `gameLoaded()` once the cart has them, passes start, pause, resume and retry through to the cart, and turns the
|
|
360
|
+
* cart's `pz_save()`, `pz_deed()` and `pz_complete()` into SDK calls. Reach for it over `createPico8Game` when you
|
|
361
|
+
* need something from `gameReady()` first, like the theme.
|
|
362
|
+
*
|
|
363
|
+
* ```ts
|
|
364
|
+
* const sdk = createPuzzmoSDK()
|
|
365
|
+
* const { puzzleString, inputString, completed, theme } = await sdk.gameReady()
|
|
366
|
+
*
|
|
367
|
+
* createPico8Bridge({ sdk, puzzleString, inputString, completed, palette: [theme.g_bg, theme.g_bgAlt] })
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
function b(e) {
|
|
371
|
+
var n, r;
|
|
372
|
+
let { sdk: i, debug: a = !1 } = e, c = new l((n = e.memory) == null ? m() : n, 0, 64), u = e.palette ? p(e.palette) : null, d = {
|
|
373
|
+
started: !1,
|
|
374
|
+
paused: !1,
|
|
375
|
+
loaded: !1,
|
|
376
|
+
reopened: !!e.completed,
|
|
377
|
+
completed: !!e.completed,
|
|
378
|
+
progress: (r = e.inputString) == null ? "" : r,
|
|
379
|
+
saving: [],
|
|
380
|
+
deeds: []
|
|
381
|
+
}, f = (e, t, n) => {
|
|
382
|
+
a && console.log(`[pico8] ${e} op ${t}`, Array.from(n));
|
|
383
|
+
}, v = (e, t = []) => {
|
|
384
|
+
f("page -> cart", e, t), c.send(e, t);
|
|
385
|
+
}, y = (e, t) => {
|
|
386
|
+
if (e < 16) throw Error(`PICO-8 ops below 16 belong to the bridge, got ${e}`);
|
|
387
|
+
v(e, t);
|
|
388
|
+
}, b = (n, r) => {
|
|
389
|
+
if (f("cart -> page", n, r), n === s.BOOT) {
|
|
390
|
+
var a;
|
|
391
|
+
if (v(o.HELLO, [d.completed ? 1 : 0]), u && v(o.PALETTE, u), e.puzzleString) for (let t of _(h(e.puzzleString))) v(o.PUZZLE_PART, t);
|
|
392
|
+
if (d.progress) for (let e of _(h(d.progress))) v(o.PROGRESS_PART, e);
|
|
393
|
+
(a = e.onBoot) == null || a.call(e, y), v(o.READY), d.started && v(o.START), d.paused && v(o.PAUSE, [1]);
|
|
394
|
+
} else if (n === s.LOADED) d.loaded || i.gameLoaded(), d.loaded = !0;
|
|
395
|
+
else if (n === s.FINISHED) {
|
|
396
|
+
if (d.reopened) return;
|
|
397
|
+
e.onFinished ? e.onFinished() : i.showCompletionScreen([]);
|
|
398
|
+
} else if (n === s.SAVE_PART) d.saving.push(...r);
|
|
399
|
+
else if (n === s.SAVE) {
|
|
400
|
+
let e = g([...d.saving, ...r]);
|
|
401
|
+
if (d.saving = [], e === d.progress) return;
|
|
402
|
+
d.progress = e, i.updateGameState(e);
|
|
403
|
+
} else if (n === s.DEED) {
|
|
404
|
+
let [e = 0, n = 0, i = 0, ...a] = r, o = {
|
|
405
|
+
id: g(a),
|
|
406
|
+
value: e * 256 + n
|
|
407
|
+
};
|
|
408
|
+
d.deeds = d.deeds.filter((e) => e.id !== o.id), d.deeds.push(i ? t(t({}, o), {}, { persist: !0 }) : o);
|
|
409
|
+
} else if (n === s.COMPLETE) {
|
|
410
|
+
if (d.completed) return;
|
|
411
|
+
let [e = 0, t = 0] = r;
|
|
412
|
+
i.gameCompleted({
|
|
413
|
+
inputString: d.progress,
|
|
414
|
+
pointsAwarded: e * 256 + t,
|
|
415
|
+
completed: !0
|
|
416
|
+
}, { deeds: d.deeds }), d.completed = !0, d.deeds = [];
|
|
417
|
+
} else if (n >= 16) {
|
|
418
|
+
var c;
|
|
419
|
+
(c = e.onMessage) == null || c.call(e, n, r, y);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
i.on("start", () => {
|
|
423
|
+
d.started = !0, v(o.START);
|
|
424
|
+
}), i.on("pause", () => {
|
|
425
|
+
d.paused = !0, v(o.PAUSE, [1]);
|
|
426
|
+
}), i.on("resume", () => {
|
|
427
|
+
d.paused = !1, v(o.PAUSE, [0]);
|
|
428
|
+
}), i.on("retry", () => {
|
|
429
|
+
var t;
|
|
430
|
+
d.reopened = !1, d.completed = !1, d.progress = "", d.deeds = [], (t = e.onRetry) == null || t.call(e), v(o.RETRY);
|
|
431
|
+
});
|
|
432
|
+
let x = () => {
|
|
433
|
+
for (let { op: e, payload: t } of c.tick()) b(e, t);
|
|
434
|
+
}, S = null, C = () => {
|
|
435
|
+
x(), S = requestAnimationFrame(C);
|
|
436
|
+
};
|
|
437
|
+
return e.autoTick !== !1 && typeof requestAnimationFrame == "function" && (S = requestAnimationFrame(C)), {
|
|
438
|
+
send: y,
|
|
439
|
+
tick: x,
|
|
440
|
+
stop: () => {
|
|
441
|
+
S !== null && cancelAnimationFrame(S), S = null;
|
|
442
|
+
},
|
|
443
|
+
get backlog() {
|
|
444
|
+
return c.backlog;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
export { s as CartOp, o as PageOp, l as Pico8Channel, b as createPico8Bridge, v as createPico8Game, a as firstGameOp, i as maxPayload, f as nearestPico8Colour, u as pico8HardwareColours, r as puzzmoLua, p as resolvePico8Palette };
|
|
449
|
+
|
|
450
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/pico8/protocol.ts","../../src/pico8/channel.ts","../../src/pico8/palette.ts","../../src/pico8/index.ts"],"sourcesContent":["/**\n * The PICO-8 bridge's wire format. PICO-8 mirrors the 128 bytes at 0x5f80 into a JavaScript array called\n * `pico8_gpio` once a frame, in both directions, and this splits them into two mailboxes. Each side only ever writes\n * to its own half: a byte written by both ends can lose one of the writes when the frame syncs.\n *\n * 0x00..0x3f page -> cart (only JavaScript writes)\n * 0x40..0x7f cart -> page (only Lua writes)\n *\n * Each mailbox holds one message:\n *\n * +0 seq 0 = nothing sent yet, else 1..255 wrapping back to 1\n * +1 op opcode\n * +2 len payload length, 0..60\n * +3 ack the last seq this side has read from the other side\n * +4..+63 payload\n *\n * Ops below 16 belong to the bridge, a game uses 16 and up. The Lua half is in ./lua.ts.\n */\n\nexport const gpioSize = 128\nexport const pageBase = 0\nexport const cartBase = 64\nexport const maxPayload = 60\n\n/** The first op a game can use for its own messages. */\nexport const firstGameOp = 16\n\n/** Page -> cart */\nexport const PageOp = {\n /** `[flags]`, bit 0: this play was already completed. First thing sent after every BOOT. */\n HELLO: 1,\n /** 16 bytes: the PICO-8 hardware colour for each draw colour, applied with `pal(i, c, 1)` */\n PALETTE: 2,\n /** Everything is sent: the cart sets `pz.puzzle`, `pz.progress` and `pz.ready`, calls `pz_on_ready()`, and answers LOADED */\n READY: 3,\n /** The host started the game */\n START: 4,\n /** `[0 or 1]` */\n PAUSE: 5,\n /** The player restarted the puzzle */\n RETRY: 6,\n /** Up to 60 characters of the puzzle string. It arrives in pieces after HELLO, and READY marks the end. */\n PUZZLE_PART: 7,\n /** Up to 60 characters of the player's saved progress, the same way. */\n PROGRESS_PART: 8,\n} as const\n\n/** Cart -> page */\nexport const CartOp = {\n /** Sent from `pz_init()`, so again whenever the cart restarts */\n BOOT: 1,\n /** The cart has everything it needs to draw */\n LOADED: 2,\n /** The cart finished its victory animation, from `pz_finished()` */\n FINISHED: 3,\n /** 60 characters of progress from `pz_save()`, with more to come */\n SAVE_PART: 4,\n /** The last (or only) piece of progress from `pz_save()` */\n SAVE: 5,\n /** `[value hi, value lo, persist, ...id]` from `pz_deed()` */\n DEED: 6,\n /** `[points hi, points lo]` from `pz_complete()`, which saves the final progress just before */\n COMPLETE: 7,\n} as const\n","import { maxPayload } from \"./protocol\"\n\n/** One message on the wire. */\nexport type Pico8Message = { op: number; payload: number[] }\n\n/** Anything indexable as bytes, in practice the `pico8_gpio` array. */\nexport type Pico8Memory = { [index: number]: number | undefined; length: number }\n\nconst clampByte = (n: number) => Math.max(0, Math.min(255, Math.round(n) || 0))\n\n/**\n * One end of a GPIO mailbox pair. The cart runs the same algorithm in Lua (`pz_update` in ./lua.ts).\n *\n * A message is written payload first and `seq` last, so a half-synced message is never read as a whole one. The\n * sender holds it until the other side's `ack` matches, and writes it again (under the same `seq`) if no ack arrives,\n * so a repeat is ignored by a side that already has it. The `ack` is restated every tick, because an ack lost to a\n * sync race would otherwise leave the other side waiting forever on a message which was delivered.\n */\nexport class Pico8Channel {\n private inSeq = 0\n private outSeq = 0\n private pending: Pico8Message | null = null\n private wait = 0\n private queue: Pico8Message[] = []\n\n /**\n * @param mem The shared 128 bytes\n * @param myBase Offset of the half this end writes\n * @param peerBase Offset of the half this end reads\n * @param resendAfter Ticks to wait for an ack before writing a message again\n */\n constructor(\n private mem: Pico8Memory,\n private myBase: number,\n private peerBase: number,\n private resendAfter = 20,\n ) {}\n\n /** Queues a message. They go out one per tick, in order. */\n send(op: number, payload: ArrayLike<number> = []) {\n if (payload.length > maxPayload) throw new Error(`PICO-8 payloads are at most ${maxPayload} bytes, op ${op} has ${payload.length}`)\n this.queue.push({ op: clampByte(op), payload: Array.from(payload, clampByte) })\n }\n\n /** Messages still to be delivered, including one waiting on an ack. */\n get backlog() {\n return this.queue.length + (this.pending ? 1 : 0)\n }\n\n /** Reads at most one message and writes at most one. Call once per frame. */\n tick(): Pico8Message[] {\n const received: Pico8Message[] = []\n\n const seq = this.read(this.peerBase)\n if (this.inSeq !== 0) this.write(this.myBase + 3, this.inSeq)\n if (seq !== 0 && seq !== this.inSeq) {\n this.inSeq = seq\n this.write(this.myBase + 3, seq)\n const len = Math.min(this.read(this.peerBase + 2), maxPayload)\n const payload: number[] = []\n for (let i = 0; i < len; i++) payload.push(this.read(this.peerBase + 4 + i))\n received.push({ op: this.read(this.peerBase + 1), payload })\n }\n\n if (this.pending && this.read(this.peerBase + 3) === this.outSeq) this.pending = null\n\n let message = this.pending\n if (message) {\n if (++this.wait < this.resendAfter) return received\n } else {\n message = this.queue.shift() ?? null\n if (!message) return received\n this.outSeq = (this.outSeq % 255) + 1\n }\n\n for (let i = 0; i < maxPayload; i++) this.write(this.myBase + 4 + i, message.payload[i] ?? 0)\n this.write(this.myBase + 1, message.op)\n this.write(this.myBase + 2, message.payload.length)\n this.write(this.myBase, this.outSeq) // seq last: it commits the message\n this.pending = message\n this.wait = 0\n return received\n }\n\n private read(i: number) {\n const v = this.mem[i]\n return typeof v === \"number\" && v >= 0 ? v & 0xff : 0\n }\n\n private write(i: number, v: number) {\n this.mem[i] = clampByte(v)\n }\n}\n","/** A colour for one of the cart's 16 draw colours: a hex string, a PICO-8 hardware colour id, or null to leave it alone. */\nexport type Pico8Colour = string | number | null | undefined\n\n/** PICO-8's 32 hardware colours as `[r, g, b, id]`: the 16 standard ones, then the 16 extras at 128..143. */\nexport const pico8HardwareColours: readonly (readonly [number, number, number, number])[] = [\n [0x00, 0x00, 0x00, 0],\n [0x1d, 0x2b, 0x53, 1],\n [0x7e, 0x25, 0x53, 2],\n [0x00, 0x87, 0x51, 3],\n [0xab, 0x52, 0x36, 4],\n [0x5f, 0x57, 0x4f, 5],\n [0xc2, 0xc3, 0xc7, 6],\n [0xff, 0xf1, 0xe8, 7],\n [0xff, 0x00, 0x4d, 8],\n [0xff, 0xa3, 0x00, 9],\n [0xff, 0xec, 0x27, 10],\n [0x00, 0xe4, 0x36, 11],\n [0x29, 0xad, 0xff, 12],\n [0x83, 0x76, 0x9c, 13],\n [0xff, 0x77, 0xa8, 14],\n [0xff, 0xcc, 0xaa, 15],\n [0x29, 0x18, 0x14, 128],\n [0x11, 0x1d, 0x35, 129],\n [0x42, 0x21, 0x36, 130],\n [0x12, 0x53, 0x59, 131],\n [0x74, 0x2f, 0x29, 132],\n [0x49, 0x33, 0x3b, 133],\n [0xa2, 0x88, 0x79, 134],\n [0xf3, 0xef, 0x7d, 135],\n [0xbe, 0x12, 0x50, 136],\n [0xff, 0x6c, 0x24, 137],\n [0xa8, 0xe7, 0x2e, 138],\n [0x00, 0xb5, 0x43, 139],\n [0x06, 0x5a, 0xb5, 140],\n [0x75, 0x46, 0x65, 141],\n [0xff, 0x6e, 0x59, 142],\n [0xff, 0x9d, 0x81, 143],\n]\n\nconst parseHex = (hex: string): [number, number, number] | null => {\n const s = hex.replace(\"#\", \"\")\n if (!/^[0-9a-f]{6}/i.test(s)) return null\n return [parseInt(s.slice(0, 2), 16), parseInt(s.slice(2, 4), 16), parseInt(s.slice(4, 6), 16)]\n}\n\n/**\n * The hardware colour closest to `hex`, weighted towards green the way eyes are. `exclude` skips colours which are\n * already taken. Returns null for anything which isn't a hex colour.\n */\nexport function nearestPico8Colour(hex: string, exclude?: ReadonlySet<number>): number | null {\n const rgb = parseHex(hex)\n if (!rgb) return null\n let best: number | null = null\n let bestDistance = Infinity\n for (const [r, g, b, id] of pico8HardwareColours) {\n if (exclude?.has(id)) continue\n const distance = 2 * (r - rgb[0]) ** 2 + 4 * (g - rgb[1]) ** 2 + 3 * (b - rgb[2]) ** 2\n if (distance < bestDistance) {\n bestDistance = distance\n best = id\n }\n }\n return best\n}\n\n/**\n * Resolves up to 16 colours into the 16 hardware ids the cart feeds to `pal()`. Hex colours are matched to the\n * nearest hardware colour which an earlier hex colour hasn't already claimed, because two theme colours landing on\n * the same PICO-8 colour usually means something drawn on top of the other one disappears. Numbers are used as-is,\n * and a missing entry keeps PICO-8's default for that slot.\n */\nexport function resolvePico8Palette(colours: readonly Pico8Colour[]): number[] {\n const taken = new Set<number>()\n const out: number[] = []\n for (let i = 0; i < 16; i++) {\n const c = colours[i]\n if (typeof c === \"number\") out.push(c)\n else if (typeof c === \"string\") {\n const id = nearestPico8Colour(c, taken) ?? i\n taken.add(id)\n out.push(id)\n } else out.push(i)\n }\n return out\n}\n","import type { PuzzmoSDK } from \"../sdk\"\nimport type { Deed } from \"../types\"\nimport { Pico8Channel, type Pico8Memory } from \"./channel\"\nimport { resolvePico8Palette, type Pico8Colour } from \"./palette\"\nimport { cartBase, CartOp, firstGameOp, gpioSize, maxPayload, pageBase, PageOp } from \"./protocol\"\n\nexport { Pico8Channel, type Pico8Message, type Pico8Memory } from \"./channel\"\nexport { nearestPico8Colour, resolvePico8Palette, pico8HardwareColours, type Pico8Colour } from \"./palette\"\nexport { CartOp, PageOp, firstGameOp, maxPayload } from \"./protocol\"\nexport { puzzmoLua } from \"./lua\"\n\n/** Sends one of your game's messages to the cart. `op` must be 16 or above, and a payload is at most 60 bytes. */\nexport type Pico8Send = (op: number, payload?: ArrayLike<number>) => void\n\n/** The parts of the SDK the bridge uses. */\nexport type Pico8BridgeSDK = Pick<PuzzmoSDK, \"gameLoaded\" | \"on\" | \"showCompletionScreen\" | \"updateGameState\" | \"gameCompleted\">\n\nexport type Pico8BridgeOptions = {\n /** The SDK, after `gameReady()` has resolved. */\n sdk: Pico8BridgeSDK\n /** `completed` from `gameReady()`. A finished play opens with `pz.completed` set, and won't ask for the completion screen again. */\n completed?: boolean\n /** `puzzleString` from `gameReady()`, which the cart gets as `pz.puzzle`. Keep puzzles to plain ASCII. */\n puzzleString?: string\n /** `inputString` from `gameReady()`: the progress the cart last saved with `pz_save()`, which it gets as `pz.progress`. */\n inputString?: string | null\n /**\n * Colours for the cart's 16 draw colours, as hex strings (matched to the nearest PICO-8 hardware colour), hardware\n * colour ids, or null to keep PICO-8's default for that slot. Leave it out to keep the default palette entirely.\n */\n palette?: readonly Pico8Colour[]\n /**\n * The cart has booted (or rebooted) and wants the board. Send whatever it needs to draw with `send`, the bridge\n * follows it with READY, and the cart's `pz_on_ready()` runs once it has all arrived.\n */\n onBoot?: (send: Pico8Send) => void\n /** One of your game's messages (op 16 and up) arrived from the cart. */\n onMessage?: (op: number, payload: number[], send: Pico8Send) => void\n /** The player restarted. Reset your state here, the cart's `pz_on_retry()` runs afterwards. */\n onRetry?: () => void\n /** The cart called `pz_finished()`. Defaults to `sdk.showCompletionScreen([])`. */\n onFinished?: () => void\n /** Log every message, both ways, to the console. Handy while you're getting started. */\n debug?: boolean\n /** The shared bytes. Defaults to the page's `pico8_gpio` array, creating it if needed. */\n memory?: Pico8Memory\n /** Tick on every animation frame. Turn it off to call `tick()` yourself. Defaults to true. */\n autoTick?: boolean\n}\n\nexport type Pico8Bridge = {\n /** Sends one of your game's messages to the cart. */\n send: Pico8Send\n /** Moves the conversation along by one frame, if you turned `autoTick` off. */\n tick: () => void\n /** Stops ticking. */\n stop: () => void\n /** Messages which haven't been acknowledged yet. */\n readonly backlog: number\n}\n\n/** The page's `pico8_gpio` array, with every slot a number. PICO-8's exported page declares it, older ones may not. */\nconst gpioMemory = (): Pico8Memory => {\n const g = globalThis as { pico8_gpio?: Pico8Memory }\n const mem = g.pico8_gpio && g.pico8_gpio.length >= gpioSize ? g.pico8_gpio : (g.pico8_gpio = new Array(gpioSize))\n for (let i = 0; i < gpioSize; i++) if (typeof mem[i] !== \"number\") mem[i] = 0\n return mem\n}\n\n/** Strings travel as one character per byte. PICO-8's characters match ASCII from 32 to 126, so keep to those. */\nconst textToBytes = (text: string) =>\n Array.from(text, (ch) => {\n const code = ch.charCodeAt(0)\n return code < 256 ? code : 63 // \"?\"\n })\nconst bytesToText = (bytes: number[]) => String.fromCharCode(...bytes)\n\n/** Splits bytes into message-sized pieces. An empty string is still one (empty) piece. */\nconst chunks = (bytes: number[]) => {\n const out: number[][] = []\n for (let i = 0; i < bytes.length; i += maxPayload) out.push(bytes.slice(i, i + maxPayload))\n return out\n}\n\n/**\n * Runs a PICO-8 cart as a Puzzmo game, with the whole game written in Lua. It waits for the puzzle, hands it to the\n * cart as `pz.puzzle` (and the player's saved progress as `pz.progress`), and turns the cart's `pz_save()`,\n * `pz_deed()` and `pz_complete()` into the SDK calls Puzzmo needs.\n *\n * ```ts\n * import { createPuzzmoSDK } from \"@puzzmo/sdk\"\n * import { createPico8Game } from \"@puzzmo/sdk/pico8\"\n *\n * createPico8Game(createPuzzmoSDK())\n * ```\n */\nexport async function createPico8Game(\n sdk: Pico8BridgeSDK & Pick<PuzzmoSDK, \"gameReady\">,\n options: Omit<Pico8BridgeOptions, \"sdk\" | \"completed\" | \"puzzleString\" | \"inputString\"> = {},\n): Promise<Pico8Bridge> {\n const { puzzleString, inputString, completed } = await sdk.gameReady()\n return createPico8Bridge({ ...options, sdk, completed, puzzleString, inputString })\n}\n\n/**\n * Connects a PICO-8 cart to the Puzzmo SDK over PICO-8's GPIO bytes. Most games want `createPico8Game`, which calls\n * this for you. The cart's half is `puzzmo.lua`, which the\n * `puzzmoPico8()` vite plugin writes next to your cart.\n *\n * The bridge runs the SDK lifecycle for you: it answers the cart's boot with the puzzle and progress, calls\n * `gameLoaded()` once the cart has them, passes start, pause, resume and retry through to the cart, and turns the\n * cart's `pz_save()`, `pz_deed()` and `pz_complete()` into SDK calls. Reach for it over `createPico8Game` when you\n * need something from `gameReady()` first, like the theme.\n *\n * ```ts\n * const sdk = createPuzzmoSDK()\n * const { puzzleString, inputString, completed, theme } = await sdk.gameReady()\n *\n * createPico8Bridge({ sdk, puzzleString, inputString, completed, palette: [theme.g_bg, theme.g_bgAlt] })\n * ```\n */\nexport function createPico8Bridge(options: Pico8BridgeOptions): Pico8Bridge {\n const { sdk, debug = false } = options\n const channel = new Pico8Channel(options.memory ?? gpioMemory(), pageBase, cartBase)\n const palette = options.palette ? resolvePico8Palette(options.palette) : null\n\n const state = {\n started: false,\n paused: false,\n loaded: false,\n // A play which was already finished must not ask for its completion screen again: the host re-opens a finished\n // play to show that screen, and asking for it from inside it would loop. A retry makes the play live again.\n reopened: Boolean(options.completed),\n completed: Boolean(options.completed),\n // The latest progress the cart saved, so a cart which restarts part way through picks up where it was.\n progress: options.inputString ?? \"\",\n saving: [] as number[],\n deeds: [] as Deed[],\n }\n\n const log = (direction: string, op: number, payload: ArrayLike<number>) => {\n if (debug) console.log(`[pico8] ${direction} op ${op}`, Array.from(payload))\n }\n\n const sendRaw = (op: number, payload: ArrayLike<number> = []) => {\n log(\"page -> cart\", op, payload)\n channel.send(op, payload)\n }\n\n const send: Pico8Send = (op, payload) => {\n if (op < firstGameOp) throw new Error(`PICO-8 ops below ${firstGameOp} belong to the bridge, got ${op}`)\n sendRaw(op, payload)\n }\n\n const onCartMessage = (op: number, payload: number[]) => {\n log(\"cart -> page\", op, payload)\n if (op === CartOp.BOOT) {\n // The first boot, or the cart restarted part way through: send it the whole world again.\n sendRaw(PageOp.HELLO, [state.completed ? 1 : 0])\n if (palette) sendRaw(PageOp.PALETTE, palette)\n if (options.puzzleString) for (const part of chunks(textToBytes(options.puzzleString))) sendRaw(PageOp.PUZZLE_PART, part)\n if (state.progress) for (const part of chunks(textToBytes(state.progress))) sendRaw(PageOp.PROGRESS_PART, part)\n options.onBoot?.(send)\n sendRaw(PageOp.READY)\n if (state.started) sendRaw(PageOp.START)\n if (state.paused) sendRaw(PageOp.PAUSE, [1])\n } else if (op === CartOp.LOADED) {\n if (!state.loaded) sdk.gameLoaded()\n state.loaded = true\n } else if (op === CartOp.FINISHED) {\n if (state.reopened) return\n if (options.onFinished) options.onFinished()\n else sdk.showCompletionScreen([])\n } else if (op === CartOp.SAVE_PART) {\n state.saving.push(...payload)\n } else if (op === CartOp.SAVE) {\n const progress = bytesToText([...state.saving, ...payload])\n state.saving = []\n // pz_complete() saves the final progress, which the cart has often just saved already\n if (progress === state.progress) return\n state.progress = progress\n sdk.updateGameState(progress)\n } else if (op === CartOp.DEED) {\n const [hi = 0, lo = 0, persist = 0, ...id] = payload\n const deed = { id: bytesToText(id), value: hi * 256 + lo }\n state.deeds = state.deeds.filter((d) => d.id !== deed.id)\n state.deeds.push(persist ? { ...deed, persist: true } : deed)\n } else if (op === CartOp.COMPLETE) {\n if (state.completed) return\n const [hi = 0, lo = 0] = payload\n // The SDK adds the time and points deeds itself, from its own timer\n sdk.gameCompleted({ inputString: state.progress, pointsAwarded: hi * 256 + lo, completed: true }, { deeds: state.deeds })\n state.completed = true\n state.deeds = []\n } else if (op >= firstGameOp) {\n options.onMessage?.(op, payload, send)\n }\n }\n\n sdk.on(\"start\", () => {\n state.started = true\n sendRaw(PageOp.START)\n })\n sdk.on(\"pause\", () => {\n state.paused = true\n sendRaw(PageOp.PAUSE, [1])\n })\n sdk.on(\"resume\", () => {\n state.paused = false\n sendRaw(PageOp.PAUSE, [0])\n })\n sdk.on(\"retry\", () => {\n state.reopened = false\n state.completed = false\n state.progress = \"\"\n state.deeds = []\n options.onRetry?.()\n sendRaw(PageOp.RETRY)\n })\n\n const tick = () => {\n for (const { op, payload } of channel.tick()) onCartMessage(op, payload)\n }\n\n let frame: number | null = null\n const loop = () => {\n tick()\n frame = requestAnimationFrame(loop)\n }\n if (options.autoTick !== false && typeof requestAnimationFrame === \"function\") frame = requestAnimationFrame(loop)\n\n return {\n send,\n tick,\n stop: () => {\n if (frame !== null) cancelAnimationFrame(frame)\n frame = null\n },\n get backlog() {\n return channel.backlog\n },\n }\n}\n"],"mappings":";;;AAsBA,MAAa,IAAa,IAGb,IAAc,IAGd,IAAS;CAEpB,OAAO;CAEP,SAAS;CAET,OAAO;CAEP,OAAO;CAEP,OAAO;CAEP,OAAO;CAEP,aAAa;CAEb,eAAe;CAChB,EAGY,IAAS;CAEpB,MAAM;CAEN,QAAQ;CAER,UAAU;CAEV,WAAW;CAEX,MAAM;CAEN,MAAM;CAEN,UAAU;CACX;ACvDD,IAAM,KAAa,MAAc,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,EAUlE,IAAb,MAA0B;;;;;;;CAaxB,YACE,GACA,GACA,GACA,IAAsB,IACtB;AADQ,UAhBV,SAAgB,EAAA,UAChB,UAAiB,EAAA,UACjB,WAAuC,KAAA,UACvC,QAAe,EAAA,UACf,SAAgC,EAAE,CAAA,EASxB,KAAA,MAAA,GACA,KAAA,SAAA,GACA,KAAA,WAAA,GACA,KAAA,cAAA;;;CAIV,KAAK,GAAY,IAA6B,EAAE,EAAE;AAChD,MAAI,EAAQ,SAAA,GAAqB,OAAU,MAAM,4CAAuD,EAAG,OAAO,EAAQ,SAAS;AACnI,OAAK,MAAM,KAAK;GAAE,IAAI,EAAU,EAAG;GAAE,SAAS,MAAM,KAAK,GAAS,EAAU;GAAE,CAAC;;;CAIjF,IAAI,UAAU;AACZ,SAAO,KAAK,MAAM,UAAU,KAAK,UAAU,IAAI;;;CAIjD,OAAuB;;EACrB,IAAM,IAA2B,EAAE,EAE7B,IAAM,KAAK,KAAK,KAAK,SAAS;AAEpC,MADI,KAAK,UAAU,KAAG,KAAK,MAAM,KAAK,SAAS,GAAG,KAAK,MAAM,EACzD,MAAQ,KAAK,MAAQ,KAAK,OAAO;AAEnC,GADA,KAAK,Q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ACL;EACA;EACA,YAAY;AAEV,GADI,MAAU,QAAM,qBAAqB,EAAM,EAC/C,IAAQ;;EAEV,IAAI,UAAU;AACZ,UAAO,EAAQ;;EAElB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cart's half of the PICO-8 bridge, as Lua source.
|
|
3
|
+
*
|
|
4
|
+
* `puzzmoPico8()` writes this next to the cart as `puzzmo.lua`, and the cart pulls it in with `#include puzzmo.lua`.
|
|
5
|
+
* It is a transliteration of `Pico8Channel` in ./channel.ts plus the messages in ./protocol.ts, so change them
|
|
6
|
+
* together. Every token here comes out of the cart's 8192, so it is written to be small rather than pretty.
|
|
7
|
+
*/
|
|
8
|
+
export declare const puzzmoLua = "-- puzzmo.lua: connects your cart to\n-- puzzmo. written by @puzzmo/sdk,\n-- edits here will be overwritten.\n--\n-- pz_init() call in _init\n-- pz_update() call first in _update\n--\n-- pz.ready puzzle has arrived\n-- pz.puzzle today's puzzle\n-- pz.progress what pz_save saved\n-- pz.started ok to take input\n-- pz.paused stop taking input\n-- pz.completed already solved\n--\n-- pz_save(str) save progress\n-- pz_deed(id,n) a stat for\n-- leaderboards\n-- pz_complete(n,str) solved! with\n-- n points\n-- pz_finished() win anim done\n--\n-- define these to hear about things:\n-- pz_on_ready(), pz_on_start(),\n-- pz_on_retry()\n\npz={started=false,paused=false,\n completed=false,ready=false,\n puzzle=\"\",progress=\"\"}\n\nfunction pz_init()\n -- carry on from the seqs already in\n -- the mailboxes: a reset cart must\n -- not reuse one the page has seen\n pz_iseq,pz_oseq=@0x5f80,@0x5fc0\n pz_q,pz_pend,pz_wait={},nil,0\n pz_send(1)\nend\n\nfunction pz_send(op,p)\n add(pz_q,{op=op,p=p or {}})\nend\n\nfunction pz_update()\n local s=@0x5f80\n if (pz_iseq>0) poke(0x5fc3,pz_iseq)\n if s>0 and s!=pz_iseq then\n pz_iseq=s\n poke(0x5fc3,s)\n local p={}\n for i=1,@0x5f82 do p[i]=@(0x5f83+i) end\n pz_recv(@0x5f81,p)\n end\n if (pz_pend and @0x5f83==pz_oseq) pz_pend=nil\n local m=pz_pend\n if m then\n pz_wait+=1\n if (pz_wait<20) return\n else\n if (#pz_q==0) return\n m=deli(pz_q,1)\n pz_oseq=pz_oseq%255+1\n end\n for i=1,60 do poke(0x5fc3+i,m.p[i] or 0) end\n poke(0x5fc1,m.op,#m.p)\n poke(0x5fc0,pz_oseq)\n pz_pend,pz_wait=m,0\nend\n\nfunction pz_recv(op,p)\n if op==1 then\n pz.completed=p[1]&1>0\n pz_pb,pz_gb=\"\",\"\"\n elseif op==2 then\n for i=1,16 do pal(i-1,p[i],1) end\n elseif op==3 then\n pz.puzzle,pz.progress,pz.ready=pz_pb,pz_gb,true\n if (pz_on_ready) pz_on_ready()\n pz_send(2)\n elseif op==4 then\n pz.started=true\n if (pz_on_start) pz_on_start()\n elseif op==5 then\n pz.paused=p[1]==1\n elseif op==6 then\n pz.completed,pz.progress=false,\"\"\n if (pz_on_retry) pz_on_retry()\n elseif op==7 then\n pz_pb..=pz_str(p)\n elseif op==8 then\n pz_gb..=pz_str(p)\n elseif pz_on_msg then\n pz_on_msg(op,p)\n end\nend\n\nfunction pz_save(s)\n s=tostr(s)\n pz.progress=s\n while #s>60 do\n pz_send(4,pz_bytes(sub(s,1,60)))\n s=sub(s,61)\n end\n pz_send(5,pz_bytes(s))\nend\n\n-- n is 0..32767, keep=true stores it\n-- on the player's profile too\nfunction pz_deed(id,n,keep)\n local p={n\\256,n%256,keep and 1 or 0}\n for c in all(pz_bytes(id)) do add(p,c) end\n pz_send(6,p)\nend\n\nfunction pz_complete(n,s)\n pz_save(s)\n pz_send(7,{n\\256,n%256})\n pz.completed=true\nend\n\nfunction pz_finished() pz_send(3) end\n\n-- bytes to a string, and back\nfunction pz_str(p)\n local s=\"\"\n for v in all(p) do s..=chr(v) end\n return s\nend\n\nfunction pz_bytes(s)\n local p={}\n for i=1,#s do p[i]=ord(s,i) end\n return p\nend\n";
|
|
9
|
+
//# sourceMappingURL=lua.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lua.d.ts","sourceRoot":"","sources":["../../src/pico8/lua.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,q4FAqIrB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A colour for one of the cart's 16 draw colours: a hex string, a PICO-8 hardware colour id, or null to leave it alone. */
|
|
2
|
+
export type Pico8Colour = string | number | null | undefined;
|
|
3
|
+
/** PICO-8's 32 hardware colours as `[r, g, b, id]`: the 16 standard ones, then the 16 extras at 128..143. */
|
|
4
|
+
export declare const pico8HardwareColours: readonly (readonly [number, number, number, number])[];
|
|
5
|
+
/**
|
|
6
|
+
* The hardware colour closest to `hex`, weighted towards green the way eyes are. `exclude` skips colours which are
|
|
7
|
+
* already taken. Returns null for anything which isn't a hex colour.
|
|
8
|
+
*/
|
|
9
|
+
export declare function nearestPico8Colour(hex: string, exclude?: ReadonlySet<number>): number | null;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves up to 16 colours into the 16 hardware ids the cart feeds to `pal()`. Hex colours are matched to the
|
|
12
|
+
* nearest hardware colour which an earlier hex colour hasn't already claimed, because two theme colours landing on
|
|
13
|
+
* the same PICO-8 colour usually means something drawn on top of the other one disappears. Numbers are used as-is,
|
|
14
|
+
* and a missing entry keeps PICO-8's default for that slot.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePico8Palette(colours: readonly Pico8Colour[]): number[];
|
|
17
|
+
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/pico8/palette.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AAE5D,6GAA6G;AAC7G,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAiCtF,CAAA;AAQD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAc5F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,EAAE,CAa7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pico8.spec.d.ts","sourceRoot":"","sources":["../../src/pico8/pico8.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PICO-8 bridge's wire format. PICO-8 mirrors the 128 bytes at 0x5f80 into a JavaScript array called
|
|
3
|
+
* `pico8_gpio` once a frame, in both directions, and this splits them into two mailboxes. Each side only ever writes
|
|
4
|
+
* to its own half: a byte written by both ends can lose one of the writes when the frame syncs.
|
|
5
|
+
*
|
|
6
|
+
* 0x00..0x3f page -> cart (only JavaScript writes)
|
|
7
|
+
* 0x40..0x7f cart -> page (only Lua writes)
|
|
8
|
+
*
|
|
9
|
+
* Each mailbox holds one message:
|
|
10
|
+
*
|
|
11
|
+
* +0 seq 0 = nothing sent yet, else 1..255 wrapping back to 1
|
|
12
|
+
* +1 op opcode
|
|
13
|
+
* +2 len payload length, 0..60
|
|
14
|
+
* +3 ack the last seq this side has read from the other side
|
|
15
|
+
* +4..+63 payload
|
|
16
|
+
*
|
|
17
|
+
* Ops below 16 belong to the bridge, a game uses 16 and up. The Lua half is in ./lua.ts.
|
|
18
|
+
*/
|
|
19
|
+
export declare const gpioSize = 128;
|
|
20
|
+
export declare const pageBase = 0;
|
|
21
|
+
export declare const cartBase = 64;
|
|
22
|
+
export declare const maxPayload = 60;
|
|
23
|
+
/** The first op a game can use for its own messages. */
|
|
24
|
+
export declare const firstGameOp = 16;
|
|
25
|
+
/** Page -> cart */
|
|
26
|
+
export declare const PageOp: {
|
|
27
|
+
/** `[flags]`, bit 0: this play was already completed. First thing sent after every BOOT. */
|
|
28
|
+
readonly HELLO: 1;
|
|
29
|
+
/** 16 bytes: the PICO-8 hardware colour for each draw colour, applied with `pal(i, c, 1)` */
|
|
30
|
+
readonly PALETTE: 2;
|
|
31
|
+
/** Everything is sent: the cart sets `pz.puzzle`, `pz.progress` and `pz.ready`, calls `pz_on_ready()`, and answers LOADED */
|
|
32
|
+
readonly READY: 3;
|
|
33
|
+
/** The host started the game */
|
|
34
|
+
readonly START: 4;
|
|
35
|
+
/** `[0 or 1]` */
|
|
36
|
+
readonly PAUSE: 5;
|
|
37
|
+
/** The player restarted the puzzle */
|
|
38
|
+
readonly RETRY: 6;
|
|
39
|
+
/** Up to 60 characters of the puzzle string. It arrives in pieces after HELLO, and READY marks the end. */
|
|
40
|
+
readonly PUZZLE_PART: 7;
|
|
41
|
+
/** Up to 60 characters of the player's saved progress, the same way. */
|
|
42
|
+
readonly PROGRESS_PART: 8;
|
|
43
|
+
};
|
|
44
|
+
/** Cart -> page */
|
|
45
|
+
export declare const CartOp: {
|
|
46
|
+
/** Sent from `pz_init()`, so again whenever the cart restarts */
|
|
47
|
+
readonly BOOT: 1;
|
|
48
|
+
/** The cart has everything it needs to draw */
|
|
49
|
+
readonly LOADED: 2;
|
|
50
|
+
/** The cart finished its victory animation, from `pz_finished()` */
|
|
51
|
+
readonly FINISHED: 3;
|
|
52
|
+
/** 60 characters of progress from `pz_save()`, with more to come */
|
|
53
|
+
readonly SAVE_PART: 4;
|
|
54
|
+
/** The last (or only) piece of progress from `pz_save()` */
|
|
55
|
+
readonly SAVE: 5;
|
|
56
|
+
/** `[value hi, value lo, persist, ...id]` from `pz_deed()` */
|
|
57
|
+
readonly DEED: 6;
|
|
58
|
+
/** `[points hi, points lo]` from `pz_complete()`, which saves the final progress just before */
|
|
59
|
+
readonly COMPLETE: 7;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/pico8/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,eAAO,MAAM,QAAQ,IAAI,CAAA;AACzB,eAAO,MAAM,QAAQ,KAAK,CAAA;AAC1B,eAAO,MAAM,UAAU,KAAK,CAAA;AAE5B,wDAAwD;AACxD,eAAO,MAAM,WAAW,KAAK,CAAA;AAE7B,mBAAmB;AACnB,eAAO,MAAM,MAAM;IACjB,4FAA4F;;IAE5F,6FAA6F;;IAE7F,6HAA6H;;IAE7H,gCAAgC;;IAEhC,iBAAiB;;IAEjB,sCAAsC;;IAEtC,2GAA2G;;IAE3G,wEAAwE;;CAEhE,CAAA;AAEV,mBAAmB;AACnB,eAAO,MAAM,MAAM;IACjB,iEAAiE;;IAEjE,+CAA+C;;IAE/C,oEAAoE;;IAEpE,oEAAoE;;IAEpE,4DAA4D;;IAE5D,8DAA8D;;IAE9D,gGAAgG;;CAExF,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export type PuzzmoPico8PluginOptions = {
|
|
3
|
+
/** The cart, relative to the page. Defaults to the only `.p8` file in `cart/`. */
|
|
4
|
+
cart?: string;
|
|
5
|
+
/** Where PICO-8's HTML export lives, relative to the page. Defaults to `export`. Commit it, so builds don't need PICO-8. */
|
|
6
|
+
exportDir?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The PICO-8 binary used to re-export the cart when it changes. Defaults to `$PICO8`, then `pico8` on your PATH,
|
|
9
|
+
* then where PICO-8's installers put it. When it can't be found the committed export is used as-is. Pass false to
|
|
10
|
+
* never export.
|
|
11
|
+
*/
|
|
12
|
+
pico8?: string | false;
|
|
13
|
+
/** Keep `puzzmo.lua` next to the cart up to date. Defaults to true. */
|
|
14
|
+
writeLua?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** @internal */
|
|
17
|
+
export type Pico8Game = {
|
|
18
|
+
/** The directory holding the page */
|
|
19
|
+
dir: string;
|
|
20
|
+
cart: string;
|
|
21
|
+
/** The cart's name, which PICO-8 also uses for its export */
|
|
22
|
+
name: string;
|
|
23
|
+
exportHTML: string;
|
|
24
|
+
exportJS: string;
|
|
25
|
+
};
|
|
26
|
+
/** @internal Finds the PICO-8 game served by the page in `dir`, if there is one. */
|
|
27
|
+
export declare function findPico8Game(dir: string, options?: PuzzmoPico8PluginOptions): Pico8Game | null;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
* Turns PICO-8's exported page into a Puzzmo game's page. PICO-8's shell is a thousand lines of globals and handlers
|
|
31
|
+
* its runtime expects to find, and it changes between versions, so rather than keep a copy we adjust theirs.
|
|
32
|
+
*/
|
|
33
|
+
export declare function patchPico8Export(html: string, name: string, scripts: string[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Vite plugin for games written as PICO-8 carts. Your `index.html` only needs your own script tag, the plugin swaps
|
|
36
|
+
* in PICO-8's exported page around it, serves the PICO-8 runtime next to it, and copies it into the build.
|
|
37
|
+
*
|
|
38
|
+
* When PICO-8 is installed it also re-exports the cart whenever it (or a `.lua` file next to it) changes, and reloads
|
|
39
|
+
* the page, so saving in PICO-8 is enough to see the change in the simulator.
|
|
40
|
+
*/
|
|
41
|
+
export declare function puzzmoPico8(options?: PuzzmoPico8PluginOptions): Plugin;
|
|
42
|
+
//# sourceMappingURL=vitePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../../src/pico8/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAA;AAMlD,MAAM,MAAM,wBAAwB,GAAG;IACrC,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4HAA4H;IAC5H,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,gBAAgB;AAChB,MAAM,MAAM,SAAS,GAAG;IACtB,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B,GAAG,SAAS,GAAG,IAAI,CAanG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CA4BtF;AAwBD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAiJ1E"}
|
package/dist/simulator/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../createSimulator-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../createSimulator-kGIstLy9.cjs`);exports.createSimulator=e.t,exports.createSoundView=e.n,exports.simulatorBuildMarker=e.r;
|