@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.
- package/README.md +23 -0
- package/dist/constants.d.mts +6 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +34 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +8 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +522 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +497 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/machine.d.mts +101 -0
- package/dist/core/machine.d.ts +101 -0
- package/dist/core/machine.js +520 -0
- package/dist/core/machine.js.map +1 -0
- package/dist/core/machine.mjs +497 -0
- package/dist/core/machine.mjs.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +526 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +499 -0
- package/dist/index.mjs.map +1 -0
- package/dist/playback/index.d.mts +2 -0
- package/dist/playback/index.d.ts +2 -0
- package/dist/playback/index.js +172 -0
- package/dist/playback/index.js.map +1 -0
- package/dist/playback/index.mjs +147 -0
- package/dist/playback/index.mjs.map +1 -0
- package/dist/playback/player.d.mts +41 -0
- package/dist/playback/player.d.ts +41 -0
- package/dist/playback/player.js +172 -0
- package/dist/playback/player.js.map +1 -0
- package/dist/playback/player.mjs +147 -0
- package/dist/playback/player.mjs.map +1 -0
- package/dist/recording/index.d.mts +2 -0
- package/dist/recording/index.d.ts +2 -0
- package/dist/recording/index.js +149 -0
- package/dist/recording/index.js.map +1 -0
- package/dist/recording/index.mjs +124 -0
- package/dist/recording/index.mjs.map +1 -0
- package/dist/recording/recorder.d.mts +41 -0
- package/dist/recording/recorder.d.ts +41 -0
- package/dist/recording/recorder.js +149 -0
- package/dist/recording/recorder.js.map +1 -0
- package/dist/recording/recorder.mjs +124 -0
- package/dist/recording/recorder.mjs.map +1 -0
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/state.d.mts +33 -0
- package/dist/types/state.d.ts +33 -0
- package/dist/types/state.js +19 -0
- package/dist/types/state.js.map +1 -0
- package/dist/types/state.mjs +1 -0
- package/dist/types/state.mjs.map +1 -0
- package/dist/utils.d.mts +9 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +60 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +37 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_RECORD_BUFFER_FRAMES = 60 * 30;
|
|
6
|
+
var DEFAULT_LOOP_BUFFER_FRAMES = 60 * 4;
|
|
7
|
+
|
|
8
|
+
// src/utils.ts
|
|
9
|
+
function deepCopy(value, excluded) {
|
|
10
|
+
if (value == null) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (excluded && excluded.includes(value)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
const result = [];
|
|
21
|
+
for (let i = 0; i < value.length; i++) {
|
|
22
|
+
result[i] = deepCopy(value[i], excluded);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "object") {
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const key in value) {
|
|
29
|
+
if (Object.hasOwn(value, key)) {
|
|
30
|
+
result[key] = deepCopy(value[key], excluded);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return excluded ? null : value;
|
|
36
|
+
}
|
|
37
|
+
__name(deepCopy, "deepCopy");
|
|
38
|
+
|
|
39
|
+
// src/playback/player.ts
|
|
40
|
+
var StatePlayer = class {
|
|
41
|
+
static {
|
|
42
|
+
__name(this, "StatePlayer");
|
|
43
|
+
}
|
|
44
|
+
looping = false;
|
|
45
|
+
loopStart = 0;
|
|
46
|
+
loopIndex = 0;
|
|
47
|
+
loopLength;
|
|
48
|
+
loopCallback = null;
|
|
49
|
+
constructor(loopLength = DEFAULT_LOOP_BUFFER_FRAMES) {
|
|
50
|
+
this.loopLength = loopLength;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if currently looping
|
|
54
|
+
*/
|
|
55
|
+
isLooping() {
|
|
56
|
+
return this.looping;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Start loop playback
|
|
60
|
+
*/
|
|
61
|
+
startLoop(position, callback) {
|
|
62
|
+
this.looping = true;
|
|
63
|
+
this.loopStart = Math.max(position, 1);
|
|
64
|
+
this.loopIndex = 0;
|
|
65
|
+
this.loopCallback = callback;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stop loop playback
|
|
69
|
+
*/
|
|
70
|
+
stopLoop() {
|
|
71
|
+
this.looping = false;
|
|
72
|
+
this.loopCallback = null;
|
|
73
|
+
return this.loopStart;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Update loop (call each frame)
|
|
77
|
+
* Returns position to replay, or null if not looping
|
|
78
|
+
*/
|
|
79
|
+
updateLoop() {
|
|
80
|
+
if (!this.looping) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (this.loopIndex === 0) {
|
|
84
|
+
this.loopIndex++;
|
|
85
|
+
return this.loopStart;
|
|
86
|
+
}
|
|
87
|
+
this.loopIndex++;
|
|
88
|
+
if (this.loopIndex > this.loopLength) {
|
|
89
|
+
this.loopIndex = 0;
|
|
90
|
+
}
|
|
91
|
+
return this.loopStart - this.loopIndex;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Execute loop callback
|
|
95
|
+
*/
|
|
96
|
+
executeCallback() {
|
|
97
|
+
if (this.loopCallback) {
|
|
98
|
+
this.loopCallback();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Restore state to target object
|
|
103
|
+
*/
|
|
104
|
+
restoreState(target, snapshot) {
|
|
105
|
+
if (!snapshot || !target) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
for (const key in target) {
|
|
109
|
+
if (Object.hasOwn(target, key) && !this.isProtectedKey(key)) {
|
|
110
|
+
delete target[key];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const key in snapshot) {
|
|
114
|
+
if (Object.hasOwn(snapshot, key)) {
|
|
115
|
+
target[key] = deepCopy(snapshot[key]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if key should be protected from restoration
|
|
121
|
+
*/
|
|
122
|
+
isProtectedKey(key) {
|
|
123
|
+
const protected_keys = [
|
|
124
|
+
"screen",
|
|
125
|
+
"audio",
|
|
126
|
+
"keyboard",
|
|
127
|
+
"mouse",
|
|
128
|
+
"touch",
|
|
129
|
+
"gamepad",
|
|
130
|
+
"system",
|
|
131
|
+
"storage",
|
|
132
|
+
"sprites",
|
|
133
|
+
"maps",
|
|
134
|
+
"sounds",
|
|
135
|
+
"music",
|
|
136
|
+
"assets",
|
|
137
|
+
"host",
|
|
138
|
+
"session",
|
|
139
|
+
"memory"
|
|
140
|
+
];
|
|
141
|
+
return protected_keys.includes(key);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
export {
|
|
145
|
+
StatePlayer
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=player.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts","../../src/utils.ts","../../src/playback/player.ts"],"sourcesContent":["/** 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"],"mappings":";;;;AACO,IAAMA,+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,GAAM;AAC9BH,eAAOG,GAAAA,IAAOT,SAASC,MAAMQ,GAAAA,GAAMP,QAAAA;MACpC;IACD;AACA,WAAOI;EACR;AAGA,SAAOJ,WAAW,OAAOD;AAC1B;AAjCgBD;;;ACOT,IAAMY,cAAN,MAAMA;EAbb,OAaaA;;;EACJC,UAAU;EACVC,YAAY;EACZC,Y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T_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"]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/recording/index.ts
|
|
22
|
+
var recording_exports = {};
|
|
23
|
+
__export(recording_exports, {
|
|
24
|
+
StateRecorder: () => StateRecorder
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(recording_exports);
|
|
27
|
+
|
|
28
|
+
// src/constants.ts
|
|
29
|
+
var DEFAULT_RECORD_BUFFER_FRAMES = 60 * 30;
|
|
30
|
+
var DEFAULT_LOOP_BUFFER_FRAMES = 60 * 4;
|
|
31
|
+
|
|
32
|
+
// src/utils.ts
|
|
33
|
+
function deepCopy(value, excluded) {
|
|
34
|
+
if (value == null) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (excluded && excluded.includes(value)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
const result = [];
|
|
45
|
+
for (let i = 0; i < value.length; i++) {
|
|
46
|
+
result[i] = deepCopy(value[i], excluded);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === "object") {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const key in value) {
|
|
53
|
+
if (Object.hasOwn(value, key)) {
|
|
54
|
+
result[key] = deepCopy(value[key], excluded);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
return excluded ? null : value;
|
|
60
|
+
}
|
|
61
|
+
__name(deepCopy, "deepCopy");
|
|
62
|
+
|
|
63
|
+
// src/recording/recorder.ts
|
|
64
|
+
var StateRecorder = class {
|
|
65
|
+
static {
|
|
66
|
+
__name(this, "StateRecorder");
|
|
67
|
+
}
|
|
68
|
+
history = [];
|
|
69
|
+
recordIndex = 0;
|
|
70
|
+
recordLength = 0;
|
|
71
|
+
maxLength;
|
|
72
|
+
excluded = [];
|
|
73
|
+
constructor(maxLength = DEFAULT_RECORD_BUFFER_FRAMES) {
|
|
74
|
+
this.maxLength = maxLength;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Set objects to exclude from serialization
|
|
78
|
+
*/
|
|
79
|
+
setExcluded(excluded) {
|
|
80
|
+
this.excluded = excluded;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Record a state snapshot
|
|
84
|
+
*/
|
|
85
|
+
record(state) {
|
|
86
|
+
const snapshot = this.makeStorableState(state);
|
|
87
|
+
this.history[this.recordIndex++] = snapshot;
|
|
88
|
+
this.recordLength = Math.min(this.recordLength + 1, this.maxLength);
|
|
89
|
+
if (this.recordIndex >= this.maxLength) {
|
|
90
|
+
this.recordIndex = 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get state at specific position (0 = most recent)
|
|
95
|
+
*/
|
|
96
|
+
getState(position) {
|
|
97
|
+
if (position >= this.recordLength) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const index = (this.recordIndex - position - 1 + this.maxLength) % this.maxLength;
|
|
101
|
+
return this.history[index];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get current record length
|
|
105
|
+
*/
|
|
106
|
+
getLength() {
|
|
107
|
+
return this.recordLength;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get maximum record length
|
|
111
|
+
*/
|
|
112
|
+
getMaxLength() {
|
|
113
|
+
return this.maxLength;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Clear all recorded history
|
|
117
|
+
*/
|
|
118
|
+
clear() {
|
|
119
|
+
this.history = [];
|
|
120
|
+
this.recordIndex = 0;
|
|
121
|
+
this.recordLength = 0;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Trim history to specific position
|
|
125
|
+
*/
|
|
126
|
+
trimTo(position) {
|
|
127
|
+
if (position >= this.recordLength) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const histo = [];
|
|
131
|
+
const start = this.recordLength;
|
|
132
|
+
const end = position + 1;
|
|
133
|
+
for (let i = start; i >= end; i--) {
|
|
134
|
+
const index = (this.recordIndex - i + this.maxLength) % this.maxLength;
|
|
135
|
+
histo.push(this.history[index]);
|
|
136
|
+
}
|
|
137
|
+
this.history = histo;
|
|
138
|
+
this.recordIndex = this.history.length;
|
|
139
|
+
this.recordLength = this.history.length;
|
|
140
|
+
}
|
|
141
|
+
makeStorableState(value) {
|
|
142
|
+
return deepCopy(value, this.excluded);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
StateRecorder
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/recording/index.ts","../../src/constants.ts","../../src/utils.ts","../../src/recording/recorder.ts"],"sourcesContent":["/**\n * Recording module exports\n */\n\nexport { StateRecorder } from \"./recorder\";\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 * 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":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACCO,IAAMA,+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,GAAM;AAC9BH,eAAOG,GAAAA,IAAOT,SAASC,MAAMQ,GAAAA,GAAMP,QAAAA;MACpC;IACD;AACA,WAAOI;EACR;AAGA,SAAOJ,WAAW,OAAOD;AAC1B;AAjCgBD;;;ACOT,IAAMY,gBAAN,MAAMA;EAbb,OAaaA;;;EACJC,UAA2B,CAAA;EAC3BC,cAAc;EACdC,eAAe;EACfC;EACAC,WAAkB,CAAA;EAE1B,YAAYD,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T_LOOP_BUFFER_FRAMES","deepCopy","value","excluded","includes","Array","isArray","result","i","length","key","Object","hasOwn","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"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_RECORD_BUFFER_FRAMES = 60 * 30;
|
|
6
|
+
var DEFAULT_LOOP_BUFFER_FRAMES = 60 * 4;
|
|
7
|
+
|
|
8
|
+
// src/utils.ts
|
|
9
|
+
function deepCopy(value, excluded) {
|
|
10
|
+
if (value == null) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (excluded && excluded.includes(value)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
const result = [];
|
|
21
|
+
for (let i = 0; i < value.length; i++) {
|
|
22
|
+
result[i] = deepCopy(value[i], excluded);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "object") {
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const key in value) {
|
|
29
|
+
if (Object.hasOwn(value, key)) {
|
|
30
|
+
result[key] = deepCopy(value[key], excluded);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return excluded ? null : value;
|
|
36
|
+
}
|
|
37
|
+
__name(deepCopy, "deepCopy");
|
|
38
|
+
|
|
39
|
+
// src/recording/recorder.ts
|
|
40
|
+
var StateRecorder = class {
|
|
41
|
+
static {
|
|
42
|
+
__name(this, "StateRecorder");
|
|
43
|
+
}
|
|
44
|
+
history = [];
|
|
45
|
+
recordIndex = 0;
|
|
46
|
+
recordLength = 0;
|
|
47
|
+
maxLength;
|
|
48
|
+
excluded = [];
|
|
49
|
+
constructor(maxLength = DEFAULT_RECORD_BUFFER_FRAMES) {
|
|
50
|
+
this.maxLength = maxLength;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set objects to exclude from serialization
|
|
54
|
+
*/
|
|
55
|
+
setExcluded(excluded) {
|
|
56
|
+
this.excluded = excluded;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Record a state snapshot
|
|
60
|
+
*/
|
|
61
|
+
record(state) {
|
|
62
|
+
const snapshot = this.makeStorableState(state);
|
|
63
|
+
this.history[this.recordIndex++] = snapshot;
|
|
64
|
+
this.recordLength = Math.min(this.recordLength + 1, this.maxLength);
|
|
65
|
+
if (this.recordIndex >= this.maxLength) {
|
|
66
|
+
this.recordIndex = 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get state at specific position (0 = most recent)
|
|
71
|
+
*/
|
|
72
|
+
getState(position) {
|
|
73
|
+
if (position >= this.recordLength) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const index = (this.recordIndex - position - 1 + this.maxLength) % this.maxLength;
|
|
77
|
+
return this.history[index];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get current record length
|
|
81
|
+
*/
|
|
82
|
+
getLength() {
|
|
83
|
+
return this.recordLength;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get maximum record length
|
|
87
|
+
*/
|
|
88
|
+
getMaxLength() {
|
|
89
|
+
return this.maxLength;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Clear all recorded history
|
|
93
|
+
*/
|
|
94
|
+
clear() {
|
|
95
|
+
this.history = [];
|
|
96
|
+
this.recordIndex = 0;
|
|
97
|
+
this.recordLength = 0;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Trim history to specific position
|
|
101
|
+
*/
|
|
102
|
+
trimTo(position) {
|
|
103
|
+
if (position >= this.recordLength) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const histo = [];
|
|
107
|
+
const start = this.recordLength;
|
|
108
|
+
const end = position + 1;
|
|
109
|
+
for (let i = start; i >= end; i--) {
|
|
110
|
+
const index = (this.recordIndex - i + this.maxLength) % this.maxLength;
|
|
111
|
+
histo.push(this.history[index]);
|
|
112
|
+
}
|
|
113
|
+
this.history = histo;
|
|
114
|
+
this.recordIndex = this.history.length;
|
|
115
|
+
this.recordLength = this.history.length;
|
|
116
|
+
}
|
|
117
|
+
makeStorableState(value) {
|
|
118
|
+
return deepCopy(value, this.excluded);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
StateRecorder
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts","../../src/utils.ts","../../src/recording/recorder.ts"],"sourcesContent":["/** 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 * 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":";;;;AACO,IAAMA,+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,GAA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KA;AAC7DiB,YAAMI,KAAK,KAAKxB,QAAQe,KAAAA,CAAM;IAC/B;AAEA,SAAKf,UAAUoB;AACf,SAAKnB,cAAc,KAAKD,QAAQyB;AAChC,SAAKvB,eAAe,KAAKF,QAAQyB;EAClC;EAEQf,kBAAkBgB,OAAiB;AAC1C,WAAOC,SAASD,OAAO,KAAKtB,QAAQ;EACrC;AACD;","names":["DEFAULT_RECORD_BUFFER_FRAMES","DEFAULT_LOOP_BUFFER_FRAMES","deepCopy","value","excluded","includes","Array","isArray","result","i","length","key","Object","hasOwn","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"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { StateSnapshot } from '../types/state.mjs';
|
|
2
|
+
|
|
3
|
+
declare class StateRecorder {
|
|
4
|
+
private history;
|
|
5
|
+
private recordIndex;
|
|
6
|
+
private recordLength;
|
|
7
|
+
private maxLength;
|
|
8
|
+
private excluded;
|
|
9
|
+
constructor(maxLength?: number);
|
|
10
|
+
/**
|
|
11
|
+
* Set objects to exclude from serialization
|
|
12
|
+
*/
|
|
13
|
+
setExcluded(excluded: any[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Record a state snapshot
|
|
16
|
+
*/
|
|
17
|
+
record(state: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get state at specific position (0 = most recent)
|
|
20
|
+
*/
|
|
21
|
+
getState(position: number): StateSnapshot | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get current record length
|
|
24
|
+
*/
|
|
25
|
+
getLength(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Get maximum record length
|
|
28
|
+
*/
|
|
29
|
+
getMaxLength(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Clear all recorded history
|
|
32
|
+
*/
|
|
33
|
+
clear(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Trim history to specific position
|
|
36
|
+
*/
|
|
37
|
+
trimTo(position: number): void;
|
|
38
|
+
private makeStorableState;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { StateRecorder };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { StateSnapshot } from '../types/state.js';
|
|
2
|
+
|
|
3
|
+
declare class StateRecorder {
|
|
4
|
+
private history;
|
|
5
|
+
private recordIndex;
|
|
6
|
+
private recordLength;
|
|
7
|
+
private maxLength;
|
|
8
|
+
private excluded;
|
|
9
|
+
constructor(maxLength?: number);
|
|
10
|
+
/**
|
|
11
|
+
* Set objects to exclude from serialization
|
|
12
|
+
*/
|
|
13
|
+
setExcluded(excluded: any[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Record a state snapshot
|
|
16
|
+
*/
|
|
17
|
+
record(state: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get state at specific position (0 = most recent)
|
|
20
|
+
*/
|
|
21
|
+
getState(position: number): StateSnapshot | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get current record length
|
|
24
|
+
*/
|
|
25
|
+
getLength(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Get maximum record length
|
|
28
|
+
*/
|
|
29
|
+
getMaxLength(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Clear all recorded history
|
|
32
|
+
*/
|
|
33
|
+
clear(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Trim history to specific position
|
|
36
|
+
*/
|
|
37
|
+
trimTo(position: number): void;
|
|
38
|
+
private makeStorableState;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { StateRecorder };
|