@bloopjs/bloop 0.0.20 → 0.0.22
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/bloop.d.ts +52 -0
- package/dist/bloop.d.ts.map +1 -0
- package/dist/context.d.ts +17 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/data/bag.d.ts +8 -0
- package/dist/data/bag.d.ts.map +1 -0
- package/dist/data/schema.d.ts +5 -0
- package/dist/data/schema.d.ts.map +1 -0
- package/dist/events.d.ts +17 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/mod.d.ts +8 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +1290 -0
- package/dist/mod.js.map +14 -0
- package/dist/mount.d.ts +17 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/runtime.d.ts +60 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/system.d.ts +26 -0
- package/dist/system.d.ts.map +1 -0
- package/dist/util.d.ts +4 -0
- package/dist/util.d.ts.map +1 -0
- package/package.json +10 -2
- package/src/bloop.ts +145 -129
- package/src/mod.ts +8 -3
- package/src/mount.ts +86 -0
- package/src/runtime.ts +15 -94
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/jsr.json +0 -6
- package/publish/tsconfig.publish.json +0 -7
- package/test/inputs.test.ts +0 -227
- package/test/runtime.test.ts +0 -298
- package/test/tape.test.ts +0 -128
- package/tsconfig.json +0 -34
package/dist/mod.js
ADDED
|
@@ -0,0 +1,1290 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/util.ts
|
|
13
|
+
var exports_util = {};
|
|
14
|
+
__export(exports_util, {
|
|
15
|
+
unwrap: () => unwrap,
|
|
16
|
+
toHexString: () => toHexString,
|
|
17
|
+
assert: () => assert
|
|
18
|
+
});
|
|
19
|
+
function toHexString(dataView, length) {
|
|
20
|
+
length ??= dataView.byteLength;
|
|
21
|
+
let hexString = "";
|
|
22
|
+
for (let i = 0;i < length; i++) {
|
|
23
|
+
const byte = dataView.getUint8(i);
|
|
24
|
+
hexString += `${byte.toString(16).padStart(2, "0")} `;
|
|
25
|
+
}
|
|
26
|
+
return hexString.trim();
|
|
27
|
+
}
|
|
28
|
+
function assert(condition, message) {
|
|
29
|
+
if (condition == null || condition === false) {
|
|
30
|
+
throw new Error(message ?? "Assertion failed");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function unwrap(value, message) {
|
|
34
|
+
assert(value != null, message ?? `Unwrap failed: value is ${value}`);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
// ../engine/dist/engine.js
|
|
38
|
+
var __defProp2 = Object.defineProperty;
|
|
39
|
+
var __export2 = (target, all) => {
|
|
40
|
+
for (var name in all)
|
|
41
|
+
__defProp2(target, name, {
|
|
42
|
+
get: all[name],
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
set: (newValue) => all[name] = () => newValue
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var exports_enums = {};
|
|
49
|
+
__export2(exports_enums, {
|
|
50
|
+
MouseButton: () => MouseButton,
|
|
51
|
+
Key: () => Key,
|
|
52
|
+
EventType: () => EventType
|
|
53
|
+
});
|
|
54
|
+
var EventType;
|
|
55
|
+
((EventType2) => {
|
|
56
|
+
EventType2[EventType2["None"] = 0] = "None";
|
|
57
|
+
EventType2[EventType2["KeyDown"] = 1] = "KeyDown";
|
|
58
|
+
EventType2[EventType2["KeyUp"] = 2] = "KeyUp";
|
|
59
|
+
EventType2[EventType2["MouseMove"] = 3] = "MouseMove";
|
|
60
|
+
EventType2[EventType2["MouseDown"] = 4] = "MouseDown";
|
|
61
|
+
EventType2[EventType2["MouseUp"] = 5] = "MouseUp";
|
|
62
|
+
EventType2[EventType2["MouseWheel"] = 6] = "MouseWheel";
|
|
63
|
+
EventType2[EventType2["FrameAdvance"] = 7] = "FrameAdvance";
|
|
64
|
+
})(EventType ||= {});
|
|
65
|
+
var MouseButton;
|
|
66
|
+
((MouseButton2) => {
|
|
67
|
+
MouseButton2[MouseButton2["None"] = 0] = "None";
|
|
68
|
+
MouseButton2[MouseButton2["Left"] = 1] = "Left";
|
|
69
|
+
MouseButton2[MouseButton2["Middle"] = 2] = "Middle";
|
|
70
|
+
MouseButton2[MouseButton2["Right"] = 3] = "Right";
|
|
71
|
+
MouseButton2[MouseButton2["X1"] = 4] = "X1";
|
|
72
|
+
MouseButton2[MouseButton2["X2"] = 5] = "X2";
|
|
73
|
+
MouseButton2[MouseButton2["X3"] = 6] = "X3";
|
|
74
|
+
MouseButton2[MouseButton2["X4"] = 7] = "X4";
|
|
75
|
+
MouseButton2[MouseButton2["X5"] = 8] = "X5";
|
|
76
|
+
})(MouseButton ||= {});
|
|
77
|
+
var Key;
|
|
78
|
+
((Key2) => {
|
|
79
|
+
Key2[Key2["None"] = 0] = "None";
|
|
80
|
+
Key2[Key2["Backquote"] = 1] = "Backquote";
|
|
81
|
+
Key2[Key2["Backslash"] = 2] = "Backslash";
|
|
82
|
+
Key2[Key2["BracketLeft"] = 3] = "BracketLeft";
|
|
83
|
+
Key2[Key2["BracketRight"] = 4] = "BracketRight";
|
|
84
|
+
Key2[Key2["Comma"] = 5] = "Comma";
|
|
85
|
+
Key2[Key2["Digit0"] = 6] = "Digit0";
|
|
86
|
+
Key2[Key2["Digit1"] = 7] = "Digit1";
|
|
87
|
+
Key2[Key2["Digit2"] = 8] = "Digit2";
|
|
88
|
+
Key2[Key2["Digit3"] = 9] = "Digit3";
|
|
89
|
+
Key2[Key2["Digit4"] = 10] = "Digit4";
|
|
90
|
+
Key2[Key2["Digit5"] = 11] = "Digit5";
|
|
91
|
+
Key2[Key2["Digit6"] = 12] = "Digit6";
|
|
92
|
+
Key2[Key2["Digit7"] = 13] = "Digit7";
|
|
93
|
+
Key2[Key2["Digit8"] = 14] = "Digit8";
|
|
94
|
+
Key2[Key2["Digit9"] = 15] = "Digit9";
|
|
95
|
+
Key2[Key2["Equal"] = 16] = "Equal";
|
|
96
|
+
Key2[Key2["IntlBackslash"] = 17] = "IntlBackslash";
|
|
97
|
+
Key2[Key2["IntlRo"] = 18] = "IntlRo";
|
|
98
|
+
Key2[Key2["IntlYen"] = 19] = "IntlYen";
|
|
99
|
+
Key2[Key2["KeyA"] = 20] = "KeyA";
|
|
100
|
+
Key2[Key2["KeyB"] = 21] = "KeyB";
|
|
101
|
+
Key2[Key2["KeyC"] = 22] = "KeyC";
|
|
102
|
+
Key2[Key2["KeyD"] = 23] = "KeyD";
|
|
103
|
+
Key2[Key2["KeyE"] = 24] = "KeyE";
|
|
104
|
+
Key2[Key2["KeyF"] = 25] = "KeyF";
|
|
105
|
+
Key2[Key2["KeyG"] = 26] = "KeyG";
|
|
106
|
+
Key2[Key2["KeyH"] = 27] = "KeyH";
|
|
107
|
+
Key2[Key2["KeyI"] = 28] = "KeyI";
|
|
108
|
+
Key2[Key2["KeyJ"] = 29] = "KeyJ";
|
|
109
|
+
Key2[Key2["KeyK"] = 30] = "KeyK";
|
|
110
|
+
Key2[Key2["KeyL"] = 31] = "KeyL";
|
|
111
|
+
Key2[Key2["KeyM"] = 32] = "KeyM";
|
|
112
|
+
Key2[Key2["KeyN"] = 33] = "KeyN";
|
|
113
|
+
Key2[Key2["KeyO"] = 34] = "KeyO";
|
|
114
|
+
Key2[Key2["KeyP"] = 35] = "KeyP";
|
|
115
|
+
Key2[Key2["KeyQ"] = 36] = "KeyQ";
|
|
116
|
+
Key2[Key2["KeyR"] = 37] = "KeyR";
|
|
117
|
+
Key2[Key2["KeyS"] = 38] = "KeyS";
|
|
118
|
+
Key2[Key2["KeyT"] = 39] = "KeyT";
|
|
119
|
+
Key2[Key2["KeyU"] = 40] = "KeyU";
|
|
120
|
+
Key2[Key2["KeyV"] = 41] = "KeyV";
|
|
121
|
+
Key2[Key2["KeyW"] = 42] = "KeyW";
|
|
122
|
+
Key2[Key2["KeyX"] = 43] = "KeyX";
|
|
123
|
+
Key2[Key2["KeyY"] = 44] = "KeyY";
|
|
124
|
+
Key2[Key2["KeyZ"] = 45] = "KeyZ";
|
|
125
|
+
Key2[Key2["Minus"] = 46] = "Minus";
|
|
126
|
+
Key2[Key2["Period"] = 47] = "Period";
|
|
127
|
+
Key2[Key2["Quote"] = 48] = "Quote";
|
|
128
|
+
Key2[Key2["Semicolon"] = 49] = "Semicolon";
|
|
129
|
+
Key2[Key2["Slash"] = 50] = "Slash";
|
|
130
|
+
Key2[Key2["AltLeft"] = 51] = "AltLeft";
|
|
131
|
+
Key2[Key2["AltRight"] = 52] = "AltRight";
|
|
132
|
+
Key2[Key2["Backspace"] = 53] = "Backspace";
|
|
133
|
+
Key2[Key2["CapsLock"] = 54] = "CapsLock";
|
|
134
|
+
Key2[Key2["ContextMenu"] = 55] = "ContextMenu";
|
|
135
|
+
Key2[Key2["ControlLeft"] = 56] = "ControlLeft";
|
|
136
|
+
Key2[Key2["ControlRight"] = 57] = "ControlRight";
|
|
137
|
+
Key2[Key2["Enter"] = 58] = "Enter";
|
|
138
|
+
Key2[Key2["MetaLeft"] = 59] = "MetaLeft";
|
|
139
|
+
Key2[Key2["MetaRight"] = 60] = "MetaRight";
|
|
140
|
+
Key2[Key2["ShiftLeft"] = 61] = "ShiftLeft";
|
|
141
|
+
Key2[Key2["ShiftRight"] = 62] = "ShiftRight";
|
|
142
|
+
Key2[Key2["Space"] = 63] = "Space";
|
|
143
|
+
Key2[Key2["Tab"] = 64] = "Tab";
|
|
144
|
+
Key2[Key2["Convert"] = 65] = "Convert";
|
|
145
|
+
Key2[Key2["KanaMode"] = 66] = "KanaMode";
|
|
146
|
+
Key2[Key2["Lang1"] = 67] = "Lang1";
|
|
147
|
+
Key2[Key2["Lang2"] = 68] = "Lang2";
|
|
148
|
+
Key2[Key2["Lang3"] = 69] = "Lang3";
|
|
149
|
+
Key2[Key2["Lang4"] = 70] = "Lang4";
|
|
150
|
+
Key2[Key2["Lang5"] = 71] = "Lang5";
|
|
151
|
+
Key2[Key2["NonConvert"] = 72] = "NonConvert";
|
|
152
|
+
Key2[Key2["Delete"] = 73] = "Delete";
|
|
153
|
+
Key2[Key2["End"] = 74] = "End";
|
|
154
|
+
Key2[Key2["Help"] = 75] = "Help";
|
|
155
|
+
Key2[Key2["Home"] = 76] = "Home";
|
|
156
|
+
Key2[Key2["Insert"] = 77] = "Insert";
|
|
157
|
+
Key2[Key2["PageDown"] = 78] = "PageDown";
|
|
158
|
+
Key2[Key2["PageUp"] = 79] = "PageUp";
|
|
159
|
+
Key2[Key2["ArrowDown"] = 80] = "ArrowDown";
|
|
160
|
+
Key2[Key2["ArrowLeft"] = 81] = "ArrowLeft";
|
|
161
|
+
Key2[Key2["ArrowRight"] = 82] = "ArrowRight";
|
|
162
|
+
Key2[Key2["ArrowUp"] = 83] = "ArrowUp";
|
|
163
|
+
Key2[Key2["NumLock"] = 84] = "NumLock";
|
|
164
|
+
Key2[Key2["Numpad0"] = 85] = "Numpad0";
|
|
165
|
+
Key2[Key2["Numpad1"] = 86] = "Numpad1";
|
|
166
|
+
Key2[Key2["Numpad2"] = 87] = "Numpad2";
|
|
167
|
+
Key2[Key2["Numpad3"] = 88] = "Numpad3";
|
|
168
|
+
Key2[Key2["Numpad4"] = 89] = "Numpad4";
|
|
169
|
+
Key2[Key2["Numpad5"] = 90] = "Numpad5";
|
|
170
|
+
Key2[Key2["Numpad6"] = 91] = "Numpad6";
|
|
171
|
+
Key2[Key2["Numpad7"] = 92] = "Numpad7";
|
|
172
|
+
Key2[Key2["Numpad8"] = 93] = "Numpad8";
|
|
173
|
+
Key2[Key2["Numpad9"] = 94] = "Numpad9";
|
|
174
|
+
Key2[Key2["NumpadAdd"] = 95] = "NumpadAdd";
|
|
175
|
+
Key2[Key2["NumpadBackspace"] = 96] = "NumpadBackspace";
|
|
176
|
+
Key2[Key2["NumpadClear"] = 97] = "NumpadClear";
|
|
177
|
+
Key2[Key2["NumpadClearEntry"] = 98] = "NumpadClearEntry";
|
|
178
|
+
Key2[Key2["NumpadComma"] = 99] = "NumpadComma";
|
|
179
|
+
Key2[Key2["NumpadDecimal"] = 100] = "NumpadDecimal";
|
|
180
|
+
Key2[Key2["NumpadDivide"] = 101] = "NumpadDivide";
|
|
181
|
+
Key2[Key2["NumpadEnter"] = 102] = "NumpadEnter";
|
|
182
|
+
Key2[Key2["NumpadEqual"] = 103] = "NumpadEqual";
|
|
183
|
+
Key2[Key2["NumpadHash"] = 104] = "NumpadHash";
|
|
184
|
+
Key2[Key2["NumpadMemoryAdd"] = 105] = "NumpadMemoryAdd";
|
|
185
|
+
Key2[Key2["NumpadMemoryClear"] = 106] = "NumpadMemoryClear";
|
|
186
|
+
Key2[Key2["NumpadMemoryRecall"] = 107] = "NumpadMemoryRecall";
|
|
187
|
+
Key2[Key2["NumpadMemoryStore"] = 108] = "NumpadMemoryStore";
|
|
188
|
+
Key2[Key2["NumpadMemorySubtract"] = 109] = "NumpadMemorySubtract";
|
|
189
|
+
Key2[Key2["NumpadMultiply"] = 110] = "NumpadMultiply";
|
|
190
|
+
Key2[Key2["NumpadParenLeft"] = 111] = "NumpadParenLeft";
|
|
191
|
+
Key2[Key2["NumpadParenRight"] = 112] = "NumpadParenRight";
|
|
192
|
+
Key2[Key2["NumpadStar"] = 113] = "NumpadStar";
|
|
193
|
+
Key2[Key2["NumpadSubtract"] = 114] = "NumpadSubtract";
|
|
194
|
+
Key2[Key2["Escape"] = 115] = "Escape";
|
|
195
|
+
Key2[Key2["Fn"] = 116] = "Fn";
|
|
196
|
+
Key2[Key2["FnLock"] = 117] = "FnLock";
|
|
197
|
+
Key2[Key2["PrintScreen"] = 118] = "PrintScreen";
|
|
198
|
+
Key2[Key2["ScrollLock"] = 119] = "ScrollLock";
|
|
199
|
+
Key2[Key2["Pause"] = 120] = "Pause";
|
|
200
|
+
Key2[Key2["BrowserBack"] = 121] = "BrowserBack";
|
|
201
|
+
Key2[Key2["BrowserFavorites"] = 122] = "BrowserFavorites";
|
|
202
|
+
Key2[Key2["BrowserForward"] = 123] = "BrowserForward";
|
|
203
|
+
Key2[Key2["BrowserHome"] = 124] = "BrowserHome";
|
|
204
|
+
Key2[Key2["BrowserRefresh"] = 125] = "BrowserRefresh";
|
|
205
|
+
Key2[Key2["BrowserSearch"] = 126] = "BrowserSearch";
|
|
206
|
+
Key2[Key2["BrowserStop"] = 127] = "BrowserStop";
|
|
207
|
+
Key2[Key2["Eject"] = 128] = "Eject";
|
|
208
|
+
Key2[Key2["LaunchApp1"] = 129] = "LaunchApp1";
|
|
209
|
+
Key2[Key2["LaunchApp2"] = 130] = "LaunchApp2";
|
|
210
|
+
Key2[Key2["LaunchMail"] = 131] = "LaunchMail";
|
|
211
|
+
Key2[Key2["MediaPlayPause"] = 132] = "MediaPlayPause";
|
|
212
|
+
Key2[Key2["MediaSelect"] = 133] = "MediaSelect";
|
|
213
|
+
Key2[Key2["MediaStop"] = 134] = "MediaStop";
|
|
214
|
+
Key2[Key2["MediaTrackNext"] = 135] = "MediaTrackNext";
|
|
215
|
+
Key2[Key2["MediaTrackPrevious"] = 136] = "MediaTrackPrevious";
|
|
216
|
+
Key2[Key2["Power"] = 137] = "Power";
|
|
217
|
+
Key2[Key2["Sleep"] = 138] = "Sleep";
|
|
218
|
+
Key2[Key2["AudioVolumeDown"] = 139] = "AudioVolumeDown";
|
|
219
|
+
Key2[Key2["AudioVolumeMute"] = 140] = "AudioVolumeMute";
|
|
220
|
+
Key2[Key2["AudioVolumeUp"] = 141] = "AudioVolumeUp";
|
|
221
|
+
Key2[Key2["WakeUp"] = 142] = "WakeUp";
|
|
222
|
+
Key2[Key2["Hyper"] = 143] = "Hyper";
|
|
223
|
+
Key2[Key2["Super"] = 144] = "Super";
|
|
224
|
+
Key2[Key2["Turbo"] = 145] = "Turbo";
|
|
225
|
+
Key2[Key2["Abort"] = 146] = "Abort";
|
|
226
|
+
Key2[Key2["Resume"] = 147] = "Resume";
|
|
227
|
+
Key2[Key2["Suspend"] = 148] = "Suspend";
|
|
228
|
+
Key2[Key2["Again"] = 149] = "Again";
|
|
229
|
+
Key2[Key2["Copy"] = 150] = "Copy";
|
|
230
|
+
Key2[Key2["Cut"] = 151] = "Cut";
|
|
231
|
+
Key2[Key2["Find"] = 152] = "Find";
|
|
232
|
+
Key2[Key2["Open"] = 153] = "Open";
|
|
233
|
+
Key2[Key2["Paste"] = 154] = "Paste";
|
|
234
|
+
Key2[Key2["Props"] = 155] = "Props";
|
|
235
|
+
Key2[Key2["Select"] = 156] = "Select";
|
|
236
|
+
Key2[Key2["Undo"] = 157] = "Undo";
|
|
237
|
+
Key2[Key2["Hiragana"] = 158] = "Hiragana";
|
|
238
|
+
Key2[Key2["Katakana"] = 159] = "Katakana";
|
|
239
|
+
Key2[Key2["F1"] = 160] = "F1";
|
|
240
|
+
Key2[Key2["F2"] = 161] = "F2";
|
|
241
|
+
Key2[Key2["F3"] = 162] = "F3";
|
|
242
|
+
Key2[Key2["F4"] = 163] = "F4";
|
|
243
|
+
Key2[Key2["F5"] = 164] = "F5";
|
|
244
|
+
Key2[Key2["F6"] = 165] = "F6";
|
|
245
|
+
Key2[Key2["F7"] = 166] = "F7";
|
|
246
|
+
Key2[Key2["F8"] = 167] = "F8";
|
|
247
|
+
Key2[Key2["F9"] = 168] = "F9";
|
|
248
|
+
Key2[Key2["F10"] = 169] = "F10";
|
|
249
|
+
Key2[Key2["F11"] = 170] = "F11";
|
|
250
|
+
Key2[Key2["F12"] = 171] = "F12";
|
|
251
|
+
Key2[Key2["F13"] = 172] = "F13";
|
|
252
|
+
Key2[Key2["F14"] = 173] = "F14";
|
|
253
|
+
Key2[Key2["F15"] = 174] = "F15";
|
|
254
|
+
Key2[Key2["F16"] = 175] = "F16";
|
|
255
|
+
Key2[Key2["F17"] = 176] = "F17";
|
|
256
|
+
Key2[Key2["F18"] = 177] = "F18";
|
|
257
|
+
Key2[Key2["F19"] = 178] = "F19";
|
|
258
|
+
Key2[Key2["F20"] = 179] = "F20";
|
|
259
|
+
Key2[Key2["F21"] = 180] = "F21";
|
|
260
|
+
Key2[Key2["F22"] = 181] = "F22";
|
|
261
|
+
Key2[Key2["F23"] = 182] = "F23";
|
|
262
|
+
Key2[Key2["F24"] = 183] = "F24";
|
|
263
|
+
Key2[Key2["F25"] = 184] = "F25";
|
|
264
|
+
Key2[Key2["F26"] = 185] = "F26";
|
|
265
|
+
Key2[Key2["F27"] = 186] = "F27";
|
|
266
|
+
Key2[Key2["F28"] = 187] = "F28";
|
|
267
|
+
Key2[Key2["F29"] = 188] = "F29";
|
|
268
|
+
Key2[Key2["F30"] = 189] = "F30";
|
|
269
|
+
Key2[Key2["F31"] = 190] = "F31";
|
|
270
|
+
Key2[Key2["F32"] = 191] = "F32";
|
|
271
|
+
Key2[Key2["F33"] = 192] = "F33";
|
|
272
|
+
Key2[Key2["F34"] = 193] = "F34";
|
|
273
|
+
Key2[Key2["F35"] = 194] = "F35";
|
|
274
|
+
})(Key ||= {});
|
|
275
|
+
var MOUSE_OFFSET = 256;
|
|
276
|
+
var MOUSE_BUTTONS_OFFSET = 16;
|
|
277
|
+
var KEYBOARD_OFFSET = 0;
|
|
278
|
+
var EVENT_PAYLOAD_SIZE = 8;
|
|
279
|
+
var EVENT_PAYLOAD_ALIGN = 4;
|
|
280
|
+
function keyToKeyCode(key) {
|
|
281
|
+
return Key[key];
|
|
282
|
+
}
|
|
283
|
+
function keyCodeToKey(code) {
|
|
284
|
+
return Key[code];
|
|
285
|
+
}
|
|
286
|
+
function mouseButtonToMouseButtonCode(button) {
|
|
287
|
+
return MouseButton[button];
|
|
288
|
+
}
|
|
289
|
+
function mouseButtonCodeToMouseButton(code) {
|
|
290
|
+
return MouseButton[code];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
class InputContext {
|
|
294
|
+
#dataView;
|
|
295
|
+
#keys;
|
|
296
|
+
#mouse;
|
|
297
|
+
constructor(dataView) {
|
|
298
|
+
if (dataView) {
|
|
299
|
+
this.#dataView = dataView;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
get dataView() {
|
|
303
|
+
if (!this.#dataView) {
|
|
304
|
+
throw new Error("DataView is not initialized on InputContext");
|
|
305
|
+
}
|
|
306
|
+
return this.#dataView;
|
|
307
|
+
}
|
|
308
|
+
set dataView(dataView) {
|
|
309
|
+
this.#dataView = dataView;
|
|
310
|
+
this.#keys = undefined;
|
|
311
|
+
this.#mouse = undefined;
|
|
312
|
+
}
|
|
313
|
+
get keys() {
|
|
314
|
+
if (!this.#keys) {
|
|
315
|
+
this.#keys = new KeyboardContext(new DataView(this.dataView.buffer, this.dataView.byteOffset + KEYBOARD_OFFSET));
|
|
316
|
+
}
|
|
317
|
+
return this.#keys;
|
|
318
|
+
}
|
|
319
|
+
get mouse() {
|
|
320
|
+
if (!this.#mouse) {
|
|
321
|
+
this.#mouse = new MouseContext(new DataView(this.dataView.buffer, this.dataView.byteOffset + MOUSE_OFFSET));
|
|
322
|
+
}
|
|
323
|
+
return this.#mouse;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
class MouseContext {
|
|
328
|
+
#dataView;
|
|
329
|
+
#buttonStates = new Map;
|
|
330
|
+
constructor(dataView) {
|
|
331
|
+
this.#dataView = dataView;
|
|
332
|
+
}
|
|
333
|
+
get x() {
|
|
334
|
+
return this.#dataView.getFloat32(0, true);
|
|
335
|
+
}
|
|
336
|
+
get y() {
|
|
337
|
+
return this.#dataView.getFloat32(4, true);
|
|
338
|
+
}
|
|
339
|
+
get wheel() {
|
|
340
|
+
return { x: this.wheelX, y: this.wheelY };
|
|
341
|
+
}
|
|
342
|
+
get wheelX() {
|
|
343
|
+
return this.#dataView.getFloat32(8, true);
|
|
344
|
+
}
|
|
345
|
+
get wheelY() {
|
|
346
|
+
return this.#dataView.getFloat32(12, true);
|
|
347
|
+
}
|
|
348
|
+
get left() {
|
|
349
|
+
return this.#buttonState(1);
|
|
350
|
+
}
|
|
351
|
+
get right() {
|
|
352
|
+
return this.#buttonState(3);
|
|
353
|
+
}
|
|
354
|
+
get middle() {
|
|
355
|
+
return this.#buttonState(2);
|
|
356
|
+
}
|
|
357
|
+
#buttonState(code) {
|
|
358
|
+
let state;
|
|
359
|
+
if (this.#buttonStates.has(code)) {
|
|
360
|
+
state = this.#buttonStates.get(code);
|
|
361
|
+
} else {
|
|
362
|
+
state = { down: false, held: false, up: false };
|
|
363
|
+
this.#buttonStates.set(code, state);
|
|
364
|
+
}
|
|
365
|
+
const offset = MOUSE_BUTTONS_OFFSET;
|
|
366
|
+
state.held = !!(this.#dataView.getUint8(offset + code) & 1);
|
|
367
|
+
state.down = state.held && !(this.#dataView.getUint8(offset + code) & 2);
|
|
368
|
+
state.up = !state.held && !!(this.#dataView.getUint8(offset + code) & 2);
|
|
369
|
+
return state;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
class KeyboardContext {
|
|
374
|
+
#dataView;
|
|
375
|
+
#keystates = new Map;
|
|
376
|
+
constructor(dataView) {
|
|
377
|
+
this.#dataView = dataView;
|
|
378
|
+
}
|
|
379
|
+
get shift() {
|
|
380
|
+
return this.shiftLeft || this.shiftRight;
|
|
381
|
+
}
|
|
382
|
+
get alt() {
|
|
383
|
+
return this.altLeft || this.altRight;
|
|
384
|
+
}
|
|
385
|
+
get control() {
|
|
386
|
+
return this.controlLeft || this.controlRight;
|
|
387
|
+
}
|
|
388
|
+
get meta() {
|
|
389
|
+
return this.metaLeft || this.metaRight;
|
|
390
|
+
}
|
|
391
|
+
get backquote() {
|
|
392
|
+
return this.#keystate(1);
|
|
393
|
+
}
|
|
394
|
+
get backslash() {
|
|
395
|
+
return this.#keystate(2);
|
|
396
|
+
}
|
|
397
|
+
get bracketLeft() {
|
|
398
|
+
return this.#keystate(3);
|
|
399
|
+
}
|
|
400
|
+
get bracketRight() {
|
|
401
|
+
return this.#keystate(4);
|
|
402
|
+
}
|
|
403
|
+
get comma() {
|
|
404
|
+
return this.#keystate(5);
|
|
405
|
+
}
|
|
406
|
+
get digit0() {
|
|
407
|
+
return this.#keystate(6);
|
|
408
|
+
}
|
|
409
|
+
get digit1() {
|
|
410
|
+
return this.#keystate(7);
|
|
411
|
+
}
|
|
412
|
+
get digit2() {
|
|
413
|
+
return this.#keystate(8);
|
|
414
|
+
}
|
|
415
|
+
get digit3() {
|
|
416
|
+
return this.#keystate(9);
|
|
417
|
+
}
|
|
418
|
+
get digit4() {
|
|
419
|
+
return this.#keystate(10);
|
|
420
|
+
}
|
|
421
|
+
get digit5() {
|
|
422
|
+
return this.#keystate(11);
|
|
423
|
+
}
|
|
424
|
+
get digit6() {
|
|
425
|
+
return this.#keystate(12);
|
|
426
|
+
}
|
|
427
|
+
get digit7() {
|
|
428
|
+
return this.#keystate(13);
|
|
429
|
+
}
|
|
430
|
+
get digit8() {
|
|
431
|
+
return this.#keystate(14);
|
|
432
|
+
}
|
|
433
|
+
get digit9() {
|
|
434
|
+
return this.#keystate(15);
|
|
435
|
+
}
|
|
436
|
+
get equal() {
|
|
437
|
+
return this.#keystate(16);
|
|
438
|
+
}
|
|
439
|
+
get intlBackslash() {
|
|
440
|
+
return this.#keystate(17);
|
|
441
|
+
}
|
|
442
|
+
get intlRo() {
|
|
443
|
+
return this.#keystate(18);
|
|
444
|
+
}
|
|
445
|
+
get intlYen() {
|
|
446
|
+
return this.#keystate(19);
|
|
447
|
+
}
|
|
448
|
+
get a() {
|
|
449
|
+
return this.#keystate(20);
|
|
450
|
+
}
|
|
451
|
+
get b() {
|
|
452
|
+
return this.#keystate(21);
|
|
453
|
+
}
|
|
454
|
+
get c() {
|
|
455
|
+
return this.#keystate(22);
|
|
456
|
+
}
|
|
457
|
+
get d() {
|
|
458
|
+
return this.#keystate(23);
|
|
459
|
+
}
|
|
460
|
+
get e() {
|
|
461
|
+
return this.#keystate(24);
|
|
462
|
+
}
|
|
463
|
+
get f() {
|
|
464
|
+
return this.#keystate(25);
|
|
465
|
+
}
|
|
466
|
+
get g() {
|
|
467
|
+
return this.#keystate(26);
|
|
468
|
+
}
|
|
469
|
+
get h() {
|
|
470
|
+
return this.#keystate(27);
|
|
471
|
+
}
|
|
472
|
+
get i() {
|
|
473
|
+
return this.#keystate(28);
|
|
474
|
+
}
|
|
475
|
+
get j() {
|
|
476
|
+
return this.#keystate(29);
|
|
477
|
+
}
|
|
478
|
+
get k() {
|
|
479
|
+
return this.#keystate(30);
|
|
480
|
+
}
|
|
481
|
+
get l() {
|
|
482
|
+
return this.#keystate(31);
|
|
483
|
+
}
|
|
484
|
+
get m() {
|
|
485
|
+
return this.#keystate(32);
|
|
486
|
+
}
|
|
487
|
+
get n() {
|
|
488
|
+
return this.#keystate(33);
|
|
489
|
+
}
|
|
490
|
+
get o() {
|
|
491
|
+
return this.#keystate(34);
|
|
492
|
+
}
|
|
493
|
+
get p() {
|
|
494
|
+
return this.#keystate(35);
|
|
495
|
+
}
|
|
496
|
+
get q() {
|
|
497
|
+
return this.#keystate(36);
|
|
498
|
+
}
|
|
499
|
+
get r() {
|
|
500
|
+
return this.#keystate(37);
|
|
501
|
+
}
|
|
502
|
+
get s() {
|
|
503
|
+
return this.#keystate(38);
|
|
504
|
+
}
|
|
505
|
+
get t() {
|
|
506
|
+
return this.#keystate(39);
|
|
507
|
+
}
|
|
508
|
+
get u() {
|
|
509
|
+
return this.#keystate(40);
|
|
510
|
+
}
|
|
511
|
+
get v() {
|
|
512
|
+
return this.#keystate(41);
|
|
513
|
+
}
|
|
514
|
+
get w() {
|
|
515
|
+
return this.#keystate(42);
|
|
516
|
+
}
|
|
517
|
+
get x() {
|
|
518
|
+
return this.#keystate(43);
|
|
519
|
+
}
|
|
520
|
+
get y() {
|
|
521
|
+
return this.#keystate(44);
|
|
522
|
+
}
|
|
523
|
+
get z() {
|
|
524
|
+
return this.#keystate(45);
|
|
525
|
+
}
|
|
526
|
+
get minus() {
|
|
527
|
+
return this.#keystate(46);
|
|
528
|
+
}
|
|
529
|
+
get period() {
|
|
530
|
+
return this.#keystate(47);
|
|
531
|
+
}
|
|
532
|
+
get quote() {
|
|
533
|
+
return this.#keystate(48);
|
|
534
|
+
}
|
|
535
|
+
get semicolon() {
|
|
536
|
+
return this.#keystate(49);
|
|
537
|
+
}
|
|
538
|
+
get slash() {
|
|
539
|
+
return this.#keystate(50);
|
|
540
|
+
}
|
|
541
|
+
get altLeft() {
|
|
542
|
+
return this.#keystate(51);
|
|
543
|
+
}
|
|
544
|
+
get altRight() {
|
|
545
|
+
return this.#keystate(52);
|
|
546
|
+
}
|
|
547
|
+
get backspace() {
|
|
548
|
+
return this.#keystate(53);
|
|
549
|
+
}
|
|
550
|
+
get capsLock() {
|
|
551
|
+
return this.#keystate(54);
|
|
552
|
+
}
|
|
553
|
+
get contextMenu() {
|
|
554
|
+
return this.#keystate(55);
|
|
555
|
+
}
|
|
556
|
+
get controlLeft() {
|
|
557
|
+
return this.#keystate(56);
|
|
558
|
+
}
|
|
559
|
+
get controlRight() {
|
|
560
|
+
return this.#keystate(57);
|
|
561
|
+
}
|
|
562
|
+
get enter() {
|
|
563
|
+
return this.#keystate(58);
|
|
564
|
+
}
|
|
565
|
+
get metaLeft() {
|
|
566
|
+
return this.#keystate(59);
|
|
567
|
+
}
|
|
568
|
+
get metaRight() {
|
|
569
|
+
return this.#keystate(60);
|
|
570
|
+
}
|
|
571
|
+
get shiftLeft() {
|
|
572
|
+
return this.#keystate(61);
|
|
573
|
+
}
|
|
574
|
+
get shiftRight() {
|
|
575
|
+
return this.#keystate(62);
|
|
576
|
+
}
|
|
577
|
+
get space() {
|
|
578
|
+
return this.#keystate(63);
|
|
579
|
+
}
|
|
580
|
+
get tab() {
|
|
581
|
+
return this.#keystate(64);
|
|
582
|
+
}
|
|
583
|
+
get convert() {
|
|
584
|
+
return this.#keystate(65);
|
|
585
|
+
}
|
|
586
|
+
get kanaMode() {
|
|
587
|
+
return this.#keystate(66);
|
|
588
|
+
}
|
|
589
|
+
get lang1() {
|
|
590
|
+
return this.#keystate(67);
|
|
591
|
+
}
|
|
592
|
+
get lang2() {
|
|
593
|
+
return this.#keystate(68);
|
|
594
|
+
}
|
|
595
|
+
get lang3() {
|
|
596
|
+
return this.#keystate(69);
|
|
597
|
+
}
|
|
598
|
+
get lang4() {
|
|
599
|
+
return this.#keystate(70);
|
|
600
|
+
}
|
|
601
|
+
get lang5() {
|
|
602
|
+
return this.#keystate(71);
|
|
603
|
+
}
|
|
604
|
+
get nonConvert() {
|
|
605
|
+
return this.#keystate(72);
|
|
606
|
+
}
|
|
607
|
+
get delete() {
|
|
608
|
+
return this.#keystate(73);
|
|
609
|
+
}
|
|
610
|
+
get end() {
|
|
611
|
+
return this.#keystate(74);
|
|
612
|
+
}
|
|
613
|
+
get help() {
|
|
614
|
+
return this.#keystate(75);
|
|
615
|
+
}
|
|
616
|
+
get home() {
|
|
617
|
+
return this.#keystate(76);
|
|
618
|
+
}
|
|
619
|
+
get insert() {
|
|
620
|
+
return this.#keystate(77);
|
|
621
|
+
}
|
|
622
|
+
get pageDown() {
|
|
623
|
+
return this.#keystate(78);
|
|
624
|
+
}
|
|
625
|
+
get pageUp() {
|
|
626
|
+
return this.#keystate(79);
|
|
627
|
+
}
|
|
628
|
+
get arrowDown() {
|
|
629
|
+
return this.#keystate(80);
|
|
630
|
+
}
|
|
631
|
+
get arrowLeft() {
|
|
632
|
+
return this.#keystate(81);
|
|
633
|
+
}
|
|
634
|
+
get arrowRight() {
|
|
635
|
+
return this.#keystate(82);
|
|
636
|
+
}
|
|
637
|
+
get arrowUp() {
|
|
638
|
+
return this.#keystate(83);
|
|
639
|
+
}
|
|
640
|
+
get numLock() {
|
|
641
|
+
return this.#keystate(84);
|
|
642
|
+
}
|
|
643
|
+
get numpad0() {
|
|
644
|
+
return this.#keystate(85);
|
|
645
|
+
}
|
|
646
|
+
get numpad1() {
|
|
647
|
+
return this.#keystate(86);
|
|
648
|
+
}
|
|
649
|
+
get numpad2() {
|
|
650
|
+
return this.#keystate(87);
|
|
651
|
+
}
|
|
652
|
+
get numpad3() {
|
|
653
|
+
return this.#keystate(88);
|
|
654
|
+
}
|
|
655
|
+
get numpad4() {
|
|
656
|
+
return this.#keystate(89);
|
|
657
|
+
}
|
|
658
|
+
get numpad5() {
|
|
659
|
+
return this.#keystate(90);
|
|
660
|
+
}
|
|
661
|
+
get numpad6() {
|
|
662
|
+
return this.#keystate(91);
|
|
663
|
+
}
|
|
664
|
+
get numpad7() {
|
|
665
|
+
return this.#keystate(92);
|
|
666
|
+
}
|
|
667
|
+
get numpad8() {
|
|
668
|
+
return this.#keystate(93);
|
|
669
|
+
}
|
|
670
|
+
get numpad9() {
|
|
671
|
+
return this.#keystate(94);
|
|
672
|
+
}
|
|
673
|
+
get numpadAdd() {
|
|
674
|
+
return this.#keystate(95);
|
|
675
|
+
}
|
|
676
|
+
get numpadBackspace() {
|
|
677
|
+
return this.#keystate(96);
|
|
678
|
+
}
|
|
679
|
+
get numpadClear() {
|
|
680
|
+
return this.#keystate(97);
|
|
681
|
+
}
|
|
682
|
+
get numpadClearEntry() {
|
|
683
|
+
return this.#keystate(98);
|
|
684
|
+
}
|
|
685
|
+
get numpadComma() {
|
|
686
|
+
return this.#keystate(99);
|
|
687
|
+
}
|
|
688
|
+
get numpadDecimal() {
|
|
689
|
+
return this.#keystate(100);
|
|
690
|
+
}
|
|
691
|
+
get numpadDivide() {
|
|
692
|
+
return this.#keystate(101);
|
|
693
|
+
}
|
|
694
|
+
get numpadEnter() {
|
|
695
|
+
return this.#keystate(102);
|
|
696
|
+
}
|
|
697
|
+
get numpadEqual() {
|
|
698
|
+
return this.#keystate(103);
|
|
699
|
+
}
|
|
700
|
+
get numpadHash() {
|
|
701
|
+
return this.#keystate(104);
|
|
702
|
+
}
|
|
703
|
+
get numpadMemoryAdd() {
|
|
704
|
+
return this.#keystate(105);
|
|
705
|
+
}
|
|
706
|
+
get numpadMemoryClear() {
|
|
707
|
+
return this.#keystate(106);
|
|
708
|
+
}
|
|
709
|
+
get numpadMemoryRecall() {
|
|
710
|
+
return this.#keystate(107);
|
|
711
|
+
}
|
|
712
|
+
get numpadMemoryStore() {
|
|
713
|
+
return this.#keystate(108);
|
|
714
|
+
}
|
|
715
|
+
get numpadMemorySubtract() {
|
|
716
|
+
return this.#keystate(109);
|
|
717
|
+
}
|
|
718
|
+
get numpadMultiply() {
|
|
719
|
+
return this.#keystate(110);
|
|
720
|
+
}
|
|
721
|
+
get numpadParenLeft() {
|
|
722
|
+
return this.#keystate(111);
|
|
723
|
+
}
|
|
724
|
+
get numpadParenRight() {
|
|
725
|
+
return this.#keystate(112);
|
|
726
|
+
}
|
|
727
|
+
get numpadStar() {
|
|
728
|
+
return this.#keystate(113);
|
|
729
|
+
}
|
|
730
|
+
get numpadSubtract() {
|
|
731
|
+
return this.#keystate(114);
|
|
732
|
+
}
|
|
733
|
+
get escape() {
|
|
734
|
+
return this.#keystate(115);
|
|
735
|
+
}
|
|
736
|
+
get fn() {
|
|
737
|
+
return this.#keystate(116);
|
|
738
|
+
}
|
|
739
|
+
get fnLock() {
|
|
740
|
+
return this.#keystate(117);
|
|
741
|
+
}
|
|
742
|
+
get printScreen() {
|
|
743
|
+
return this.#keystate(118);
|
|
744
|
+
}
|
|
745
|
+
get scrollLock() {
|
|
746
|
+
return this.#keystate(119);
|
|
747
|
+
}
|
|
748
|
+
get pause() {
|
|
749
|
+
return this.#keystate(120);
|
|
750
|
+
}
|
|
751
|
+
get browserBack() {
|
|
752
|
+
return this.#keystate(121);
|
|
753
|
+
}
|
|
754
|
+
get browserFavorites() {
|
|
755
|
+
return this.#keystate(122);
|
|
756
|
+
}
|
|
757
|
+
get browserForward() {
|
|
758
|
+
return this.#keystate(123);
|
|
759
|
+
}
|
|
760
|
+
get browserHome() {
|
|
761
|
+
return this.#keystate(124);
|
|
762
|
+
}
|
|
763
|
+
get browserRefresh() {
|
|
764
|
+
return this.#keystate(125);
|
|
765
|
+
}
|
|
766
|
+
get browserSearch() {
|
|
767
|
+
return this.#keystate(126);
|
|
768
|
+
}
|
|
769
|
+
get browserStop() {
|
|
770
|
+
return this.#keystate(127);
|
|
771
|
+
}
|
|
772
|
+
get eject() {
|
|
773
|
+
return this.#keystate(128);
|
|
774
|
+
}
|
|
775
|
+
get launchApp1() {
|
|
776
|
+
return this.#keystate(129);
|
|
777
|
+
}
|
|
778
|
+
get launchApp2() {
|
|
779
|
+
return this.#keystate(130);
|
|
780
|
+
}
|
|
781
|
+
get launchMail() {
|
|
782
|
+
return this.#keystate(131);
|
|
783
|
+
}
|
|
784
|
+
get mediaPlayPause() {
|
|
785
|
+
return this.#keystate(132);
|
|
786
|
+
}
|
|
787
|
+
get mediaSelect() {
|
|
788
|
+
return this.#keystate(133);
|
|
789
|
+
}
|
|
790
|
+
get mediaStop() {
|
|
791
|
+
return this.#keystate(134);
|
|
792
|
+
}
|
|
793
|
+
get mediaTrackNext() {
|
|
794
|
+
return this.#keystate(135);
|
|
795
|
+
}
|
|
796
|
+
get mediaTrackPrevious() {
|
|
797
|
+
return this.#keystate(136);
|
|
798
|
+
}
|
|
799
|
+
get power() {
|
|
800
|
+
return this.#keystate(137);
|
|
801
|
+
}
|
|
802
|
+
get sleep() {
|
|
803
|
+
return this.#keystate(138);
|
|
804
|
+
}
|
|
805
|
+
get audioVolumeDown() {
|
|
806
|
+
return this.#keystate(139);
|
|
807
|
+
}
|
|
808
|
+
get audioVolumeMute() {
|
|
809
|
+
return this.#keystate(140);
|
|
810
|
+
}
|
|
811
|
+
get audioVolumeUp() {
|
|
812
|
+
return this.#keystate(141);
|
|
813
|
+
}
|
|
814
|
+
get wakeUp() {
|
|
815
|
+
return this.#keystate(142);
|
|
816
|
+
}
|
|
817
|
+
get hyper() {
|
|
818
|
+
return this.#keystate(143);
|
|
819
|
+
}
|
|
820
|
+
get super() {
|
|
821
|
+
return this.#keystate(144);
|
|
822
|
+
}
|
|
823
|
+
get turbo() {
|
|
824
|
+
return this.#keystate(145);
|
|
825
|
+
}
|
|
826
|
+
get abort() {
|
|
827
|
+
return this.#keystate(146);
|
|
828
|
+
}
|
|
829
|
+
get resume() {
|
|
830
|
+
return this.#keystate(147);
|
|
831
|
+
}
|
|
832
|
+
get suspend() {
|
|
833
|
+
return this.#keystate(148);
|
|
834
|
+
}
|
|
835
|
+
get again() {
|
|
836
|
+
return this.#keystate(149);
|
|
837
|
+
}
|
|
838
|
+
get copy() {
|
|
839
|
+
return this.#keystate(150);
|
|
840
|
+
}
|
|
841
|
+
get cut() {
|
|
842
|
+
return this.#keystate(151);
|
|
843
|
+
}
|
|
844
|
+
get find() {
|
|
845
|
+
return this.#keystate(152);
|
|
846
|
+
}
|
|
847
|
+
get open() {
|
|
848
|
+
return this.#keystate(153);
|
|
849
|
+
}
|
|
850
|
+
get paste() {
|
|
851
|
+
return this.#keystate(154);
|
|
852
|
+
}
|
|
853
|
+
get props() {
|
|
854
|
+
return this.#keystate(155);
|
|
855
|
+
}
|
|
856
|
+
get select() {
|
|
857
|
+
return this.#keystate(156);
|
|
858
|
+
}
|
|
859
|
+
get undo() {
|
|
860
|
+
return this.#keystate(157);
|
|
861
|
+
}
|
|
862
|
+
get hiragana() {
|
|
863
|
+
return this.#keystate(158);
|
|
864
|
+
}
|
|
865
|
+
get katakana() {
|
|
866
|
+
return this.#keystate(159);
|
|
867
|
+
}
|
|
868
|
+
get f1() {
|
|
869
|
+
return this.#keystate(160);
|
|
870
|
+
}
|
|
871
|
+
get f2() {
|
|
872
|
+
return this.#keystate(161);
|
|
873
|
+
}
|
|
874
|
+
get f3() {
|
|
875
|
+
return this.#keystate(162);
|
|
876
|
+
}
|
|
877
|
+
get f4() {
|
|
878
|
+
return this.#keystate(163);
|
|
879
|
+
}
|
|
880
|
+
get f5() {
|
|
881
|
+
return this.#keystate(164);
|
|
882
|
+
}
|
|
883
|
+
get f6() {
|
|
884
|
+
return this.#keystate(165);
|
|
885
|
+
}
|
|
886
|
+
get f7() {
|
|
887
|
+
return this.#keystate(166);
|
|
888
|
+
}
|
|
889
|
+
get f8() {
|
|
890
|
+
return this.#keystate(167);
|
|
891
|
+
}
|
|
892
|
+
get f9() {
|
|
893
|
+
return this.#keystate(168);
|
|
894
|
+
}
|
|
895
|
+
get f10() {
|
|
896
|
+
return this.#keystate(169);
|
|
897
|
+
}
|
|
898
|
+
get f11() {
|
|
899
|
+
return this.#keystate(170);
|
|
900
|
+
}
|
|
901
|
+
get f12() {
|
|
902
|
+
return this.#keystate(171);
|
|
903
|
+
}
|
|
904
|
+
get f13() {
|
|
905
|
+
return this.#keystate(172);
|
|
906
|
+
}
|
|
907
|
+
get f14() {
|
|
908
|
+
return this.#keystate(173);
|
|
909
|
+
}
|
|
910
|
+
get f15() {
|
|
911
|
+
return this.#keystate(174);
|
|
912
|
+
}
|
|
913
|
+
get f16() {
|
|
914
|
+
return this.#keystate(175);
|
|
915
|
+
}
|
|
916
|
+
get f17() {
|
|
917
|
+
return this.#keystate(176);
|
|
918
|
+
}
|
|
919
|
+
get f18() {
|
|
920
|
+
return this.#keystate(177);
|
|
921
|
+
}
|
|
922
|
+
get f19() {
|
|
923
|
+
return this.#keystate(178);
|
|
924
|
+
}
|
|
925
|
+
get f20() {
|
|
926
|
+
return this.#keystate(179);
|
|
927
|
+
}
|
|
928
|
+
get f21() {
|
|
929
|
+
return this.#keystate(180);
|
|
930
|
+
}
|
|
931
|
+
get f22() {
|
|
932
|
+
return this.#keystate(181);
|
|
933
|
+
}
|
|
934
|
+
get f23() {
|
|
935
|
+
return this.#keystate(182);
|
|
936
|
+
}
|
|
937
|
+
get f24() {
|
|
938
|
+
return this.#keystate(183);
|
|
939
|
+
}
|
|
940
|
+
get f25() {
|
|
941
|
+
return this.#keystate(184);
|
|
942
|
+
}
|
|
943
|
+
get f26() {
|
|
944
|
+
return this.#keystate(185);
|
|
945
|
+
}
|
|
946
|
+
get f27() {
|
|
947
|
+
return this.#keystate(186);
|
|
948
|
+
}
|
|
949
|
+
get f28() {
|
|
950
|
+
return this.#keystate(187);
|
|
951
|
+
}
|
|
952
|
+
get f29() {
|
|
953
|
+
return this.#keystate(188);
|
|
954
|
+
}
|
|
955
|
+
get f30() {
|
|
956
|
+
return this.#keystate(189);
|
|
957
|
+
}
|
|
958
|
+
get f31() {
|
|
959
|
+
return this.#keystate(190);
|
|
960
|
+
}
|
|
961
|
+
get f32() {
|
|
962
|
+
return this.#keystate(191);
|
|
963
|
+
}
|
|
964
|
+
get f33() {
|
|
965
|
+
return this.#keystate(192);
|
|
966
|
+
}
|
|
967
|
+
get f34() {
|
|
968
|
+
return this.#keystate(193);
|
|
969
|
+
}
|
|
970
|
+
get f35() {
|
|
971
|
+
return this.#keystate(194);
|
|
972
|
+
}
|
|
973
|
+
#keystate(code) {
|
|
974
|
+
let state;
|
|
975
|
+
if (this.#keystates.has(code)) {
|
|
976
|
+
state = this.#keystates.get(code);
|
|
977
|
+
} else {
|
|
978
|
+
state = { down: false, held: false, up: false };
|
|
979
|
+
this.#keystates.set(code, state);
|
|
980
|
+
}
|
|
981
|
+
state.held = !!(this.#dataView.getUint8(code) & 1);
|
|
982
|
+
state.down = state.held && !(this.#dataView.getUint8(code) & 2);
|
|
983
|
+
state.up = !state.held && !!(this.#dataView.getUint8(code) & 2);
|
|
984
|
+
return state;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
class TimeContext {
|
|
989
|
+
dataView;
|
|
990
|
+
constructor(dataView) {
|
|
991
|
+
this.dataView = dataView;
|
|
992
|
+
}
|
|
993
|
+
get frame() {
|
|
994
|
+
if (!this.dataView) {
|
|
995
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
996
|
+
}
|
|
997
|
+
return this.dataView.getUint32(0, true);
|
|
998
|
+
}
|
|
999
|
+
get dt() {
|
|
1000
|
+
if (!this.dataView) {
|
|
1001
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
1002
|
+
}
|
|
1003
|
+
return this.dataView.getUint32(4, true) / 1000;
|
|
1004
|
+
}
|
|
1005
|
+
get time() {
|
|
1006
|
+
if (!this.dataView) {
|
|
1007
|
+
throw new Error("TimeContext DataView is not initialized");
|
|
1008
|
+
}
|
|
1009
|
+
return this.dataView.getUint32(8, true) / 1000;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
var DEFAULT_WASM_URL = new URL("../wasm/bloop.wasm", import.meta.url);
|
|
1013
|
+
var TIME_CTX_OFFSET = 0;
|
|
1014
|
+
var INPUT_CTX_OFFSET = TIME_CTX_OFFSET + 4;
|
|
1015
|
+
var EVENTS_OFFSET = INPUT_CTX_OFFSET + 4;
|
|
1016
|
+
var SNAPSHOT_HEADER_USER_LEN_OFFSET = 4;
|
|
1017
|
+
var SNAPSHOT_HEADER_ENGINE_LEN_OFFSET = 8;
|
|
1018
|
+
|
|
1019
|
+
// src/runtime.ts
|
|
1020
|
+
class Runtime {
|
|
1021
|
+
wasm;
|
|
1022
|
+
#memory;
|
|
1023
|
+
#time;
|
|
1024
|
+
#serialize;
|
|
1025
|
+
constructor(wasm, memory, opts) {
|
|
1026
|
+
this.wasm = wasm;
|
|
1027
|
+
this.#memory = memory;
|
|
1028
|
+
this.#time = new TimeContext(new DataView(this.#memory.buffer, this.wasm.get_time_ctx()));
|
|
1029
|
+
this.#serialize = opts?.serialize;
|
|
1030
|
+
}
|
|
1031
|
+
step(ms) {
|
|
1032
|
+
this.wasm.step(ms ?? 16);
|
|
1033
|
+
}
|
|
1034
|
+
stepBack() {
|
|
1035
|
+
if (this.time.frame === 0) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
this.seek(this.time.frame - 1);
|
|
1039
|
+
}
|
|
1040
|
+
seek(frame) {
|
|
1041
|
+
assert(this.hasHistory, "Not recording or playing back, can't seek to frame");
|
|
1042
|
+
this.wasm.seek(frame);
|
|
1043
|
+
}
|
|
1044
|
+
record() {
|
|
1045
|
+
const serializer = this.#serialize ? this.#serialize() : null;
|
|
1046
|
+
const size = serializer ? serializer.size : 0;
|
|
1047
|
+
this.wasm.start_recording(size, 1024);
|
|
1048
|
+
}
|
|
1049
|
+
snapshot() {
|
|
1050
|
+
const serializer = this.#serialize ? this.#serialize() : null;
|
|
1051
|
+
const size = serializer ? serializer.size : 0;
|
|
1052
|
+
const ptr = this.wasm.take_snapshot(size);
|
|
1053
|
+
const header = new Uint32Array(this.#memory.buffer, ptr, 4);
|
|
1054
|
+
const userLenIndex = SNAPSHOT_HEADER_USER_LEN_OFFSET / Uint32Array.BYTES_PER_ELEMENT;
|
|
1055
|
+
const engineLenIndex = SNAPSHOT_HEADER_ENGINE_LEN_OFFSET / Uint32Array.BYTES_PER_ELEMENT;
|
|
1056
|
+
assert(header[userLenIndex], `header user length missing`);
|
|
1057
|
+
assert(header[engineLenIndex], `header engine length missing`);
|
|
1058
|
+
const length = header[userLenIndex] + header[engineLenIndex];
|
|
1059
|
+
const memoryView = new Uint8Array(this.#memory.buffer, ptr, length);
|
|
1060
|
+
const copy = new Uint8Array(length);
|
|
1061
|
+
copy.set(memoryView);
|
|
1062
|
+
return copy;
|
|
1063
|
+
}
|
|
1064
|
+
restore(snapshot) {
|
|
1065
|
+
const dataPtr = this.wasm.alloc(snapshot.byteLength);
|
|
1066
|
+
assert(dataPtr > 0, `failed to allocate ${snapshot.byteLength} bytes for snapshot restore, pointer=${dataPtr}`);
|
|
1067
|
+
const memoryView = new Uint8Array(this.#memory.buffer, dataPtr, snapshot.byteLength);
|
|
1068
|
+
memoryView.set(snapshot);
|
|
1069
|
+
this.wasm.restore(dataPtr);
|
|
1070
|
+
this.wasm.free(dataPtr, snapshot.byteLength);
|
|
1071
|
+
}
|
|
1072
|
+
get time() {
|
|
1073
|
+
if (!this.#time.dataView || this.#time.dataView.buffer !== this.#memory.buffer) {
|
|
1074
|
+
this.#time.dataView = new DataView(this.#memory.buffer, this.wasm.get_time_ctx());
|
|
1075
|
+
}
|
|
1076
|
+
return this.#time;
|
|
1077
|
+
}
|
|
1078
|
+
get buffer() {
|
|
1079
|
+
return this.#memory.buffer;
|
|
1080
|
+
}
|
|
1081
|
+
get isRecording() {
|
|
1082
|
+
return this.wasm.is_recording();
|
|
1083
|
+
}
|
|
1084
|
+
get isReplaying() {
|
|
1085
|
+
return this.wasm.is_replaying();
|
|
1086
|
+
}
|
|
1087
|
+
get hasHistory() {
|
|
1088
|
+
return this.isRecording || this.isReplaying;
|
|
1089
|
+
}
|
|
1090
|
+
emit = {
|
|
1091
|
+
keydown: (key) => {
|
|
1092
|
+
this.wasm.emit_keydown(keyToKeyCode(key));
|
|
1093
|
+
},
|
|
1094
|
+
keyup: (key) => {
|
|
1095
|
+
this.wasm.emit_keyup(keyToKeyCode(key));
|
|
1096
|
+
},
|
|
1097
|
+
mousemove: (x, y) => {
|
|
1098
|
+
this.wasm.emit_mousemove(x, y);
|
|
1099
|
+
},
|
|
1100
|
+
mousedown: (button) => {
|
|
1101
|
+
this.wasm.emit_mousedown(mouseButtonToMouseButtonCode(button));
|
|
1102
|
+
},
|
|
1103
|
+
mouseup: (button) => {
|
|
1104
|
+
this.wasm.emit_mouseup(mouseButtonToMouseButtonCode(button));
|
|
1105
|
+
},
|
|
1106
|
+
mousewheel: (x, y) => {
|
|
1107
|
+
this.wasm.emit_mousewheel(x, y);
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// src/mount.ts
|
|
1113
|
+
async function mount(opts) {
|
|
1114
|
+
const bytes = await fetch(opts.wasmUrl ?? DEFAULT_WASM_URL).then((res) => res.arrayBuffer()).catch((e) => {
|
|
1115
|
+
console.error(`Failed to fetch wasm at ${opts.wasmUrl ?? DEFAULT_WASM_URL}`, e);
|
|
1116
|
+
throw e;
|
|
1117
|
+
});
|
|
1118
|
+
const memory = new WebAssembly.Memory({ initial: 17, maximum: 1000 });
|
|
1119
|
+
const wasmInstantiatedSource = await WebAssembly.instantiate(bytes, {
|
|
1120
|
+
env: {
|
|
1121
|
+
memory,
|
|
1122
|
+
__cb: function(system_handle, ptr) {
|
|
1123
|
+
opts.hooks.setBuffer(memory.buffer);
|
|
1124
|
+
opts.hooks.systemsCallback(system_handle, ptr);
|
|
1125
|
+
},
|
|
1126
|
+
console_log: function(ptr, len) {
|
|
1127
|
+
const bytes2 = new Uint8Array(memory.buffer, ptr, len);
|
|
1128
|
+
const string = new TextDecoder("utf-8").decode(bytes2);
|
|
1129
|
+
console.log(string);
|
|
1130
|
+
},
|
|
1131
|
+
user_data_len: function() {
|
|
1132
|
+
const serializer = opts.hooks.serialize();
|
|
1133
|
+
return serializer ? serializer.size : 0;
|
|
1134
|
+
},
|
|
1135
|
+
user_data_serialize: function(ptr, len) {
|
|
1136
|
+
const serializer = opts.hooks.serialize();
|
|
1137
|
+
assert(len === serializer.size, `user_data_serialize length mismatch, expected=${serializer.size} got=${len}`);
|
|
1138
|
+
serializer.write(memory.buffer, ptr);
|
|
1139
|
+
},
|
|
1140
|
+
user_data_deserialize: function(ptr, len) {
|
|
1141
|
+
opts.hooks.deserialize(memory.buffer, ptr, len);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
const wasm = wasmInstantiatedSource.instance.exports;
|
|
1146
|
+
wasm.initialize();
|
|
1147
|
+
const runtime = new Runtime(wasm, memory, {
|
|
1148
|
+
serialize: opts.hooks.serialize
|
|
1149
|
+
});
|
|
1150
|
+
if (opts.startRecording ?? true) {
|
|
1151
|
+
runtime.record();
|
|
1152
|
+
}
|
|
1153
|
+
return {
|
|
1154
|
+
runtime,
|
|
1155
|
+
wasm
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
// src/bloop.ts
|
|
1159
|
+
class Bloop {
|
|
1160
|
+
#systems = [];
|
|
1161
|
+
#context;
|
|
1162
|
+
#engineBuffer = new ArrayBuffer(0);
|
|
1163
|
+
static create(opts = {}) {
|
|
1164
|
+
return new Bloop(opts, "dontCallMeDirectly");
|
|
1165
|
+
}
|
|
1166
|
+
constructor(opts = {}, dontCallMeDirectly) {
|
|
1167
|
+
if (dontCallMeDirectly !== "dontCallMeDirectly") {
|
|
1168
|
+
throw new Error("Bloop constructor is private. Use Bloop.create() to create a new game instance.");
|
|
1169
|
+
}
|
|
1170
|
+
this.#context = {
|
|
1171
|
+
bag: opts.bag ?? {},
|
|
1172
|
+
time: new TimeContext,
|
|
1173
|
+
inputs: new InputContext,
|
|
1174
|
+
rawPointer: -1
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
get bag() {
|
|
1178
|
+
return this.#context.bag;
|
|
1179
|
+
}
|
|
1180
|
+
get context() {
|
|
1181
|
+
return this.#context;
|
|
1182
|
+
}
|
|
1183
|
+
system(label, system) {
|
|
1184
|
+
system.label ??= label;
|
|
1185
|
+
this.#systems.push(system);
|
|
1186
|
+
return this.#systems.length;
|
|
1187
|
+
}
|
|
1188
|
+
hooks = {
|
|
1189
|
+
serialize: () => {
|
|
1190
|
+
const str = JSON.stringify(this.#context.bag);
|
|
1191
|
+
const encoder = new TextEncoder;
|
|
1192
|
+
const textBytes = encoder.encode(str);
|
|
1193
|
+
return {
|
|
1194
|
+
size: textBytes.byteLength,
|
|
1195
|
+
write: (buffer, ptr) => {
|
|
1196
|
+
const memoryView = new Uint8Array(buffer, ptr, textBytes.byteLength);
|
|
1197
|
+
memoryView.set(textBytes);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
},
|
|
1201
|
+
deserialize: (buffer, ptr, len) => {
|
|
1202
|
+
const bagBytes = new Uint8Array(buffer, ptr, len);
|
|
1203
|
+
const decoder = new TextDecoder;
|
|
1204
|
+
const str = decoder.decode(bagBytes);
|
|
1205
|
+
try {
|
|
1206
|
+
this.#context.bag = JSON.parse(str);
|
|
1207
|
+
} catch (e) {
|
|
1208
|
+
console.error("failed to deserialize bag", { json: str, error: e });
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
setBuffer: (buffer) => {
|
|
1212
|
+
this.#engineBuffer = buffer;
|
|
1213
|
+
},
|
|
1214
|
+
systemsCallback: (system_handle, ptr) => {
|
|
1215
|
+
const dv = new DataView(this.#engineBuffer, ptr);
|
|
1216
|
+
const timeCtxPtr = dv.getUint32(TIME_CTX_OFFSET, true);
|
|
1217
|
+
const inputCtxPtr = dv.getUint32(INPUT_CTX_OFFSET, true);
|
|
1218
|
+
const eventsPtr = dv.getUint32(EVENTS_OFFSET, true);
|
|
1219
|
+
this.#context.rawPointer = ptr;
|
|
1220
|
+
this.#context.inputs.dataView = new DataView(this.#engineBuffer, inputCtxPtr);
|
|
1221
|
+
this.#context.time.dataView = new DataView(this.#engineBuffer, timeCtxPtr);
|
|
1222
|
+
const eventsDataView = new DataView(this.#engineBuffer, eventsPtr);
|
|
1223
|
+
for (const system of this.#systems) {
|
|
1224
|
+
system.update?.(this.#context);
|
|
1225
|
+
const eventCount = eventsDataView.getUint32(0, true);
|
|
1226
|
+
let offset = Uint32Array.BYTES_PER_ELEMENT;
|
|
1227
|
+
for (let i = 0;i < eventCount; i++) {
|
|
1228
|
+
const eventType = eventsDataView.getUint8(offset);
|
|
1229
|
+
const payloadSize = EVENT_PAYLOAD_SIZE;
|
|
1230
|
+
const payloadByte = eventsDataView.getUint8(offset + EVENT_PAYLOAD_ALIGN);
|
|
1231
|
+
const payloadVec2 = {
|
|
1232
|
+
x: eventsDataView.getFloat32(offset + EVENT_PAYLOAD_ALIGN, true),
|
|
1233
|
+
y: eventsDataView.getFloat32(offset + EVENT_PAYLOAD_ALIGN + Float32Array.BYTES_PER_ELEMENT, true)
|
|
1234
|
+
};
|
|
1235
|
+
switch (eventType) {
|
|
1236
|
+
case exports_enums.EventType.KeyDown: {
|
|
1237
|
+
system.keydown?.(attachEvent(this.#context, {
|
|
1238
|
+
key: keyCodeToKey(payloadByte)
|
|
1239
|
+
}));
|
|
1240
|
+
break;
|
|
1241
|
+
}
|
|
1242
|
+
case exports_enums.EventType.KeyUp:
|
|
1243
|
+
system.keyup?.(attachEvent(this.#context, {
|
|
1244
|
+
key: keyCodeToKey(payloadByte)
|
|
1245
|
+
}));
|
|
1246
|
+
break;
|
|
1247
|
+
case exports_enums.EventType.MouseDown:
|
|
1248
|
+
system.mousedown?.(attachEvent(this.#context, {
|
|
1249
|
+
button: mouseButtonCodeToMouseButton(payloadByte)
|
|
1250
|
+
}));
|
|
1251
|
+
break;
|
|
1252
|
+
case exports_enums.EventType.MouseUp:
|
|
1253
|
+
system.mouseup?.(attachEvent(this.#context, {
|
|
1254
|
+
button: mouseButtonCodeToMouseButton(payloadByte)
|
|
1255
|
+
}));
|
|
1256
|
+
break;
|
|
1257
|
+
case exports_enums.EventType.MouseMove:
|
|
1258
|
+
system.mousemove?.(attachEvent(this.#context, {
|
|
1259
|
+
x: payloadVec2.x,
|
|
1260
|
+
y: payloadVec2.y
|
|
1261
|
+
}));
|
|
1262
|
+
break;
|
|
1263
|
+
case exports_enums.EventType.MouseWheel:
|
|
1264
|
+
system.mousewheel?.(attachEvent(this.#context, {
|
|
1265
|
+
x: payloadVec2.x,
|
|
1266
|
+
y: payloadVec2.y
|
|
1267
|
+
}));
|
|
1268
|
+
break;
|
|
1269
|
+
default:
|
|
1270
|
+
throw new Error(`Unknown event type: ${eventType}`);
|
|
1271
|
+
}
|
|
1272
|
+
offset += EVENT_PAYLOAD_ALIGN + EVENT_PAYLOAD_SIZE;
|
|
1273
|
+
}
|
|
1274
|
+
this.#context.event = undefined;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
function attachEvent(context, event) {
|
|
1280
|
+
context.event = event;
|
|
1281
|
+
return context;
|
|
1282
|
+
}
|
|
1283
|
+
export {
|
|
1284
|
+
mount,
|
|
1285
|
+
exports_util as Util,
|
|
1286
|
+
Bloop
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
//# debugId=43C3568B8A190DC064756E2164756E21
|
|
1290
|
+
//# sourceMappingURL=mod.js.map
|