@turbowarp/types 0.0.1
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/.github/workflows/validate.yml +24 -0
- package/LICENSE +202 -0
- package/README.md +87 -0
- package/index.d.ts +40 -0
- package/package.json +28 -0
- package/tests/blockly.ts +15 -0
- package/tests/cjs-es6.js +4 -0
- package/tests/cjs-js.js +3 -0
- package/tests/deprecated.js +4 -0
- package/tests/events.ts +15 -0
- package/tests/render.ts +8 -0
- package/tests/ts-es6.ts +4 -0
- package/tests/ts-require.ts +4 -0
- package/tests/vm.ts +49 -0
- package/tsconfig.json +18 -0
- package/types/events.d.ts +14 -0
- package/types/immutable.d.ts +6 -0
- package/types/jszip.d.ts +10 -0
- package/types/scratch-audio.d.ts +29 -0
- package/types/scratch-blocks.d.ts +183 -0
- package/types/scratch-parser.d.ts +6 -0
- package/types/scratch-render-fonts.d.ts +6 -0
- package/types/scratch-render.d.ts +686 -0
- package/types/scratch-storage.d.ts +20 -0
- package/types/scratch-svg-renderer.d.ts +6 -0
- package/types/scratch-vm.d.ts +1460 -0
- package/types/twgl.d.ts +21 -0
|
@@ -0,0 +1,1460 @@
|
|
|
1
|
+
// Type definitions for scratch-vm
|
|
2
|
+
// Project: https://github.com/LLK/scratch-vm
|
|
3
|
+
|
|
4
|
+
/// <reference path="./events.d.ts" />
|
|
5
|
+
/// <reference path="./immutable.d.ts" />
|
|
6
|
+
/// <reference path="./jszip.d.ts" />
|
|
7
|
+
/// <reference path="./scratch-render.d.ts" />
|
|
8
|
+
/// <reference path="./scratch-audio.d.ts" />
|
|
9
|
+
/// <reference path="./scratch-storage.d.ts" />
|
|
10
|
+
|
|
11
|
+
declare namespace VM {
|
|
12
|
+
/**
|
|
13
|
+
* Indicates the type is dependent on the existence of a renderer.
|
|
14
|
+
*/
|
|
15
|
+
type IfRenderer<HasRenderer, NoRenderer> = HasRenderer;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Indicates the type is dependent on the existence of an audio engine.
|
|
19
|
+
*/
|
|
20
|
+
type IfAudioEngine<HasAudioEngine, NoAudioEngine> = HasAudioEngine;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Indicates thte type is dependent on the existence of an attached storage.
|
|
24
|
+
*/
|
|
25
|
+
type IfStorage<HasStorage, NoStorage> = HasStorage;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Indicates the type is dependent of whether the VM is attached to scratch-gui.
|
|
29
|
+
*/
|
|
30
|
+
type IfGui<HasGui, NoGui> = HasGui;
|
|
31
|
+
|
|
32
|
+
type ScratchCompatibleValue = string | boolean | number;
|
|
33
|
+
|
|
34
|
+
interface ScratchList extends Array<ScratchCompatibleValue> {
|
|
35
|
+
_monitorUpToDate?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type VariableValue = ScratchCompatibleValue | ScratchList;
|
|
39
|
+
|
|
40
|
+
interface BaseAsset {
|
|
41
|
+
/**
|
|
42
|
+
* The md5 of this asset.
|
|
43
|
+
*/
|
|
44
|
+
assetId: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The md5 + file extension of this asset.
|
|
48
|
+
*/
|
|
49
|
+
md5: string;
|
|
50
|
+
|
|
51
|
+
name: string;
|
|
52
|
+
|
|
53
|
+
asset: ScratchStorage.Asset;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Costume extends BaseAsset {
|
|
57
|
+
dataFormat: 'svg' | 'png' | 'jpg';
|
|
58
|
+
bitmapResolution: number;
|
|
59
|
+
rotationCenterX: number;
|
|
60
|
+
rotationCenterY: number;
|
|
61
|
+
size: [number, number];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface Sound extends BaseAsset {
|
|
65
|
+
dataFormat: 'mp3' | 'wav';
|
|
66
|
+
format: ''; // TODO
|
|
67
|
+
rate: number;
|
|
68
|
+
sampleCount: number;
|
|
69
|
+
soundId: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface Sprite {
|
|
73
|
+
runtime: Runtime;
|
|
74
|
+
blocks: Blocks;
|
|
75
|
+
name: string;
|
|
76
|
+
costumes: Costume[];
|
|
77
|
+
sounds: Sound[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface Field {
|
|
81
|
+
id: string | null;
|
|
82
|
+
name: string;
|
|
83
|
+
value: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface Input {
|
|
87
|
+
name: string;
|
|
88
|
+
block: string;
|
|
89
|
+
shadow: string | null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface BaseMutation {
|
|
93
|
+
tagName: 'mutation';
|
|
94
|
+
children: [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Found on blocks with an opcode of procedures_call
|
|
99
|
+
*/
|
|
100
|
+
interface ProcedureCallMutation extends BaseMutation {
|
|
101
|
+
proccode: string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* JSON-stringified list of strings.
|
|
105
|
+
*/
|
|
106
|
+
argumentids: string;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* JSON-stringified boolean.
|
|
110
|
+
*/
|
|
111
|
+
warp: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Found on blocks with an opcode of procedures_prototype
|
|
116
|
+
*/
|
|
117
|
+
interface ProcedurePrototypeMutation extends ProcedureCallMutation {
|
|
118
|
+
/**
|
|
119
|
+
* JSON-stringified list of strings.
|
|
120
|
+
*/
|
|
121
|
+
argumentdefaults: string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* JSON-stringified list of strings.
|
|
125
|
+
*/
|
|
126
|
+
argumentnames: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface Block {
|
|
130
|
+
id: string;
|
|
131
|
+
opcode: string;
|
|
132
|
+
parent: string | null;
|
|
133
|
+
next: string | null;
|
|
134
|
+
shadow: boolean;
|
|
135
|
+
topLevel: boolean;
|
|
136
|
+
inputs: Record<string, Input>;
|
|
137
|
+
fields: Record<string, Field>;
|
|
138
|
+
mutation: null | ProcedureCallMutation | ProcedurePrototypeMutation;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface Blocks {
|
|
142
|
+
runtime: Runtime;
|
|
143
|
+
|
|
144
|
+
_blocks: Record<string, Block>;
|
|
145
|
+
|
|
146
|
+
getBlock(id: string): Block | undefined;
|
|
147
|
+
|
|
148
|
+
getOpcode(id: string): string | null;
|
|
149
|
+
|
|
150
|
+
getFields(id: string): object | null;
|
|
151
|
+
|
|
152
|
+
getInputs(id: string): object | null;
|
|
153
|
+
|
|
154
|
+
getProcedureDefinition(procedureCode: string): string | null;
|
|
155
|
+
|
|
156
|
+
getProcedureParamNamesAndIds(procedureCode: string): [
|
|
157
|
+
// Argument name
|
|
158
|
+
string[],
|
|
159
|
+
// Argument IDs
|
|
160
|
+
string[]
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
getProcedureParamNamesIdsAndDefaults(procedureCode: string): [
|
|
164
|
+
// Argument names
|
|
165
|
+
string[],
|
|
166
|
+
// Argument IDs
|
|
167
|
+
string[],
|
|
168
|
+
// Argument defaults
|
|
169
|
+
unknown[]
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
duplicate(): Blocks;
|
|
173
|
+
|
|
174
|
+
resetCache(): void;
|
|
175
|
+
|
|
176
|
+
emitProjectChanged(): void;
|
|
177
|
+
|
|
178
|
+
toXML(): string;
|
|
179
|
+
|
|
180
|
+
forceNoGlow: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface BaseVariable {
|
|
184
|
+
id: string;
|
|
185
|
+
name: string;
|
|
186
|
+
isCloud: boolean;
|
|
187
|
+
toXML(isLocal?: boolean): string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const enum VariableType {
|
|
191
|
+
Scalar = '',
|
|
192
|
+
List = 'list',
|
|
193
|
+
Broadcast = 'broadcast_msg'
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface ScalarVariable extends BaseVariable {
|
|
197
|
+
type: '';
|
|
198
|
+
value: ScratchCompatibleValue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface ListVariable extends BaseVariable {
|
|
202
|
+
type: 'list';
|
|
203
|
+
value: ScratchList;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface BroadcastVariable extends BaseVariable {
|
|
207
|
+
type: 'broadcast_msg';
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Always the same as name.
|
|
211
|
+
*/
|
|
212
|
+
value: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
type Variable = ScalarVariable | ListVariable | BroadcastVariable;
|
|
216
|
+
|
|
217
|
+
interface Comment {
|
|
218
|
+
id: string;
|
|
219
|
+
blockId: string | null;
|
|
220
|
+
minimized: boolean;
|
|
221
|
+
text: string;
|
|
222
|
+
x: number;
|
|
223
|
+
y: number;
|
|
224
|
+
width: number;
|
|
225
|
+
height: number;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface PostedSpriteInfo {
|
|
229
|
+
force?: boolean;
|
|
230
|
+
x?: number;
|
|
231
|
+
y?: number;
|
|
232
|
+
direction?: number;
|
|
233
|
+
draggable?: boolean;
|
|
234
|
+
rotationStyle?: VM.RotationStyle;
|
|
235
|
+
visible?: boolean;
|
|
236
|
+
size?: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface BaseTarget extends EventEmitter<{}> {
|
|
240
|
+
runtime: Runtime;
|
|
241
|
+
|
|
242
|
+
id: string;
|
|
243
|
+
|
|
244
|
+
blocks: Blocks;
|
|
245
|
+
|
|
246
|
+
variables: Record<string, Variable>;
|
|
247
|
+
|
|
248
|
+
comments: Record<string, Comment>;
|
|
249
|
+
|
|
250
|
+
_customState: Record<string, unknown>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Called by runtime when the green flag is pressed.
|
|
254
|
+
*/
|
|
255
|
+
onGreenFlag(): void;
|
|
256
|
+
|
|
257
|
+
getName(): string;
|
|
258
|
+
|
|
259
|
+
lookupOrCreateVariable(id: string, name: string): ScalarVariable;
|
|
260
|
+
|
|
261
|
+
lookupBroadcastMsg(id: string, name: string): BroadcastVariable | undefined;
|
|
262
|
+
|
|
263
|
+
lookupBroadcastByInputValue(name: string): BroadcastVariable | undefined;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Look for a variable by its ID in this target.
|
|
267
|
+
* If it doesn't exist in this target, will check if it exists in the stage target.
|
|
268
|
+
* If it still doesn't exist, returns undefined.
|
|
269
|
+
*/
|
|
270
|
+
lookupVariableById(id: string): Variable | undefined;
|
|
271
|
+
|
|
272
|
+
lookupVariableByNameAndType(name: string): ScalarVariable | undefined;
|
|
273
|
+
lookupVariableByNameAndType(name: string, type: '', skipStage?: boolean): ScalarVariable | undefined;
|
|
274
|
+
lookupVariableByNameAndType(name: string, type: 'list', skipStage?: boolean): ListVariable | undefined;
|
|
275
|
+
lookupVariableByNameAndType(name: string, type: 'broadcast_msg', skipStage?: boolean): BroadcastVariable | undefined;
|
|
276
|
+
|
|
277
|
+
lookupOrCreateList(id: string, name: string): ListVariable;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Create a new variable. If the ID is already used, silently does nothing.
|
|
281
|
+
* isCloud is ignored if the sprite is not the stage or if the cloud variable limit has been reached.
|
|
282
|
+
*/
|
|
283
|
+
createVariable(id: string, name: string, type: VariableType, isCloud?: boolean): void;
|
|
284
|
+
|
|
285
|
+
postSpriteInfo(spriteInfo: PostedSpriteInfo): void;
|
|
286
|
+
|
|
287
|
+
dispose(): void;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const enum RotationStyle {
|
|
291
|
+
AllAround = 'all-around',
|
|
292
|
+
LeftRight = 'left-right',
|
|
293
|
+
None = "don't rotate"
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
interface RenderedTargetEventMap {
|
|
297
|
+
// TODO
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const enum Effect {
|
|
301
|
+
// TODO: document ranges
|
|
302
|
+
Color = 'color',
|
|
303
|
+
Fisheye = 'fisheye',
|
|
304
|
+
Whirl = 'whirl',
|
|
305
|
+
Pixelate = 'pixelate',
|
|
306
|
+
Mosaic = 'mosaic',
|
|
307
|
+
Brightness = 'brightness',
|
|
308
|
+
Ghost = 'ghost'
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @see {Renderer.Rectangle}
|
|
313
|
+
*/
|
|
314
|
+
interface SimpleRectangle {
|
|
315
|
+
left: number;
|
|
316
|
+
right: number;
|
|
317
|
+
top: number;
|
|
318
|
+
bottom: number;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
interface RenderedTarget extends BaseTarget {
|
|
322
|
+
sprite: Sprite;
|
|
323
|
+
|
|
324
|
+
renderer: IfRenderer<RenderWebGL, undefined>;
|
|
325
|
+
|
|
326
|
+
drawableID: number;
|
|
327
|
+
|
|
328
|
+
isOriginal: boolean;
|
|
329
|
+
|
|
330
|
+
isStage: boolean;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Returns true if the target is not the stage and is not a clone.
|
|
334
|
+
*/
|
|
335
|
+
isSprite(): boolean;
|
|
336
|
+
|
|
337
|
+
x: number;
|
|
338
|
+
|
|
339
|
+
y: number;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Update the sprite's position. The given coordinates may be fenced to make the target fit on screen.
|
|
343
|
+
* Set force to true to force the sprite to move even if it's being dragged.
|
|
344
|
+
*/
|
|
345
|
+
setXY(x: number, y: number, force?: boolean): void;
|
|
346
|
+
|
|
347
|
+
keepInFence(newX: number, newY: number, fence?: SimpleRectangle): [number, number];
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Direction in degrees. Defaults to 90 (right). Can be from -179 to 180.
|
|
351
|
+
*/
|
|
352
|
+
direction: number;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Change the sprite's direction. The direction will be wrapped as needed to fit in the expected range.
|
|
356
|
+
*/
|
|
357
|
+
setDirection(direction: number): void;
|
|
358
|
+
|
|
359
|
+
rotationStyle: RotationStyle;
|
|
360
|
+
|
|
361
|
+
setRotationStyle(rotationStyle: RotationStyle): void;
|
|
362
|
+
|
|
363
|
+
_getRenderedDirectionAndScale(): {
|
|
364
|
+
direction: number;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* X scale then Y scale, both from 100.
|
|
368
|
+
* A negative scale means that the target should be flipped on that axis.
|
|
369
|
+
*/
|
|
370
|
+
scale: [number, number];
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
visible: boolean;
|
|
374
|
+
|
|
375
|
+
setVisible(visible: boolean): void;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The sprite's size. Default is 100.
|
|
379
|
+
*/
|
|
380
|
+
size: number;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Change the sprite's size. The given size may be fenced to make the target fit on screen and isn't negative.
|
|
384
|
+
*/
|
|
385
|
+
setSize(size: number): void;
|
|
386
|
+
|
|
387
|
+
getBounds(): IfRenderer<RenderWebGL.Rectangle, null>;
|
|
388
|
+
|
|
389
|
+
getBoundsForBubble(): IfRenderer<RenderWebGL.Rectangle, null>;
|
|
390
|
+
|
|
391
|
+
draggable: boolean;
|
|
392
|
+
|
|
393
|
+
setDraggable(draggable: boolean): void;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The index of the current costume.
|
|
397
|
+
*/
|
|
398
|
+
currentCostume: number;
|
|
399
|
+
|
|
400
|
+
getCurrentCostume(): Costume;
|
|
401
|
+
|
|
402
|
+
getCostumes(): Costume[];
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Update the current costume index.
|
|
406
|
+
* If index is not finite, it will be converted to 0.
|
|
407
|
+
* If index is not in the list, it will wrap around.
|
|
408
|
+
*/
|
|
409
|
+
setCostume(costumeIndex: number): void;
|
|
410
|
+
|
|
411
|
+
addCostume(costume: Costume, index: number): void;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Rename the costume at a given index.
|
|
415
|
+
* Will throw an error if the index is out of bounds.
|
|
416
|
+
* If the new name is already used, it may be modified.
|
|
417
|
+
*/
|
|
418
|
+
renameCostume(costumeIndex: number, newName: string): void;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Get the index of a costume with a given name.
|
|
422
|
+
* If the costume doesn't exist, returns -1.
|
|
423
|
+
*/
|
|
424
|
+
getCostumeIndexByName(name: string): number;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Delete the costume at a given index.
|
|
428
|
+
* Returns the deleted costume if one exists at that index, otherwise null.
|
|
429
|
+
*/
|
|
430
|
+
deleteCostume(costumeIndex: number): Costume | null;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Move the costume from one index to another.
|
|
434
|
+
* Returns true if any change was made.
|
|
435
|
+
*/
|
|
436
|
+
reorderCostume(costumeIndex: number, newIndex: number): boolean;
|
|
437
|
+
|
|
438
|
+
getSounds(): Sound[];
|
|
439
|
+
|
|
440
|
+
addSound(sound: Sound, index: number): void;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* @see {renameCostume}
|
|
444
|
+
*/
|
|
445
|
+
renameSound(soundIndex: number, name: string): void;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @see {deleteCostume}
|
|
449
|
+
*/
|
|
450
|
+
deleteSound(soundIndex: number): Sound | null;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @see {reorderCostume}
|
|
454
|
+
*/
|
|
455
|
+
reorderSound(soundIndex: number, newIndex: number): boolean;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Visual effects on the target. All default to 0.
|
|
459
|
+
*/
|
|
460
|
+
effects: Record<Effect, number>;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Update the value of an effect.
|
|
464
|
+
* @param effectName
|
|
465
|
+
* @param value
|
|
466
|
+
*/
|
|
467
|
+
setEffect(effectName: Effect, value: number): void;
|
|
468
|
+
|
|
469
|
+
clearEffects(): void;
|
|
470
|
+
|
|
471
|
+
isTouchingObject(object: '_mouse_' | '_edge_' | string): boolean;
|
|
472
|
+
|
|
473
|
+
isTouchingPoint(x: number, y: number): boolean;
|
|
474
|
+
|
|
475
|
+
isTouchingEdge(): boolean;
|
|
476
|
+
|
|
477
|
+
isTouchingSprite(spriteName: string): boolean;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* @param rgb RGB channels from [0-255]
|
|
481
|
+
*/
|
|
482
|
+
isTouchingColor(rgb: [number, number, number]): boolean;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @param rgb RGB channels from [0-255]
|
|
486
|
+
* @param mask RGB channels from [0-255]
|
|
487
|
+
*/
|
|
488
|
+
colorIsTouchingColor(rgb: [number, number, number], mask: [number, number, number]): boolean;
|
|
489
|
+
|
|
490
|
+
getLayerOrder(): IfRenderer<number, null>;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Make sure this target is not the stage before calling this method.
|
|
494
|
+
*/
|
|
495
|
+
goToFront(): void;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Make sure this target is not the stage before calling this method.
|
|
499
|
+
*/
|
|
500
|
+
goToBack(): void;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Make sure this target is not the stage before calling this method.
|
|
504
|
+
*/
|
|
505
|
+
goForwardLayers(layers: number): void;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Make sure this target is not the stage before calling this method.
|
|
509
|
+
*/
|
|
510
|
+
goBackwardLayers(layers: number): void;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Make sure this target and the target being moved behind are not the stage before calling this method.
|
|
514
|
+
*/
|
|
515
|
+
goBehindOther(other: RenderedTarget): void;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Defaults to 100.
|
|
519
|
+
*/
|
|
520
|
+
volume: number;
|
|
521
|
+
|
|
522
|
+
tempo: number;
|
|
523
|
+
|
|
524
|
+
videoTransparency: number;
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Create a clone of this sprite if the clone limit has not been reached.
|
|
529
|
+
*/
|
|
530
|
+
makeClone(): RenderedTarget | null;
|
|
531
|
+
|
|
532
|
+
duplicate(): Promise<RenderedTarget>;
|
|
533
|
+
|
|
534
|
+
startDrag(): void;
|
|
535
|
+
|
|
536
|
+
stopDrag(): void;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Called by the runtime when the project is stopped.
|
|
540
|
+
*/
|
|
541
|
+
onStopAll(): void;
|
|
542
|
+
|
|
543
|
+
toJSON(): SerializedTarget;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// These types are intended for use in a browser environment where a base Target can never be created as
|
|
547
|
+
// all targets are RenderedTarget.
|
|
548
|
+
type Target = RenderedTarget;
|
|
549
|
+
|
|
550
|
+
interface SerializedTarget {
|
|
551
|
+
// TODO
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
interface StackFrame {
|
|
555
|
+
// TODO
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const enum ThreadStatus {
|
|
559
|
+
STATUS_RUNNING = 0,
|
|
560
|
+
STATUS_PROMISE_WAIT = 1,
|
|
561
|
+
STATUS_YIELD = 2,
|
|
562
|
+
STATUS_YIELD_TICK = 3,
|
|
563
|
+
STATUS_DONE = 4
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
interface Thread {
|
|
567
|
+
topBlock: string;
|
|
568
|
+
stack: string[];
|
|
569
|
+
stackFrames: StackFrame[];
|
|
570
|
+
status: ThreadStatus;
|
|
571
|
+
isKilled: boolean;
|
|
572
|
+
target: Target;
|
|
573
|
+
blockContainer: Blocks;
|
|
574
|
+
requestScriptGlowInFrame: boolean;
|
|
575
|
+
blockGlowInFrame: string | null;
|
|
576
|
+
warpTimer: Timer | null;
|
|
577
|
+
justReported: unknown;
|
|
578
|
+
pushStack(blockId: string): void;
|
|
579
|
+
popStack(): string;
|
|
580
|
+
peekStack(): string;
|
|
581
|
+
peekStackFrame(): StackFrame | null;
|
|
582
|
+
peekParentStackFrame(): StackFrame | null;
|
|
583
|
+
initParams(): void;
|
|
584
|
+
pushParam(name: string, value: ScratchCompatibleValue): void;
|
|
585
|
+
getParam(name: string): ScratchCompatibleValue | null;
|
|
586
|
+
atStackTop(): boolean;
|
|
587
|
+
goToNextBlock(): void;
|
|
588
|
+
isRecursiveCall(procedureCode: string): boolean;
|
|
589
|
+
stackClick: boolean;
|
|
590
|
+
updateMonitor: boolean;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
interface HatInfo {
|
|
594
|
+
edgeActivated?: boolean;
|
|
595
|
+
restartExistingThreads?: boolean;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
interface ExtensionInfo {
|
|
599
|
+
// TODO
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
interface Peripheral {
|
|
603
|
+
// TODO
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
interface Profiler {
|
|
607
|
+
// TODO
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
interface ProfilerFrame {
|
|
611
|
+
// TODO
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
interface Sequencer {
|
|
615
|
+
timer: Timer;
|
|
616
|
+
runtime: Runtime;
|
|
617
|
+
activeThread: Thread | null;
|
|
618
|
+
stepThreads(): void;
|
|
619
|
+
stepThread(thread: Thread): void;
|
|
620
|
+
stepToBranch(thread: Thread, branch: number, isLoop: boolean): void;
|
|
621
|
+
stepToProcedure(thread: Thread, procedureCode: string): void;
|
|
622
|
+
retireThread(thread: Thread): void;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
interface ImportedExtensionsInfo {
|
|
626
|
+
extensionIDs: string[];
|
|
627
|
+
extensionURLs: string[];
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
interface ExtensionManager {
|
|
631
|
+
runtime: Runtime;
|
|
632
|
+
|
|
633
|
+
isExtensionLoaded(extensionID: string): boolean;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Load a builtin extension.
|
|
637
|
+
* Logs a warning if the extension is already loaded or could not be found.
|
|
638
|
+
*/
|
|
639
|
+
loadExtensionIdSync(extensionID: string): void;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Load a remote extension. Does not work on scratch.mit.edu.
|
|
643
|
+
*/
|
|
644
|
+
loadExtensionURL(extensionID: string): void;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Timer operates on milliseconds.
|
|
649
|
+
*/
|
|
650
|
+
interface Timer {
|
|
651
|
+
startTime: number;
|
|
652
|
+
|
|
653
|
+
time(): number;
|
|
654
|
+
|
|
655
|
+
relativeTime(): number;
|
|
656
|
+
|
|
657
|
+
start(): void;
|
|
658
|
+
|
|
659
|
+
timeElapsed(): number;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* @see {window.setTimeout}
|
|
663
|
+
*/
|
|
664
|
+
setTimeout(callback: () => void, timeoutMS: number): number;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* @see {window.clearTImeout}
|
|
668
|
+
*/
|
|
669
|
+
clearTimeout(timeoutID: number): void;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
interface Clock {
|
|
673
|
+
_projectTimer: Timer;
|
|
674
|
+
|
|
675
|
+
_paused: boolean;
|
|
676
|
+
|
|
677
|
+
_pausedTime: number | null;
|
|
678
|
+
|
|
679
|
+
runtime: Runtime;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Project's current time in seconds.
|
|
683
|
+
*/
|
|
684
|
+
projectTimer(): number;
|
|
685
|
+
|
|
686
|
+
pause(): void;
|
|
687
|
+
|
|
688
|
+
resume(): void;
|
|
689
|
+
|
|
690
|
+
resetProjectTimer(): void;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
interface CloudProvider {
|
|
694
|
+
createVariable(name: string, value: ScratchCompatibleValue): void;
|
|
695
|
+
updateVariable(name: string, value: ScratchCompatibleValue): void;
|
|
696
|
+
renameVariable(oldName: string, newName: string): void;
|
|
697
|
+
deleteVariable(name: string): void;
|
|
698
|
+
requestCloseConnection(): void;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
interface CloudVariableUpdate {
|
|
702
|
+
name: string;
|
|
703
|
+
value: ScratchCompatibleValue;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
interface CloudData {
|
|
707
|
+
varUpdate: CloudVariableUpdate;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
interface Cloud {
|
|
711
|
+
runtime: Runtime;
|
|
712
|
+
provider: CloudProvider | null;
|
|
713
|
+
setProvider(provider: CloudProvider | null): void;
|
|
714
|
+
stage: Target | null;
|
|
715
|
+
setStage(stage: Target | null): void;
|
|
716
|
+
postData(data: CloudData): void;
|
|
717
|
+
requestCreateVariable(variable: ScalarVariable): void;
|
|
718
|
+
requestUpdateVariable(name: string, value: ScratchCompatibleValue): void;
|
|
719
|
+
requestRenameVariable(oldName: string, newName: string): void;
|
|
720
|
+
requestDeleteVariable(name: string): void;
|
|
721
|
+
updateCloudVariable(varUpdate: CloudVariableUpdate): void;
|
|
722
|
+
clear(): void;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
interface KeyboardData {
|
|
726
|
+
key: string;
|
|
727
|
+
isDown: boolean;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
interface Keyboard {
|
|
731
|
+
runtime: Runtime;
|
|
732
|
+
postData(data: KeyboardData): void;
|
|
733
|
+
_keyStringToScratchKey(key: string): string;
|
|
734
|
+
_keyArgToScratchKey(key: string | number): string;
|
|
735
|
+
getKeyIsDown(key: string | number): boolean;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
interface MouseData {
|
|
739
|
+
x?: number;
|
|
740
|
+
y?: number;
|
|
741
|
+
canvasWidth?: number;
|
|
742
|
+
canvasHeight?: number;
|
|
743
|
+
isDown?: boolean;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
interface Mouse {
|
|
747
|
+
runtime: Runtime;
|
|
748
|
+
_clientX: number;
|
|
749
|
+
_clientY: number;
|
|
750
|
+
getClientX(): number;
|
|
751
|
+
getClientY(): number;
|
|
752
|
+
_scratchX: number;
|
|
753
|
+
_scratchY: number;
|
|
754
|
+
getScratchX(): number;
|
|
755
|
+
getScratchY(): number;
|
|
756
|
+
_isDown: boolean;
|
|
757
|
+
getIsDown(): boolean;
|
|
758
|
+
postData(data: MouseData): void;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
interface MouseWheelData {
|
|
762
|
+
deltaY: number;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
interface MouseWheel {
|
|
766
|
+
runtime: Runtime;
|
|
767
|
+
postData(data: MouseWheelData): void;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
interface UserDataData {
|
|
771
|
+
username: string;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
interface UserData {
|
|
775
|
+
_username: string;
|
|
776
|
+
getUsername(): string;
|
|
777
|
+
postData(data: UserData): void;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
interface VideoProvider {
|
|
781
|
+
// TODO
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
interface VideoData {
|
|
785
|
+
// TODO
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
interface Video {
|
|
789
|
+
// TODO
|
|
790
|
+
postData(data: VideoData): void;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
interface IODevices {
|
|
794
|
+
clock: Clock;
|
|
795
|
+
cloud: Cloud;
|
|
796
|
+
keyboard: Keyboard;
|
|
797
|
+
mouse: Mouse;
|
|
798
|
+
mouseWheel: MouseWheel;
|
|
799
|
+
userData: UserData;
|
|
800
|
+
video: Video;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
interface RuntimeAndVirtualMachineEventMap {
|
|
804
|
+
SCRIPT_GLOW_ON: [{
|
|
805
|
+
id: string;
|
|
806
|
+
}];
|
|
807
|
+
|
|
808
|
+
SCRIPT_GLOW_OFF: [{
|
|
809
|
+
id: string;
|
|
810
|
+
}];
|
|
811
|
+
|
|
812
|
+
BLOCK_GLOW_ON: [{
|
|
813
|
+
id: string;
|
|
814
|
+
}];
|
|
815
|
+
|
|
816
|
+
BLOCK_GLOW_OFF: [{
|
|
817
|
+
id: string
|
|
818
|
+
}];
|
|
819
|
+
|
|
820
|
+
PROJECT_START: [{
|
|
821
|
+
id: string;
|
|
822
|
+
value: string;
|
|
823
|
+
}];
|
|
824
|
+
|
|
825
|
+
PROJECT_RUN_START: [];
|
|
826
|
+
|
|
827
|
+
PROJECT_RUN_STOP: [];
|
|
828
|
+
|
|
829
|
+
PROJECT_CHANGED: [];
|
|
830
|
+
|
|
831
|
+
VISUAL_REPORT: [{
|
|
832
|
+
id: string;
|
|
833
|
+
value: string;
|
|
834
|
+
}];
|
|
835
|
+
|
|
836
|
+
MONITORS_UPDATE: [OrderedMap];
|
|
837
|
+
|
|
838
|
+
BLOCK_DRAG_UPDATE: [
|
|
839
|
+
// Are blocks over GUI?
|
|
840
|
+
boolean
|
|
841
|
+
];
|
|
842
|
+
|
|
843
|
+
BLOCK_DRAG_END: [
|
|
844
|
+
// Blocks being dragged to the GUI
|
|
845
|
+
unknown[],
|
|
846
|
+
// Original ID of top block being dragged
|
|
847
|
+
string
|
|
848
|
+
];
|
|
849
|
+
|
|
850
|
+
EXTENSION_ADDED: [ExtensionInfo];
|
|
851
|
+
|
|
852
|
+
EXTENSION_FIELD_ADDED: [{
|
|
853
|
+
name: string;
|
|
854
|
+
implementation: unknown;
|
|
855
|
+
}];
|
|
856
|
+
|
|
857
|
+
BLOCKSINFO_UPDATE: [ExtensionInfo];
|
|
858
|
+
|
|
859
|
+
// TODO: is this number or string?
|
|
860
|
+
PERIPHERAL_LIST_UPDATE: [Record<number, Peripheral>];
|
|
861
|
+
|
|
862
|
+
// TODO: is this number or string?
|
|
863
|
+
USER_PICKED_PERIPHERAL: [Record<number, Peripheral>];
|
|
864
|
+
|
|
865
|
+
PERIPHERAL_CONNECTED: [];
|
|
866
|
+
|
|
867
|
+
PERIPHERAL_DISCONNECTED: [];
|
|
868
|
+
|
|
869
|
+
PERIPHERAL_REQUEST_ERROR: [{
|
|
870
|
+
message: string;
|
|
871
|
+
extensionId: string;
|
|
872
|
+
}];
|
|
873
|
+
|
|
874
|
+
PERIPHERAL_CONNECTION_LOST_ERROR: [{
|
|
875
|
+
message: string;
|
|
876
|
+
extensionId: string;
|
|
877
|
+
}];
|
|
878
|
+
|
|
879
|
+
PERIPHERAL_SCAN_TIMEOUT: [];
|
|
880
|
+
|
|
881
|
+
MIC_LISTENING: [
|
|
882
|
+
// Is the mic listening?
|
|
883
|
+
boolean
|
|
884
|
+
];
|
|
885
|
+
|
|
886
|
+
RUNTIME_STARTED: [];
|
|
887
|
+
|
|
888
|
+
RUNTIME_STOPPED: [];
|
|
889
|
+
|
|
890
|
+
HAS_CLOUD_DATA_UPDATE: [
|
|
891
|
+
// Has cloud data?
|
|
892
|
+
boolean
|
|
893
|
+
];
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
interface RuntimeEventMap extends RuntimeAndVirtualMachineEventMap {
|
|
897
|
+
PROJECT_STOP_ALL: [];
|
|
898
|
+
|
|
899
|
+
STOP_FOR_TARGET: [BaseTarget, Thread | undefined];
|
|
900
|
+
|
|
901
|
+
PROJECT_LOADED: [];
|
|
902
|
+
|
|
903
|
+
RUNTIME_DISPOSED: [];
|
|
904
|
+
|
|
905
|
+
TARGETS_UPDATE: [
|
|
906
|
+
// Whether to emit project changed
|
|
907
|
+
boolean
|
|
908
|
+
];
|
|
909
|
+
|
|
910
|
+
BLOCKS_NEED_UPDATE: [];
|
|
911
|
+
|
|
912
|
+
TOOLBOX_EXTENSIONS_NEED_UPDATE: [];
|
|
913
|
+
|
|
914
|
+
targetWasCreated: [
|
|
915
|
+
// The new target
|
|
916
|
+
Target,
|
|
917
|
+
// The original target, if any. This will be set for clones.
|
|
918
|
+
Target?
|
|
919
|
+
];
|
|
920
|
+
|
|
921
|
+
targetWasRemoved: [Target];
|
|
922
|
+
|
|
923
|
+
SAY: [Target, 'say' | 'think', string];
|
|
924
|
+
|
|
925
|
+
QUESTION: [string | null];
|
|
926
|
+
|
|
927
|
+
ANSWER: [string];
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
interface Runtime extends EventEmitter<RuntimeEventMap> {
|
|
931
|
+
/**
|
|
932
|
+
* Start the runtime's event loop. This doesn't start any scripts.
|
|
933
|
+
*/
|
|
934
|
+
start(): void;
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Start "when green flag pressed" scripts.
|
|
938
|
+
*/
|
|
939
|
+
greenFlag(): void;
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Press the stop sign.
|
|
943
|
+
*/
|
|
944
|
+
stopAll(): void;
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* The event loop function.
|
|
948
|
+
*/
|
|
949
|
+
_step(): void;
|
|
950
|
+
|
|
951
|
+
renderer: IfRenderer<RenderWebGL, undefined>;
|
|
952
|
+
|
|
953
|
+
attachRenderer(renderer: RenderWebGL): void;
|
|
954
|
+
|
|
955
|
+
audioEngine: IfAudioEngine<AudioEngine, undefined>;
|
|
956
|
+
|
|
957
|
+
attachAudioEngine(audioEngine: AudioEngine): void;
|
|
958
|
+
|
|
959
|
+
storage: IfGui<GUIScratchStorage, ScratchStorage>;
|
|
960
|
+
|
|
961
|
+
attachStorage(storage: ScratchStorage): void;
|
|
962
|
+
|
|
963
|
+
targets: Target[];
|
|
964
|
+
|
|
965
|
+
executableTargets: Target[];
|
|
966
|
+
|
|
967
|
+
addTarget(target: Target): void;
|
|
968
|
+
|
|
969
|
+
moveExecutable(target: Target, delta: number): void;
|
|
970
|
+
|
|
971
|
+
setExecutablePosition(target: Target, newIndex: number): void;
|
|
972
|
+
|
|
973
|
+
removeExecutable(target: Target): void;
|
|
974
|
+
|
|
975
|
+
disposeTarget(target: Target): void;
|
|
976
|
+
|
|
977
|
+
stopForTarget(target: Target): void;
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Returns the target that is the stage.
|
|
981
|
+
* Returns undefined if called before the project has loaded or if the stage has somehow been removed.
|
|
982
|
+
*/
|
|
983
|
+
getTargetForStage(): Target | undefined;
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Look up a target by its ID.
|
|
987
|
+
* Returns undefined if the target doesn't exist.
|
|
988
|
+
*/
|
|
989
|
+
getTargetById(targetId: string): Target | undefined;
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Find a sprite's original target (not a clone) using the sprite's name.
|
|
993
|
+
* Returns undefined if the target doesn't exist.
|
|
994
|
+
*/
|
|
995
|
+
getSpriteTargetByName(spriteName: string): Target | undefined;
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Look up a target by it's drawable ID.
|
|
999
|
+
* Returns undefined if the target doesn't exist.
|
|
1000
|
+
*/
|
|
1001
|
+
getTargetByDrawableId(drawableID: number): Target | undefined;
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Emit a targetWasCreated event.
|
|
1005
|
+
*/
|
|
1006
|
+
fireTargetWasCreated(newTarget: Target, oldTarget?: Target): void;
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* Emit a targetWasRemoved event.
|
|
1010
|
+
*/
|
|
1011
|
+
fireTargetWasRemoved(target: Target): void;
|
|
1012
|
+
|
|
1013
|
+
threads: Thread[];
|
|
1014
|
+
|
|
1015
|
+
_pushThread(topBlockId: string, target: Target, options?: {
|
|
1016
|
+
stackClick?: boolean;
|
|
1017
|
+
updateMonitor?: boolean;
|
|
1018
|
+
}): Thread;
|
|
1019
|
+
|
|
1020
|
+
_stopThread(thread: Thread): void;
|
|
1021
|
+
|
|
1022
|
+
_restartThread(thread: Thread): void;
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* A thread is considered active if it is in the thread list and is not STATUS_DONE.
|
|
1026
|
+
*/
|
|
1027
|
+
isActiveThread(thread: Thread): boolean;
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* A thread is considered waiting if:
|
|
1031
|
+
* - It is in STATUS_PROMISE_WAIT, or
|
|
1032
|
+
* - It is in STATUS_YIELD_TICK, or
|
|
1033
|
+
* - It is not considered active
|
|
1034
|
+
* @see {isActiveThread}
|
|
1035
|
+
*/
|
|
1036
|
+
isWaitingThread(thread: Thread): boolean;
|
|
1037
|
+
|
|
1038
|
+
_getMonitorThreadCount(threads: Thread[]): number;
|
|
1039
|
+
|
|
1040
|
+
startHats(opcode: string, matchFields?: Record<string, unknown>, target?: Target): void;
|
|
1041
|
+
|
|
1042
|
+
toggleScript(topBlockId: string, options?: {
|
|
1043
|
+
target?: string;
|
|
1044
|
+
stackClick?: boolean;
|
|
1045
|
+
}): void;
|
|
1046
|
+
|
|
1047
|
+
allScriptsDo(callback: (blockId: string, target: Target) => void, target?: Target): void;
|
|
1048
|
+
|
|
1049
|
+
allScriptsByOpcodeDo(opcode: string, callback: (blockId: string, target: Target) => void, target?: Target): void;
|
|
1050
|
+
|
|
1051
|
+
sequencer: Sequencer;
|
|
1052
|
+
|
|
1053
|
+
flyoutBlocks: Blocks;
|
|
1054
|
+
|
|
1055
|
+
monitorBlocks: Blocks;
|
|
1056
|
+
|
|
1057
|
+
visualReport(blockId: string, value: any): void;
|
|
1058
|
+
|
|
1059
|
+
_primitives: Record<string, Function>;
|
|
1060
|
+
|
|
1061
|
+
getOpcodeFunction(opcode: string): Function;
|
|
1062
|
+
|
|
1063
|
+
getLabelForOpcode(opcode: string): {
|
|
1064
|
+
category: 'extension';
|
|
1065
|
+
label: string;
|
|
1066
|
+
} | undefined;
|
|
1067
|
+
|
|
1068
|
+
getBlocksXML(target?: Target): Array<{
|
|
1069
|
+
id: string;
|
|
1070
|
+
xml: string;
|
|
1071
|
+
}>;
|
|
1072
|
+
|
|
1073
|
+
_blockInfo: ExtensionInfo[];
|
|
1074
|
+
|
|
1075
|
+
_hats: Record<string, HatInfo>;
|
|
1076
|
+
|
|
1077
|
+
getIsHat(opcode: string): boolean;
|
|
1078
|
+
|
|
1079
|
+
getIsEdgeActivatedHat(opcode: string): boolean;
|
|
1080
|
+
|
|
1081
|
+
_cloneCounter: number;
|
|
1082
|
+
|
|
1083
|
+
changeCloneCounter(changeAmount: number): void;
|
|
1084
|
+
|
|
1085
|
+
clonesAvailable(): boolean;
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* The time of a step, measured in milliseconds. null if accessed before the project has started.
|
|
1089
|
+
*/
|
|
1090
|
+
currentStepTime: number | null;
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Interval ID returned by setInterval(). null if accessed before the project has started.
|
|
1094
|
+
*/
|
|
1095
|
+
_steppingInterval: number | null;
|
|
1096
|
+
|
|
1097
|
+
redrawRequested: boolean;
|
|
1098
|
+
|
|
1099
|
+
requestRedraw(): void;
|
|
1100
|
+
|
|
1101
|
+
currentMSecs: number;
|
|
1102
|
+
|
|
1103
|
+
updateCurrentMSecs(): void;
|
|
1104
|
+
|
|
1105
|
+
ioDevices: IODevices;
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns true if the runtime's cloud variable counter is non-zero.
|
|
1109
|
+
*/
|
|
1110
|
+
hasCloudData(): boolean;
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Returns true if the runtime's cloud variable counter is under the limit.
|
|
1114
|
+
*/
|
|
1115
|
+
canAddCloudVariable(): boolean;
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns the value of the runtime's cloud variable counter.
|
|
1119
|
+
*/
|
|
1120
|
+
getNumberOfCloudVariables(): number;
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Increment the value of the runtime's cloud variable counter.
|
|
1124
|
+
* Check the value before you call this method; it will let the counter go above the limit.
|
|
1125
|
+
* This method does not actually create a new cloud variable.
|
|
1126
|
+
*/
|
|
1127
|
+
addCloudVariable(): void;
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* Decrement the value of the runtime's cloud variable counter.
|
|
1131
|
+
* Check the value before you call this method; it will let the counter go under 0.
|
|
1132
|
+
* This method does not actually remove a cloud variable.
|
|
1133
|
+
*/
|
|
1134
|
+
removeCloudVariable(): void;
|
|
1135
|
+
|
|
1136
|
+
createNewGlobalVariable(variableName: string): ScalarVariable;
|
|
1137
|
+
createNewGlobalVariable(variableName: string, variableId: string): ScalarVariable;
|
|
1138
|
+
createNewGlobalVariable(variableName: string, variableId: string, type: ''): ScalarVariable;
|
|
1139
|
+
createNewGlobalVariable(variableName: string, variableId: string, type: 'list'): ListVariable;
|
|
1140
|
+
createNewGlobalVariable(variableName: string, variableId: string, type: 'broadcast_msg'): BroadcastVariable;
|
|
1141
|
+
|
|
1142
|
+
getAllVarNamesOfType(variableType: VariableType): string[];
|
|
1143
|
+
|
|
1144
|
+
origin: string | null;
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Remove everything from the Runtime.
|
|
1148
|
+
*/
|
|
1149
|
+
dispose(): void;
|
|
1150
|
+
|
|
1151
|
+
requestTargetsUpdate(target: Target): void;
|
|
1152
|
+
|
|
1153
|
+
requestBlocksUpdate(): void;
|
|
1154
|
+
|
|
1155
|
+
requestToolboxExtensionsUpdate(): void;
|
|
1156
|
+
|
|
1157
|
+
emitProjectLoaded(): void;
|
|
1158
|
+
|
|
1159
|
+
emitProjectChanged(): void;
|
|
1160
|
+
|
|
1161
|
+
getEditingTarget(): Target | null;
|
|
1162
|
+
|
|
1163
|
+
setEditingTarget(target: Target): void;
|
|
1164
|
+
|
|
1165
|
+
scanForPeripheral(extensionID: string): void;
|
|
1166
|
+
|
|
1167
|
+
connectPeripheral(extensionID: string, peripheralId: number): void;
|
|
1168
|
+
|
|
1169
|
+
disconnectPeripheral(extensionID: string): void;
|
|
1170
|
+
|
|
1171
|
+
getPeripheralIsConnected(extensionID: string): boolean;
|
|
1172
|
+
|
|
1173
|
+
profiler: Profiler | null;
|
|
1174
|
+
enableProfiling(callback: (profilerFrame: ProfilerFrame) => void): void;
|
|
1175
|
+
disableProfiling(): void;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
interface VirtualMachineEventMap extends RuntimeAndVirtualMachineEventMap {
|
|
1179
|
+
TURBO_MODE_ON: [];
|
|
1180
|
+
|
|
1181
|
+
TURBO_MODE_OFF: [];
|
|
1182
|
+
|
|
1183
|
+
targetsUpdate: [{
|
|
1184
|
+
targetList: SerializedTarget[];
|
|
1185
|
+
editingTarget: string | null;
|
|
1186
|
+
}];
|
|
1187
|
+
|
|
1188
|
+
workspaceUpdate: [{
|
|
1189
|
+
xml: string;
|
|
1190
|
+
}];
|
|
1191
|
+
|
|
1192
|
+
playgroundData: [{
|
|
1193
|
+
blocks: Blocks;
|
|
1194
|
+
// Stringified JSON of Thread[]
|
|
1195
|
+
thread: string;
|
|
1196
|
+
}];
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
declare class VM extends EventEmitter<VM.VirtualMachineEventMap> {
|
|
1201
|
+
constructor();
|
|
1202
|
+
|
|
1203
|
+
runtime: VM.Runtime;
|
|
1204
|
+
|
|
1205
|
+
renderer: VM.IfRenderer<RenderWebGL, undefined>;
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* @see {VM.Runtime.attachRenderer}
|
|
1209
|
+
*/
|
|
1210
|
+
attachRenderer(renderer: RenderWebGL): void;
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* @see {VM.Runtime.attachAudioEngine}
|
|
1214
|
+
*/
|
|
1215
|
+
attachAudioEngine(audioEngine: AudioEngine): void;
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* @see {VM.Runtime.attachStorage}
|
|
1219
|
+
*/
|
|
1220
|
+
attachStorage(storage: ScratchStorage): void;
|
|
1221
|
+
|
|
1222
|
+
extensionManager: VM.ExtensionManager;
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* @see {VM.Runtime.start}
|
|
1226
|
+
*/
|
|
1227
|
+
start(): void;
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* @see {VM.Runtime.greenFlag}
|
|
1231
|
+
*/
|
|
1232
|
+
greenFlag(): void;
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Changes whether the runtime is in turbo mode or not.
|
|
1236
|
+
* Emits either TURBO_MODE_ON or TURBO_MODE_OFF.
|
|
1237
|
+
* @param turboMode whether turbo mode should be enabled
|
|
1238
|
+
*/
|
|
1239
|
+
setTurboMode(turboMode: boolean): void;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Changes whether the runtime is in "compatibility mode" (true by default)
|
|
1243
|
+
* Compatibility mode sets the runtime's framerate to 30 FPS. Disabling it sets the framerate to 60 FPS.
|
|
1244
|
+
* @param compatibilityMode
|
|
1245
|
+
*/
|
|
1246
|
+
setCompatibilityMode(compatibilityMode: boolean): void;
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* @see {Runtime.stopAll}
|
|
1250
|
+
*/
|
|
1251
|
+
stopAll(): void;
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Remove everything from the VM.
|
|
1255
|
+
*/
|
|
1256
|
+
clear(): void;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Load a project.
|
|
1260
|
+
* @param input Compressed sb, sb2, sb3 or sb2 project.json or sb3 project.json.
|
|
1261
|
+
*/
|
|
1262
|
+
loadProject(input: ArrayBufferView | ArrayBuffer | string | object): Promise<void>;
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Load a project usings its ID from scratch.mit.edu.
|
|
1266
|
+
*/
|
|
1267
|
+
downloadProjectId(id: string | number): Promise<void>;
|
|
1268
|
+
|
|
1269
|
+
deserializeProject(json: object, zip?: JSZip): Promise<void>;
|
|
1270
|
+
|
|
1271
|
+
installTargets(targets: VM.Target[], extensions: VM.ImportedExtensionsInfo, wholeProject: boolean): Promise<void>;
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* @deprecated
|
|
1275
|
+
* @see {loadProject}
|
|
1276
|
+
*/
|
|
1277
|
+
fromJSON(input: ArrayBufferView | ArrayBuffer | string | object): Promise<void>;
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* the project to a compressed sb3 file.
|
|
1281
|
+
*/
|
|
1282
|
+
saveProjectSb3(): Promise<Blob>;
|
|
1283
|
+
|
|
1284
|
+
toJSON(targetId?: string): string;
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* @see {VM.Runtime.getEditingTarget}
|
|
1288
|
+
*/
|
|
1289
|
+
editingTarget: VM.Target | null;
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Change the editing target. If a target with the ID doesn't exist, silently does nothing.
|
|
1293
|
+
* @see {VM.Runtime.setEditingTarget}
|
|
1294
|
+
*/
|
|
1295
|
+
setEditingTarget(targetId: string): void;
|
|
1296
|
+
|
|
1297
|
+
getTargetIdForDrawableId(drawableId: number): string | null;
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* Updates the value of a variable.
|
|
1301
|
+
* Returns true if the target and variable were successfully found and updated, otherwise null.
|
|
1302
|
+
*/
|
|
1303
|
+
setVariableValue(targetId: string, variableId: string, value: VM.VariableValue): boolean;
|
|
1304
|
+
|
|
1305
|
+
getVariableValue(targetId: string, variableId: string): VM.VariableValue | null;
|
|
1306
|
+
|
|
1307
|
+
assets: ScratchStorage.Asset[];
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Export a specific sprite to a compressed sprite3 file.
|
|
1311
|
+
* @param targetId The ID of the target
|
|
1312
|
+
*/
|
|
1313
|
+
exportSprite(targetId: string): Promise<Blob>;
|
|
1314
|
+
exportSprite(targetId: string, zipType: string): Promise<unknown>;
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* Gets the string representation of a costume.
|
|
1318
|
+
* For an SVG costume, returns the text.
|
|
1319
|
+
* For a PNG or JPG costume, returns a data URL.
|
|
1320
|
+
* If costume doesn't exist, returns null.
|
|
1321
|
+
*/
|
|
1322
|
+
getCostume(costumeIndex: number): string | null;
|
|
1323
|
+
|
|
1324
|
+
getSoundBuffer(soundIndex: number): AudioBuffer | null;
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Loads a sprite from a compressed .sprite2 or .sprite3 or JSON.
|
|
1328
|
+
*/
|
|
1329
|
+
addSprite(data: ArrayBufferView | ArrayBuffer | string | object): Promise<void>;
|
|
1330
|
+
|
|
1331
|
+
addCostume(md5ext: string, costume?: VM.Costume, targetId?: string, version?: 2): Promise<void>;
|
|
1332
|
+
|
|
1333
|
+
addCostumeFromLibrary(md5ext: string, costume: VM.Costume): Promise<void>;
|
|
1334
|
+
|
|
1335
|
+
addBackdrop(md5ext: string, costume?: VM.Costume): Promise<void>;
|
|
1336
|
+
|
|
1337
|
+
addSound(sound: VM.Sound, targetId?: string): Promise<void>;
|
|
1338
|
+
|
|
1339
|
+
duplicateSprite(targetId: string): Promise<void>;
|
|
1340
|
+
|
|
1341
|
+
duplicateCostume(costumeIndex: number): Promise<void>;
|
|
1342
|
+
|
|
1343
|
+
duplicateSound(soundIndex: number): Promise<void>;
|
|
1344
|
+
|
|
1345
|
+
updateSvg(costumeIndex: number, svg: string, rotationCenterX: number, rotationCenterY: number): void;
|
|
1346
|
+
|
|
1347
|
+
updateBitmap(costumeIndex: number, bitmap: ImageData, rotationCenterX: number, rotationCenterY: number, bitmapResolution: number): void;
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Update a sound.
|
|
1351
|
+
* @param soundIndex The index of the sound in the current sprite
|
|
1352
|
+
* @param buffer The new audio data
|
|
1353
|
+
* @param encodedWAV The data of an encoded WAV. If not provided, the new sound won't be saved if the project is exported.
|
|
1354
|
+
*/
|
|
1355
|
+
updateSoundBuffer(soundIndex: number, buffer: AudioBuffer, encodedWAV?: ArrayBuffer): void;
|
|
1356
|
+
|
|
1357
|
+
reorderTarget(targetId: string, newIndex: number): boolean;
|
|
1358
|
+
|
|
1359
|
+
reorderCostume(targetId: string, costumeIndex: number, newIndex: number): boolean;
|
|
1360
|
+
|
|
1361
|
+
reorderSound(targetId: string, soundIndex: number, newIndex: number): boolean;
|
|
1362
|
+
|
|
1363
|
+
renameSprite(targetId: string, newName: string): void;
|
|
1364
|
+
|
|
1365
|
+
renameCostume(costumeIndex: number, newName: string): void;
|
|
1366
|
+
|
|
1367
|
+
renameSound(soundIndex: number, newName: string): void;
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* Deletes the target with the given ID and any of its clones.
|
|
1371
|
+
* @returns If a sprite was deleted, returns a function to undo the deletion.
|
|
1372
|
+
*/
|
|
1373
|
+
deleteSprite(targetId: string): (() => void) | null;
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Deletes the costume at a given index int he editing target.
|
|
1377
|
+
* @returns If a costume was deleted, returns a function to undo the deletion.
|
|
1378
|
+
*/
|
|
1379
|
+
deleteCostume(costumeIndex: number): (() => void) | null;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Deletes the sound at a given index in the editing target.
|
|
1383
|
+
* @returns If a sound was deleted, returns a function to undo the deletion.
|
|
1384
|
+
*/
|
|
1385
|
+
deleteSound(soundIndex: number): (() => void) | null;
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Returns a promise that resolves when all required extensions have been imported.
|
|
1389
|
+
*/
|
|
1390
|
+
shareBlocksToTarget(blocks: VM.Block[], targetId: string, fromTargetId?: string): Promise<void>;
|
|
1391
|
+
|
|
1392
|
+
/**
|
|
1393
|
+
* Share a costume from the editing target to another target.
|
|
1394
|
+
*/
|
|
1395
|
+
shareCostumeToTarget(costumeIndex: number, targetId: string): Promise<void>;
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Share a sound from the editing target to another target.
|
|
1399
|
+
*/
|
|
1400
|
+
shareSoundToTarget(soundIndex: number, targetId: string): Promise<void>;
|
|
1401
|
+
|
|
1402
|
+
refreshWorkspace(): void;
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* Emit a targetsUpdate event about the current target information.
|
|
1406
|
+
* @param shouldTriggerProjectChange Whether a PROJECT_CHANGED event should be emitted. Defaults to true.
|
|
1407
|
+
*/
|
|
1408
|
+
emitTargetsUpdate(shouldTriggerProjectChange?: boolean): void;
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Emit a workspaceUpdate event.
|
|
1412
|
+
*/
|
|
1413
|
+
emitWorkspaceUpdate(): void;
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Post sprite info to the target that's being dragged, otherwise the editing target.
|
|
1417
|
+
* @see {VM.Target.postSpriteInfo}
|
|
1418
|
+
*/
|
|
1419
|
+
postSpriteInfo(spriteInfo: VM.PostedSpriteInfo): void;
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* The target that's currently being dragged, if any.
|
|
1423
|
+
*/
|
|
1424
|
+
_dragTarget: VM.Target | null;
|
|
1425
|
+
|
|
1426
|
+
startDrag(targetId: string): void;
|
|
1427
|
+
|
|
1428
|
+
stopDrag(targetId: string): void;
|
|
1429
|
+
|
|
1430
|
+
postIOData(device: 'cloud', data: VM.CloudData): void;
|
|
1431
|
+
postIOData(device: 'keyboard', data: VM.KeyboardData): void;
|
|
1432
|
+
postIOData(device: 'mouse', data: VM.MouseData): void;
|
|
1433
|
+
postIOData(device: 'mouseWheel', data: VM.MouseWheelData): void;
|
|
1434
|
+
postIOData(device: 'userData', data: VM.UserDataData): void;
|
|
1435
|
+
postIOData(device: 'video', data: VM.VideoData): void;
|
|
1436
|
+
|
|
1437
|
+
setVideoProvider(videoProvider: VM.VideoProvider): void;
|
|
1438
|
+
|
|
1439
|
+
setCloudProvider(cloudProvider: VM.CloudProvider): void;
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* @see {VM.Runtime.scanForPeripheral}
|
|
1443
|
+
*/
|
|
1444
|
+
scanForPeripheral(extensionID: string): void;
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* @see {VM.Runtime.connectPeripheral}
|
|
1448
|
+
*/
|
|
1449
|
+
connectPeripheral(extensionID: string, peripheralId: number): void;
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* @see {VM.Runtime.disconnectPeripheral}
|
|
1453
|
+
*/
|
|
1454
|
+
disconnectPeripheral(extensionID: string): void;
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* @see {VM.Runtime.getPeripheralIsConnected}
|
|
1458
|
+
*/
|
|
1459
|
+
getPeripheralIsConnected(extensionID: string): boolean;
|
|
1460
|
+
}
|