@al8b/time 0.1.0

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.
Files changed (68) hide show
  1. package/README.md +23 -0
  2. package/dist/constants.d.mts +6 -0
  3. package/dist/constants.d.ts +6 -0
  4. package/dist/constants.js +34 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/constants.mjs +8 -0
  7. package/dist/constants.mjs.map +1 -0
  8. package/dist/core/index.d.mts +2 -0
  9. package/dist/core/index.d.ts +2 -0
  10. package/dist/core/index.js +522 -0
  11. package/dist/core/index.js.map +1 -0
  12. package/dist/core/index.mjs +497 -0
  13. package/dist/core/index.mjs.map +1 -0
  14. package/dist/core/machine.d.mts +101 -0
  15. package/dist/core/machine.d.ts +101 -0
  16. package/dist/core/machine.js +520 -0
  17. package/dist/core/machine.js.map +1 -0
  18. package/dist/core/machine.mjs +497 -0
  19. package/dist/core/machine.mjs.map +1 -0
  20. package/dist/index.d.mts +4 -0
  21. package/dist/index.d.ts +4 -0
  22. package/dist/index.js +526 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/index.mjs +499 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/playback/index.d.mts +2 -0
  27. package/dist/playback/index.d.ts +2 -0
  28. package/dist/playback/index.js +172 -0
  29. package/dist/playback/index.js.map +1 -0
  30. package/dist/playback/index.mjs +147 -0
  31. package/dist/playback/index.mjs.map +1 -0
  32. package/dist/playback/player.d.mts +41 -0
  33. package/dist/playback/player.d.ts +41 -0
  34. package/dist/playback/player.js +172 -0
  35. package/dist/playback/player.js.map +1 -0
  36. package/dist/playback/player.mjs +147 -0
  37. package/dist/playback/player.mjs.map +1 -0
  38. package/dist/recording/index.d.mts +2 -0
  39. package/dist/recording/index.d.ts +2 -0
  40. package/dist/recording/index.js +149 -0
  41. package/dist/recording/index.js.map +1 -0
  42. package/dist/recording/index.mjs +124 -0
  43. package/dist/recording/index.mjs.map +1 -0
  44. package/dist/recording/recorder.d.mts +41 -0
  45. package/dist/recording/recorder.d.ts +41 -0
  46. package/dist/recording/recorder.js +149 -0
  47. package/dist/recording/recorder.js.map +1 -0
  48. package/dist/recording/recorder.mjs +124 -0
  49. package/dist/recording/recorder.mjs.map +1 -0
  50. package/dist/types/index.d.mts +1 -0
  51. package/dist/types/index.d.ts +1 -0
  52. package/dist/types/index.js +19 -0
  53. package/dist/types/index.js.map +1 -0
  54. package/dist/types/index.mjs +1 -0
  55. package/dist/types/index.mjs.map +1 -0
  56. package/dist/types/state.d.mts +33 -0
  57. package/dist/types/state.d.ts +33 -0
  58. package/dist/types/state.js +19 -0
  59. package/dist/types/state.js.map +1 -0
  60. package/dist/types/state.mjs +1 -0
  61. package/dist/types/state.mjs.map +1 -0
  62. package/dist/utils.d.mts +9 -0
  63. package/dist/utils.d.ts +9 -0
  64. package/dist/utils.js +60 -0
  65. package/dist/utils.js.map +1 -0
  66. package/dist/utils.mjs +37 -0
  67. package/dist/utils.mjs.map +1 -0
  68. package/package.json +37 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,499 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core/machine.ts
5
+ import { APIErrorCode, reportRuntimeError } from "@al8b/diagnostics";
6
+
7
+ // src/constants.ts
8
+ var DEFAULT_RECORD_BUFFER_FRAMES = 60 * 30;
9
+ var DEFAULT_LOOP_BUFFER_FRAMES = 60 * 4;
10
+
11
+ // src/utils.ts
12
+ function deepCopy(value, excluded) {
13
+ if (value == null) {
14
+ return value;
15
+ }
16
+ if (excluded && excluded.includes(value)) {
17
+ return null;
18
+ }
19
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
20
+ return value;
21
+ }
22
+ if (Array.isArray(value)) {
23
+ const result = [];
24
+ for (let i = 0; i < value.length; i++) {
25
+ result[i] = deepCopy(value[i], excluded);
26
+ }
27
+ return result;
28
+ }
29
+ if (typeof value === "object") {
30
+ const result = {};
31
+ for (const key in value) {
32
+ if (Object.hasOwn(value, key)) {
33
+ result[key] = deepCopy(value[key], excluded);
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+ return excluded ? null : value;
39
+ }
40
+ __name(deepCopy, "deepCopy");
41
+
42
+ // src/playback/player.ts
43
+ var StatePlayer = class {
44
+ static {
45
+ __name(this, "StatePlayer");
46
+ }
47
+ looping = false;
48
+ loopStart = 0;
49
+ loopIndex = 0;
50
+ loopLength;
51
+ loopCallback = null;
52
+ constructor(loopLength = DEFAULT_LOOP_BUFFER_FRAMES) {
53
+ this.loopLength = loopLength;
54
+ }
55
+ /**
56
+ * Check if currently looping
57
+ */
58
+ isLooping() {
59
+ return this.looping;
60
+ }
61
+ /**
62
+ * Start loop playback
63
+ */
64
+ startLoop(position, callback) {
65
+ this.looping = true;
66
+ this.loopStart = Math.max(position, 1);
67
+ this.loopIndex = 0;
68
+ this.loopCallback = callback;
69
+ }
70
+ /**
71
+ * Stop loop playback
72
+ */
73
+ stopLoop() {
74
+ this.looping = false;
75
+ this.loopCallback = null;
76
+ return this.loopStart;
77
+ }
78
+ /**
79
+ * Update loop (call each frame)
80
+ * Returns position to replay, or null if not looping
81
+ */
82
+ updateLoop() {
83
+ if (!this.looping) {
84
+ return null;
85
+ }
86
+ if (this.loopIndex === 0) {
87
+ this.loopIndex++;
88
+ return this.loopStart;
89
+ }
90
+ this.loopIndex++;
91
+ if (this.loopIndex > this.loopLength) {
92
+ this.loopIndex = 0;
93
+ }
94
+ return this.loopStart - this.loopIndex;
95
+ }
96
+ /**
97
+ * Execute loop callback
98
+ */
99
+ executeCallback() {
100
+ if (this.loopCallback) {
101
+ this.loopCallback();
102
+ }
103
+ }
104
+ /**
105
+ * Restore state to target object
106
+ */
107
+ restoreState(target, snapshot) {
108
+ if (!snapshot || !target) {
109
+ return;
110
+ }
111
+ for (const key in target) {
112
+ if (Object.hasOwn(target, key) && !this.isProtectedKey(key)) {
113
+ delete target[key];
114
+ }
115
+ }
116
+ for (const key in snapshot) {
117
+ if (Object.hasOwn(snapshot, key)) {
118
+ target[key] = deepCopy(snapshot[key]);
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * Check if key should be protected from restoration
124
+ */
125
+ isProtectedKey(key) {
126
+ const protected_keys = [
127
+ "screen",
128
+ "audio",
129
+ "keyboard",
130
+ "mouse",
131
+ "touch",
132
+ "gamepad",
133
+ "system",
134
+ "storage",
135
+ "sprites",
136
+ "maps",
137
+ "sounds",
138
+ "music",
139
+ "assets",
140
+ "host",
141
+ "session",
142
+ "memory"
143
+ ];
144
+ return protected_keys.includes(key);
145
+ }
146
+ };
147
+
148
+ // src/recording/recorder.ts
149
+ var StateRecorder = class {
150
+ static {
151
+ __name(this, "StateRecorder");
152
+ }
153
+ history = [];
154
+ recordIndex = 0;
155
+ recordLength = 0;
156
+ maxLength;
157
+ excluded = [];
158
+ constructor(maxLength = DEFAULT_RECORD_BUFFER_FRAMES) {
159
+ this.maxLength = maxLength;
160
+ }
161
+ /**
162
+ * Set objects to exclude from serialization
163
+ */
164
+ setExcluded(excluded) {
165
+ this.excluded = excluded;
166
+ }
167
+ /**
168
+ * Record a state snapshot
169
+ */
170
+ record(state) {
171
+ const snapshot = this.makeStorableState(state);
172
+ this.history[this.recordIndex++] = snapshot;
173
+ this.recordLength = Math.min(this.recordLength + 1, this.maxLength);
174
+ if (this.recordIndex >= this.maxLength) {
175
+ this.recordIndex = 0;
176
+ }
177
+ }
178
+ /**
179
+ * Get state at specific position (0 = most recent)
180
+ */
181
+ getState(position) {
182
+ if (position >= this.recordLength) {
183
+ return null;
184
+ }
185
+ const index = (this.recordIndex - position - 1 + this.maxLength) % this.maxLength;
186
+ return this.history[index];
187
+ }
188
+ /**
189
+ * Get current record length
190
+ */
191
+ getLength() {
192
+ return this.recordLength;
193
+ }
194
+ /**
195
+ * Get maximum record length
196
+ */
197
+ getMaxLength() {
198
+ return this.maxLength;
199
+ }
200
+ /**
201
+ * Clear all recorded history
202
+ */
203
+ clear() {
204
+ this.history = [];
205
+ this.recordIndex = 0;
206
+ this.recordLength = 0;
207
+ }
208
+ /**
209
+ * Trim history to specific position
210
+ */
211
+ trimTo(position) {
212
+ if (position >= this.recordLength) {
213
+ return;
214
+ }
215
+ const histo = [];
216
+ const start = this.recordLength;
217
+ const end = position + 1;
218
+ for (let i = start; i >= end; i--) {
219
+ const index = (this.recordIndex - i + this.maxLength) % this.maxLength;
220
+ histo.push(this.history[index]);
221
+ }
222
+ this.history = histo;
223
+ this.recordIndex = this.history.length;
224
+ this.recordLength = this.history.length;
225
+ }
226
+ makeStorableState(value) {
227
+ return deepCopy(value, this.excluded);
228
+ }
229
+ };
230
+
231
+ // src/core/machine.ts
232
+ var TimeMachine = class {
233
+ static {
234
+ __name(this, "TimeMachine");
235
+ }
236
+ runtime;
237
+ recorder;
238
+ player;
239
+ recording = false;
240
+ replayPosition = 0;
241
+ statusCallback;
242
+ constructor(runtime) {
243
+ this.runtime = runtime;
244
+ this.recorder = new StateRecorder(DEFAULT_RECORD_BUFFER_FRAMES);
245
+ this.player = new StatePlayer(DEFAULT_LOOP_BUFFER_FRAMES);
246
+ this.setupExclusions();
247
+ }
248
+ /**
249
+ * Setup objects to exclude from recording
250
+ */
251
+ setupExclusions() {
252
+ const excluded = [];
253
+ if (this.runtime.vm?.context?.global) {
254
+ const global = this.runtime.vm.context.global;
255
+ if (global.random) excluded.push(global.random);
256
+ if (global.screen) excluded.push(global.screen);
257
+ if (global.audio) excluded.push(global.audio);
258
+ if (global.keyboard) excluded.push(global.keyboard);
259
+ if (global.mouse) excluded.push(global.mouse);
260
+ if (global.touch) excluded.push(global.touch);
261
+ if (global.gamepad) excluded.push(global.gamepad);
262
+ if (global.system) excluded.push(global.system);
263
+ if (global.storage) excluded.push(global.storage);
264
+ if (global.host) excluded.push(global.host);
265
+ if (global.session) excluded.push(global.session);
266
+ if (global.memory) excluded.push(global.memory);
267
+ }
268
+ this.recorder.setExcluded(excluded);
269
+ }
270
+ /**
271
+ * Step function - call each frame
272
+ */
273
+ step() {
274
+ if (!this.recording) {
275
+ return;
276
+ }
277
+ try {
278
+ if (this.replayPosition !== 0) {
279
+ this.recorder.trimTo(this.replayPosition);
280
+ if (this.player.isLooping()) {
281
+ this.player.startLoop(this.recorder.getLength(), () => this.loopCallback());
282
+ }
283
+ this.replayPosition = 0;
284
+ }
285
+ if (this.runtime.vm?.context?.global) {
286
+ this.recorder.record(this.runtime.vm.context.global);
287
+ }
288
+ this.sendStatus();
289
+ } catch (err) {
290
+ reportRuntimeError(this.runtime?.listener, APIErrorCode.E7082, {
291
+ error: String(err)
292
+ });
293
+ }
294
+ }
295
+ /**
296
+ * Handle incoming messages
297
+ */
298
+ messageReceived(data) {
299
+ switch (data.command) {
300
+ case "start_recording":
301
+ this.startRecording();
302
+ break;
303
+ case "stop_recording":
304
+ this.stopRecording();
305
+ break;
306
+ case "step_backward":
307
+ this.stepBackward();
308
+ break;
309
+ case "step_forward":
310
+ this.stepForward();
311
+ break;
312
+ case "replay_position":
313
+ if (data.position != null) {
314
+ this.setReplayPosition(data.position);
315
+ }
316
+ break;
317
+ case "start_looping":
318
+ this.startLooping();
319
+ break;
320
+ case "stop_looping":
321
+ this.stopLooping();
322
+ break;
323
+ }
324
+ }
325
+ /**
326
+ * Start recording
327
+ */
328
+ startRecording() {
329
+ if (this.recording) {
330
+ return;
331
+ }
332
+ try {
333
+ this.recording = true;
334
+ this.recorder.clear();
335
+ this.replayPosition = 0;
336
+ this.sendStatus();
337
+ } catch (err) {
338
+ this.recording = false;
339
+ reportRuntimeError(this.runtime?.listener, APIErrorCode.E7083, {
340
+ error: String(err)
341
+ });
342
+ }
343
+ }
344
+ /**
345
+ * Stop recording
346
+ */
347
+ stopRecording() {
348
+ if (!this.recording) {
349
+ return;
350
+ }
351
+ try {
352
+ this.recording = false;
353
+ this.sendStatus();
354
+ } catch (err) {
355
+ reportRuntimeError(this.runtime?.listener, APIErrorCode.E7083, {
356
+ error: String(err)
357
+ });
358
+ }
359
+ }
360
+ /**
361
+ * Step backward in time
362
+ */
363
+ stepBackward() {
364
+ if (this.replayPosition + 1 >= this.recorder.getLength()) {
365
+ return;
366
+ }
367
+ this.stopLooping();
368
+ this.replayPosition++;
369
+ this.replay();
370
+ this.sendStatus();
371
+ }
372
+ /**
373
+ * Step forward in time
374
+ */
375
+ stepForward() {
376
+ if (this.replayPosition <= 1) {
377
+ return;
378
+ }
379
+ this.stopLooping();
380
+ this.replayPosition--;
381
+ this.replay();
382
+ this.sendStatus();
383
+ }
384
+ /**
385
+ * Set replay position
386
+ */
387
+ setReplayPosition(position) {
388
+ if (!isFinite(position) || position < 0) {
389
+ reportRuntimeError(this.runtime?.listener, APIErrorCode.E7081, {
390
+ value: String(position)
391
+ });
392
+ return;
393
+ }
394
+ const pos = Math.round(position);
395
+ this.replayPosition = Math.max(2, Math.min(this.recorder.getLength() - 1, pos));
396
+ if (this.player.isLooping()) {
397
+ this.player.startLoop(this.replayPosition, () => this.loopCallback());
398
+ }
399
+ this.replay();
400
+ this.sendStatus();
401
+ }
402
+ /**
403
+ * Start looping
404
+ */
405
+ startLooping() {
406
+ if (this.recorder.getLength() === 0) {
407
+ return;
408
+ }
409
+ this.recording = false;
410
+ const position = Math.max(this.replayPosition, 1);
411
+ this.player.startLoop(position, () => this.loopCallback());
412
+ }
413
+ /**
414
+ * Stop looping
415
+ */
416
+ stopLooping() {
417
+ if (!this.player.isLooping()) {
418
+ return;
419
+ }
420
+ this.replayPosition = this.player.stopLoop();
421
+ this.sendStatus();
422
+ }
423
+ /**
424
+ * Replay state at current position
425
+ */
426
+ replay(skipDraw = false) {
427
+ if (this.replayPosition >= this.recorder.getLength()) {
428
+ return;
429
+ }
430
+ const snapshot = this.recorder.getState(this.replayPosition);
431
+ if (snapshot && this.runtime.vm?.context?.global) {
432
+ this.player.restoreState(this.runtime.vm.context.global, snapshot);
433
+ }
434
+ if (!skipDraw) {
435
+ this.runtime.drawCall?.();
436
+ }
437
+ }
438
+ /**
439
+ * Loop callback
440
+ */
441
+ loopCallback() {
442
+ const position = this.player.updateLoop();
443
+ if (position !== null) {
444
+ this.replayPosition = position;
445
+ this.replay(true);
446
+ this.runtime.updateCall?.();
447
+ this.runtime.drawCall?.();
448
+ }
449
+ this.sendStatus();
450
+ }
451
+ /**
452
+ * Send status update
453
+ */
454
+ sendStatus() {
455
+ if (this.statusCallback) {
456
+ this.statusCallback({
457
+ recording: this.recording,
458
+ looping: this.player.isLooping(),
459
+ position: this.replayPosition,
460
+ length: this.recorder.getLength(),
461
+ max: this.recorder.getMaxLength()
462
+ });
463
+ }
464
+ }
465
+ /**
466
+ * Advance the loop playback by one tick.
467
+ * Call once per real game frame (from the orchestrator's watch-step hook).
468
+ * No-op when not looping.
469
+ */
470
+ loopStep() {
471
+ if (this.player.isLooping()) {
472
+ this.player.executeCallback();
473
+ }
474
+ }
475
+ /**
476
+ * Set status callback
477
+ */
478
+ onStatus(callback) {
479
+ this.statusCallback = callback;
480
+ }
481
+ /**
482
+ * Check if recording
483
+ */
484
+ isRecording() {
485
+ return this.recording;
486
+ }
487
+ /**
488
+ * Check if looping
489
+ */
490
+ isLooping() {
491
+ return this.player.isLooping();
492
+ }
493
+ };
494
+ export {
495
+ StatePlayer,
496
+ StateRecorder,
497
+ TimeMachine
498
+ };
499
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/machine.ts","../src/constants.ts","../src/utils.ts","../src/playback/player.ts","../src/recording/recorder.ts"],"sourcesContent":["/**\n * TimeMachine - Main time machine controller\n *\n * Responsibilities:\n * - Coordinate recording and playback\n * - Handle commands\n * - Manage state\n */\n\nimport { APIErrorCode, reportRuntimeError } from \"@al8b/diagnostics\";\nimport { DEFAULT_LOOP_BUFFER_FRAMES, DEFAULT_RECORD_BUFFER_FRAMES } from \"../constants\";\nimport { StatePlayer } from \"../playback\";\nimport { StateRecorder } from \"../recording\";\nimport type { TimeMachineMessage, TimeMachineStatus } from \"../types\";\n\nexport interface TimeMachineRuntime {\n\tvm?: {\n\t\tcontext?: {\n\t\t\tglobal?: any;\n\t\t};\n\t};\n\tupdateCall?: () => void;\n\tdrawCall?: () => void;\n}\n\nexport class TimeMachine {\n\tprivate runtime: TimeMachineRuntime;\n\tprivate recorder: StateRecorder;\n\tprivate player: StatePlayer;\n\tprivate recording = false;\n\tprivate replayPosition = 0;\n\tprivate statusCallback?: (status: TimeMachineStatus) => void;\n\n\tconstructor(runtime: TimeMachineRuntime) {\n\t\tthis.runtime = runtime;\n\t\tthis.recorder = new StateRecorder(DEFAULT_RECORD_BUFFER_FRAMES);\n\t\tthis.player = new StatePlayer(DEFAULT_LOOP_BUFFER_FRAMES);\n\n\t\t// Configure which objects should be excluded from state recording\n\t\tthis.setupExclusions();\n\t}\n\n\t/**\n\t * Setup objects to exclude from recording\n\t */\n\tprivate setupExclusions(): void {\n\t\tconst excluded: any[] = [];\n\n\t\tif (this.runtime.vm?.context?.global) {\n\t\t\tconst global = this.runtime.vm.context.global;\n\n\t\t\t// Exclude system APIs and non-serializable objects from recording\n\t\t\tif (global.random) excluded.push(global.random);\n\t\t\tif (global.screen) excluded.push(global.screen);\n\t\t\tif (global.audio) excluded.push(global.audio);\n\t\t\tif (global.keyboard) excluded.push(global.keyboard);\n\t\t\tif (global.mouse) excluded.push(global.mouse);\n\t\t\tif (global.touch) excluded.push(global.touch);\n\t\t\tif (global.gamepad) excluded.push(global.gamepad);\n\t\t\tif (global.system) excluded.push(global.system);\n\t\t\tif (global.storage) excluded.push(global.storage);\n\t\t\tif (global.host) excluded.push(global.host);\n\t\t\tif (global.session) excluded.push(global.session);\n\t\t\tif (global.memory) excluded.push(global.memory);\n\t\t}\n\n\t\tthis.recorder.setExcluded(excluded);\n\t}\n\n\t/**\n\t * Step function - call each frame\n\t */\n\tstep(): void {\n\t\tif (!this.recording) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Apply replay position changes and update loop if active\n\t\t\tif (this.replayPosition !== 0) {\n\t\t\t\tthis.recorder.trimTo(this.replayPosition);\n\t\t\t\tif (this.player.isLooping()) {\n\t\t\t\t\tthis.player.startLoop(this.recorder.getLength(), () => this.loopCallback());\n\t\t\t\t}\n\t\t\t\tthis.replayPosition = 0;\n\t\t\t}\n\n\t\t\t// Capture current global state snapshot for time travel\n\t\t\tif (this.runtime.vm?.context?.global) {\n\t\t\t\tthis.recorder.record(this.runtime.vm.context.global);\n\t\t\t}\n\n\t\t\tthis.sendStatus();\n\t\t} catch (err) {\n\t\t\treportRuntimeError((this.runtime as any)?.listener, APIErrorCode.E7082, { error: String(err) });\n\t\t}\n\t}\n\n\t/**\n\t * Handle incoming messages\n\t */\n\tmessageReceived(data: TimeMachineMessage): void {\n\t\tswitch (data.command) {\n\t\t\tcase \"start_recording\":\n\t\t\t\tthis.startRecording();\n\t\t\t\tbreak;\n\n\t\t\tcase \"stop_recording\":\n\t\t\t\tthis.stopRecording();\n\t\t\t\tbreak;\n\n\t\t\tcase \"step_backward\":\n\t\t\t\tthis.stepBackward();\n\t\t\t\tbreak;\n\n\t\t\tcase \"step_forward\":\n\t\t\t\tthis.stepForward();\n\t\t\t\tbreak;\n\n\t\t\tcase \"replay_position\":\n\t\t\t\tif (data.position != null) {\n\t\t\t\t\tthis.setReplayPosition(data.position);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"start_looping\":\n\t\t\t\tthis.startLooping();\n\t\t\t\tbreak;\n\n\t\t\tcase \"stop_looping\":\n\t\t\t\tthis.stopLooping();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/**\n\t * Start recording\n\t */\n\tprivate startRecording(): void {\n\t\tif (this.recording) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.recording = true;\n\t\t\tthis.recorder.clear();\n\t\t\tthis.replayPosition = 0;\n\t\t\tthis.sendStatus();\n\t\t} catch (err) {\n\t\t\tthis.recording = false;\n\t\t\treportRuntimeError((this.runtime as any)?.listener, APIErrorCode.E7083, { error: String(err) });\n\t\t}\n\t}\n\n\t/**\n\t * Stop recording\n\t */\n\tprivate stopRecording(): void {\n\t\tif (!this.recording) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.recording = false;\n\t\t\tthis.sendStatus();\n\t\t} catch (err) {\n\t\t\treportRuntimeError((this.runtime as any)?.listener, APIErrorCode.E7083, { error: String(err) });\n\t\t}\n\t}\n\n\t/**\n\t * Step backward in time\n\t */\n\tprivate stepBackward(): void {\n\t\tif (this.replayPosition + 1 >= this.recorder.getLength()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.stopLooping();\n\t\tthis.replayPosition++;\n\t\tthis.replay();\n\t\tthis.sendStatus();\n\t}\n\n\t/**\n\t * Step forward in time\n\t */\n\tprivate stepForward(): void {\n\t\tif (this.replayPosition <= 1) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.stopLooping();\n\t\tthis.replayPosition--;\n\t\tthis.replay();\n\t\tthis.sendStatus();\n\t}\n\n\t/**\n\t * Set replay position\n\t */\n\tprivate setReplayPosition(position: number): void {\n\t\t// Validate time value is finite and non-negative\n\t\tif (!isFinite(position) || position < 0) {\n\t\t\treportRuntimeError((this.runtime as any)?.listener, APIErrorCode.E7081, { value: String(position) });\n\t\t\treturn;\n\t\t}\n\n\t\tconst pos = Math.round(position);\n\t\tthis.replayPosition = Math.max(2, Math.min(this.recorder.getLength() - 1, pos));\n\n\t\tif (this.player.isLooping()) {\n\t\t\tthis.player.startLoop(this.replayPosition, () => this.loopCallback());\n\t\t}\n\n\t\tthis.replay();\n\t\tthis.sendStatus();\n\t}\n\n\t/**\n\t * Start looping\n\t */\n\tprivate startLooping(): void {\n\t\tif (this.recorder.getLength() === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.recording = false;\n\t\tconst position = Math.max(this.replayPosition, 1);\n\t\tthis.player.startLoop(position, () => this.loopCallback());\n\t}\n\n\t/**\n\t * Stop looping\n\t */\n\tprivate stopLooping(): void {\n\t\tif (!this.player.isLooping()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.replayPosition = this.player.stopLoop();\n\t\tthis.sendStatus();\n\t}\n\n\t/**\n\t * Replay state at current position\n\t */\n\tprivate replay(skipDraw = false): void {\n\t\tif (this.replayPosition >= this.recorder.getLength()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshot = this.recorder.getState(this.replayPosition);\n\t\tif (snapshot && this.runtime.vm?.context?.global) {\n\t\t\tthis.player.restoreState(this.runtime.vm.context.global, snapshot);\n\t\t}\n\n\t\tif (!skipDraw) {\n\t\t\tthis.runtime.drawCall?.();\n\t\t}\n\t}\n\n\t/**\n\t * Loop callback\n\t */\n\tprivate loopCallback(): void {\n\t\tconst position = this.player.updateLoop();\n\t\tif (position !== null) {\n\t\t\tthis.replayPosition = position;\n\t\t\tthis.replay(true);\n\t\t\tthis.runtime.updateCall?.();\n\t\t\tthis.runtime.drawCall?.();\n\t\t}\n\t\tthis.sendStatus();\n\t}\n\n\t/**\n\t * Send status update\n\t */\n\tprivate sendStatus(): void {\n\t\tif (this.statusCallback) {\n\t\t\tthis.statusCallback({\n\t\t\t\trecording: this.recording,\n\t\t\t\tlooping: this.player.isLooping(),\n\t\t\t\tposition: this.replayPosition,\n\t\t\t\tlength: this.recorder.getLength(),\n\t\t\t\tmax: this.recorder.getMaxLength(),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Advance the loop playback by one tick.\n\t * Call once per real game frame (from the orchestrator's watch-step hook).\n\t * No-op when not looping.\n\t */\n\tloopStep(): void {\n\t\tif (this.player.isLooping()) {\n\t\t\tthis.player.executeCallback();\n\t\t}\n\t}\n\n\t/**\n\t * Set status callback\n\t */\n\tonStatus(callback: (status: TimeMachineStatus) => void): void {\n\t\tthis.statusCallback = callback;\n\t}\n\n\t/**\n\t * Check if recording\n\t */\n\tisRecording(): boolean {\n\t\treturn this.recording;\n\t}\n\n\t/**\n\t * Check if looping\n\t */\n\tisLooping(): boolean {\n\t\treturn this.player.isLooping();\n\t}\n}\n","/** Default recording buffer: 30 seconds at 60fps (1800 frames) */\nexport const DEFAULT_RECORD_BUFFER_FRAMES = 60 * 30;\n\n/** Default loop playback buffer: 4 seconds at 60fps (240 frames) */\nexport const DEFAULT_LOOP_BUFFER_FRAMES = 60 * 4;\n","/**\n * Deep copy a value, optionally skipping excluded references.\n *\n * @param value - The value to deep copy\n * @param excluded - Optional array of object references to skip (replaced with null)\n */\nexport function deepCopy(value: any, excluded?: any[]): any {\n\tif (value == null) {\n\t\treturn value;\n\t}\n\n\tif (excluded && excluded.includes(value)) {\n\t\treturn null;\n\t}\n\n\tif (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: any[] = [];\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tresult[i] = deepCopy(value[i], excluded);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (typeof value === \"object\") {\n\t\tconst result: any = {};\n\t\tfor (const key in value) {\n\t\t\tif (Object.hasOwn(value, key)) {\n\t\t\t\tresult[key] = deepCopy(value[key], excluded);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t// Non-serializable types: return null when filtering, passthrough otherwise\n\treturn excluded ? null : value;\n}\n","/**\n * StatePlayer - Handles replay and loop playback\n *\n * Responsibilities:\n * - Restore state snapshots\n * - Manage loop playback\n * - Control playback position\n */\nimport { DEFAULT_LOOP_BUFFER_FRAMES } from \"../constants\";\nimport { deepCopy } from \"../utils\";\n\nimport type { StateSnapshot } from \"../types\";\n\nexport class StatePlayer {\n\tprivate looping = false;\n\tprivate loopStart = 0;\n\tprivate loopIndex = 0;\n\tprivate loopLength: number;\n\tprivate loopCallback: (() => void) | null = null;\n\n\tconstructor(loopLength = DEFAULT_LOOP_BUFFER_FRAMES) {\n\t\tthis.loopLength = loopLength;\n\t}\n\n\t/**\n\t * Check if currently looping\n\t */\n\tisLooping(): boolean {\n\t\treturn this.looping;\n\t}\n\n\t/**\n\t * Start loop playback\n\t */\n\tstartLoop(position: number, callback: () => void): void {\n\t\tthis.looping = true;\n\t\tthis.loopStart = Math.max(position, 1);\n\t\tthis.loopIndex = 0;\n\t\tthis.loopCallback = callback;\n\t}\n\n\t/**\n\t * Stop loop playback\n\t */\n\tstopLoop(): number {\n\t\tthis.looping = false;\n\t\tthis.loopCallback = null;\n\t\treturn this.loopStart;\n\t}\n\n\t/**\n\t * Update loop (call each frame)\n\t * Returns position to replay, or null if not looping\n\t */\n\tupdateLoop(): number | null {\n\t\tif (!this.looping) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (this.loopIndex === 0) {\n\t\t\tthis.loopIndex++;\n\t\t\treturn this.loopStart;\n\t\t}\n\n\t\tthis.loopIndex++;\n\t\tif (this.loopIndex > this.loopLength) {\n\t\t\tthis.loopIndex = 0;\n\t\t}\n\n\t\treturn this.loopStart - this.loopIndex;\n\t}\n\n\t/**\n\t * Execute loop callback\n\t */\n\texecuteCallback(): void {\n\t\tif (this.loopCallback) {\n\t\t\tthis.loopCallback();\n\t\t}\n\t}\n\n\t/**\n\t * Restore state to target object\n\t */\n\trestoreState(target: any, snapshot: StateSnapshot): void {\n\t\tif (!snapshot || !target) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove all existing properties except protected system APIs\n\t\tfor (const key in target) {\n\t\t\tif (Object.hasOwn(target, key) && !this.isProtectedKey(key)) {\n\t\t\t\tdelete target[key];\n\t\t\t}\n\t\t}\n\n\t\t// Apply snapshot properties to target object via deep copy\n\t\tfor (const key in snapshot) {\n\t\t\tif (Object.hasOwn(snapshot, key)) {\n\t\t\t\ttarget[key] = deepCopy(snapshot[key]);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if key should be protected from restoration\n\t */\n\tprivate isProtectedKey(key: string): boolean {\n\t\t// Prevent system APIs and runtime objects from being overwritten during restore\n\t\tconst protected_keys = [\n\t\t\t\"screen\",\n\t\t\t\"audio\",\n\t\t\t\"keyboard\",\n\t\t\t\"mouse\",\n\t\t\t\"touch\",\n\t\t\t\"gamepad\",\n\t\t\t\"system\",\n\t\t\t\"storage\",\n\t\t\t\"sprites\",\n\t\t\t\"maps\",\n\t\t\t\"sounds\",\n\t\t\t\"music\",\n\t\t\t\"assets\",\n\t\t\t\"host\",\n\t\t\t\"session\",\n\t\t\t\"memory\",\n\t\t];\n\t\treturn protected_keys.includes(key);\n\t}\n\n}\n","/**\n * StateRecorder - Records game state history\n *\n * Responsibilities:\n * - Capture state snapshots\n * - Manage circular buffer\n * - Exclude non-serializable objects\n */\nimport { DEFAULT_RECORD_BUFFER_FRAMES } from \"../constants\";\nimport { deepCopy } from \"../utils\";\n\nimport type { StateSnapshot } from \"../types\";\n\nexport class StateRecorder {\n\tprivate history: StateSnapshot[] = [];\n\tprivate recordIndex = 0;\n\tprivate recordLength = 0;\n\tprivate maxLength: number;\n\tprivate excluded: any[] = [];\n\n\tconstructor(maxLength = DEFAULT_RECORD_BUFFER_FRAMES) {\n\t\tthis.maxLength = maxLength;\n\t}\n\n\t/**\n\t * Set objects to exclude from serialization\n\t */\n\tsetExcluded(excluded: any[]): void {\n\t\tthis.excluded = excluded;\n\t}\n\n\t/**\n\t * Record a state snapshot\n\t */\n\trecord(state: any): void {\n\t\tconst snapshot = this.makeStorableState(state);\n\t\tthis.history[this.recordIndex++] = snapshot;\n\t\tthis.recordLength = Math.min(this.recordLength + 1, this.maxLength);\n\n\t\tif (this.recordIndex >= this.maxLength) {\n\t\t\tthis.recordIndex = 0;\n\t\t}\n\t}\n\n\t/**\n\t * Get state at specific position (0 = most recent)\n\t */\n\tgetState(position: number): StateSnapshot | null {\n\t\tif (position >= this.recordLength) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst index = (this.recordIndex - position - 1 + this.maxLength) % this.maxLength;\n\t\treturn this.history[index];\n\t}\n\n\t/**\n\t * Get current record length\n\t */\n\tgetLength(): number {\n\t\treturn this.recordLength;\n\t}\n\n\t/**\n\t * Get maximum record length\n\t */\n\tgetMaxLength(): number {\n\t\treturn this.maxLength;\n\t}\n\n\t/**\n\t * Clear all recorded history\n\t */\n\tclear(): void {\n\t\tthis.history = [];\n\t\tthis.recordIndex = 0;\n\t\tthis.recordLength = 0;\n\t}\n\n\t/**\n\t * Trim history to specific position\n\t */\n\ttrimTo(position: number): void {\n\t\tif (position >= this.recordLength) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst histo: StateSnapshot[] = [];\n\t\tconst start = this.recordLength;\n\t\tconst end = position + 1;\n\n\t\tfor (let i = start; i >= end; i--) {\n\t\t\tconst index = (this.recordIndex - i + this.maxLength) % this.maxLength;\n\t\t\thisto.push(this.history[index]);\n\t\t}\n\n\t\tthis.history = histo;\n\t\tthis.recordIndex = this.history.length;\n\t\tthis.recordLength = this.history.length;\n\t}\n\n\tprivate makeStorableState(value: any): any {\n\t\treturn deepCopy(value, this.excluded);\n\t}\n}\n"],"mappings":";;;;AASA,SAASA,cAAcC,0BAA0B;;;ACR1C,IAAMC,+BAA+B,KAAK;AAG1C,IAAMC,6BAA6B,KAAK;;;ACExC,SAASC,SAASC,OAAYC,UAAgB;AACpD,MAAID,SAAS,MAAM;AAClB,WAAOA;EACR;AAEA,MAAIC,YAAYA,SAASC,SAASF,KAAAA,GAAQ;AACzC,WAAO;EACR;AAEA,MAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,YAAY,OAAOA,UAAU,WAAW;AACzF,WAAOA;EACR;AAEA,MAAIG,MAAMC,QAAQJ,KAAAA,GAAQ;AACzB,UAAMK,SAAgB,CAAA;AACtB,aAASC,IAAI,GAAGA,IAAIN,MAAMO,QAAQD,KAAK;AACtCD,aAAOC,CAAAA,IAAKP,SAASC,MAAMM,CAAAA,GAAIL,QAAAA;IAChC;AACA,WAAOI;EACR;AAEA,MAAI,OAAOL,UAAU,UAAU;AAC9B,UAAMK,SAAc,CAAC;AACrB,eAAWG,OAAOR,OAAO;AACxB,UAAIS,OAAOC,OAAOV,OAAOQ,GAAAA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EACD;;;;;;EAOAC,WAAiB;AAChB,QAAI,KAAK3E,OAAO6B,UAAS,GAAI;AAC5B,WAAK7B,OAAO4E,gBAAe;IAC5B;EACD;;;;EAKAC,SAASC,UAAqD;AAC7D,SAAK3E,iBAAiB2E;EACvB;;;;EAKAC,cAAuB;AACtB,WAAO,KAAK9E;EACb;;;;EAKA4B,YAAqB;AACpB,WAAO,KAAK7B,OAAO6B,UAAS;EAC7B;AACD;","names":["APIErrorCode","reportRuntimeError","DEFAULT_RECORD_BUFFER_FRAMES","DEFAULT_LOOP_BUFFER_FRAMES","deepCopy","value","excluded","includes","Array","isArray","result","i","length","key","Object","hasOwn","StatePlayer","looping","loopStart","loopIndex","loopLength","loopCallback","DEFAULT_LOOP_BUFFER_FRAMES","isLooping","startLoop","position","callback","Math","max","stopLoop","updateLoop","executeCallback","restoreState","target","snapshot","key","Object","hasOwn","isProtectedKey","deepCopy","protected_keys","includes","StateRecorder","history","recordIndex","recordLength","maxLength","excluded","DEFAULT_RECORD_BUFFER_FRAMES","setExcluded","record","state","snapshot","makeStorableState","Math","min","getState","position","index","getLength","getMaxLength","clear","trimTo","histo","start","end","i","push","length","value","deepCopy","TimeMachine","runtime","recorder","player","recording","replayPosition","statusCallback","StateRecorder","DEFAULT_RECORD_BUFFER_FRAMES","StatePlayer","DEFAULT_LOOP_BUFFER_FRAMES","setupExclusions","excluded","vm","context","global","random","push","screen","audio","keyboard","mouse","touch","gamepad","system","storage","host","session","memory","setExcluded","step","trimTo","isLooping","startLoop","getLength","loopCallback","record","sendStatus","err","reportRuntimeError","listener","APIErrorCode","E7082","error","String","messageReceived","data","command","startRecording","stopRecording","stepBackward","stepForward","position","setReplayPosition","startLooping","stopLooping","clear","E7083","replay","isFinite","E7081","value","pos","Math","round","max","min","stopLoop","skipDraw","snapshot","getState","restoreState","drawCall","updateLoop","updateCall","looping","length","getMaxLength","loopStep","executeCallback","onStatus","callback","isRecording"]}
@@ -0,0 +1,2 @@
1
+ export { StatePlayer } from './player.mjs';
2
+ import '../types/state.mjs';
@@ -0,0 +1,2 @@
1
+ export { StatePlayer } from './player.js';
2
+ import '../types/state.js';