@turbowarp/types 0.0.3 → 0.0.5

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.
@@ -0,0 +1,9 @@
1
+ # Contributing
2
+
3
+ Our goal is to document all the APIs exposed by Scratch. We accept any contributions that work towards that goal.
4
+
5
+ Even if you aren't able to write types, please open issues to report missing or incorrect types.
6
+
7
+ In terms of code style, we aren't super picky. Just keep it consistent with whatever is already there.
8
+
9
+ For very complex types, please add a small test case in the `tests` directory. Presumably you already wrote some test code while writing the types, so just don't delete that once you're done.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/types",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Type definitions for the Scratch VM and editor",
5
5
  "keywords": [
6
6
  "scratch"
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -15,3 +15,11 @@ audioEngine.decodeSoundPlayer({
15
15
  });
16
16
  return player.finished();
17
17
  });
18
+
19
+ declare const pitchEffect: AudioEngine.PitchEffect;
20
+ pitchEffect.ratio as number
21
+ pitchEffect.updatePlayers([]);
22
+
23
+ declare const soundPlayer: AudioEngine.SoundPlayer;
24
+
25
+ new audioEngine.effects[0](audioEngine, soundPlayer, pitchEffect);
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ (function(Scratch) {
2
+ 'use strict';
3
+
4
+ class Fetch {
5
+ getInfo () {
6
+ return {
7
+ id: 'fetch',
8
+ name: 'Fetch',
9
+ blocks: [
10
+ {
11
+ opcode: 'get',
12
+ blockType: Scratch.BlockType.REPORTER,
13
+ text: 'GET [URL]',
14
+ arguments: {
15
+ URL: {
16
+ type: Scratch.ArgumentType.STRING,
17
+ defaultValue: 'https://extensions.turbowarp.org/hello.txt'
18
+ }
19
+ }
20
+ }
21
+ ]
22
+ };
23
+ }
24
+
25
+ /**
26
+ * @param {{URL: string;}} args
27
+ */
28
+ get (args) {
29
+ return fetch(args.URL)
30
+ .then(r => r.text())
31
+ .catch(() => '');
32
+ }
33
+ }
34
+
35
+ Scratch.extensions.register(new Fetch());
36
+ })(Scratch);
@@ -53,3 +53,11 @@ if (target) {
53
53
  const audioEngine = new AudioEngine();
54
54
  vm.attachAudioEngine(audioEngine);
55
55
  audioEngine.audioContext.suspend();
56
+
57
+ vm.setTurboMode(true);
58
+ vm.runtime.turboMode as boolean
59
+ vm.setCompatibilityMode(true);
60
+ vm.runtime.compatibilityMode as boolean
61
+
62
+ const costume = vm.runtime.getTargetForStage()?.getCostumes()?.[0];
63
+ costume?.skinId as number;
@@ -0,0 +1,29 @@
1
+ (function () {
2
+ const ext = {};
3
+
4
+ ext._getStatus = () => ({
5
+ status: 2,
6
+ msg: 'Ready'
7
+ });
8
+
9
+ ext.testReporter = () => Math.random();
10
+
11
+ /**
12
+ * @param {number} delay
13
+ * @param {function} callback
14
+ */
15
+ ext.testReporterWait = (delay, callback) => {
16
+ setTimeout(() => {
17
+ callback(Math.random())
18
+ }, delay * 1000);
19
+ };
20
+
21
+ var descriptor = {
22
+ blocks: [
23
+ ['r', 'test reporter', 'testReporter'],
24
+ ['R', 'test reporter 2 %n', 'testReporterWait', '1'],
25
+ ],
26
+ };
27
+
28
+ ScratchExtensions.register('ScratchX Test', descriptor, ext);
29
+ }());
File without changes
File without changes
package/types/paper.d.ts CHANGED
@@ -9,4 +9,9 @@ declare namespace Paper {
9
9
  interface Matrix {
10
10
  // TODO
11
11
  }
12
+
13
+ interface Tool {
14
+ // TODO
15
+ activate(): void;
16
+ }
12
17
  }
@@ -19,10 +19,10 @@ declare namespace AudioEngine {
19
19
  getLoudness(): number;
20
20
  }
21
21
 
22
- interface Effect {
22
+ interface AbstractEffect {
23
23
  audioEngine: AudioEngine;
24
24
  audioPlayer: SoundPlayer;
25
- lastEffect: Effect;
25
+ lastEffect: AbstractEffect;
26
26
  value: number;
27
27
  initialized: boolean;
28
28
  initialize(): void;
@@ -41,11 +41,36 @@ declare namespace AudioEngine {
41
41
  dispose(): void;
42
42
  }
43
43
 
44
+ interface PitchEffect extends AbstractEffect {
45
+ get name(): 'pitch';
46
+ ratio: number;
47
+ getRatio(val: number): number;
48
+ updatePlayer(soundPlayer: SoundPlayer): void;
49
+ updatePlayers(soundPlayers: Record<string, SoundPlayer> | SoundPlayer[]): void;
50
+ }
51
+
52
+ interface PanEffect extends AbstractEffect {
53
+ get name(): 'pan';
54
+ leftGain: GainNode;
55
+ rightGain: GainNode;
56
+ channelMerger: ChannelMergerNode;
57
+ }
58
+
59
+ interface VolumeEffect extends AbstractEffect {
60
+ get name(): 'volume';
61
+ }
62
+
63
+ type Effect = PitchEffect | PanEffect | VolumeEffect;
64
+
65
+ interface EffectConstructor {
66
+ new(audioEngine: AudioEngine, soundPlayer: SoundPlayer, lastEffect: Effect | null): Effect;
67
+ }
68
+
44
69
  interface EffectChain {
45
70
  audioEngine: AudioEngine;
46
71
  inputNode: GainNode;
47
72
  getInputNode(): GainNode;
48
- effects: Effect[];
73
+ effects: EffectConstructor[];
49
74
  _effects: Effect[];
50
75
  firstEffect: Effect;
51
76
  lastEffect: Effect;
@@ -86,14 +111,32 @@ declare namespace AudioEngine {
86
111
  stopImmediately(): void;
87
112
  finished(): Promise<void>;
88
113
  setPlaybackRate(playbackRate: number): void;
114
+ take(): SoundPlayer;
89
115
  }
90
116
 
91
117
  interface SoundBank {
92
118
  audioEngine: AudioEngine;
119
+
120
+ /**
121
+ * Maps sound ID to its sound player.
122
+ */
93
123
  soundPlayers: Record<string, SoundPlayer>;
94
- playerTargets: Record<string, Target>;
95
- soundEffects: Record<string, EffectChain>;
124
+
125
+ /**
126
+ * Maps sound IDs to the target they were most recently been started by.
127
+ */
128
+ playerTargets: Map<string, Target>;
129
+
130
+ /**
131
+ * Maps sound IDs to their effect chain.
132
+ */
133
+ soundEffects: Map<string, EffectChain>;
134
+
135
+ /**
136
+ * Original effect chain cloned for each sound.
137
+ */
96
138
  effectChainPrime: EffectChain;
139
+
97
140
  addSoundPlayer(soundPlayer: SoundPlayer): void;
98
141
  getSoundPlayer(soundId: string): SoundPlayer | undefined;
99
142
  getSoundEffects(soundId: string): EffectChain;
@@ -128,7 +171,8 @@ declare class AudioEngine {
128
171
  */
129
172
  getLoudness(): number;
130
173
 
131
- effects: AudioEngine.Effect[];
174
+ effects: AudioEngine.EffectConstructor[];
175
+
132
176
  get EFFECT_NAMES(): Record<string, string>;
133
177
  get DECAY_DURATION(): number;
134
178
  get DECAY_WAIT(): number;
@@ -452,73 +452,73 @@ declare namespace ScratchGUI {
452
452
  {
453
453
  type: 'scratch-gui/project-state/DONE_CREATING_COPY';
454
454
  projectId: string;
455
- } |
455
+ } |
456
456
  {
457
457
  type: 'scratch-gui/project-state/DONE_CREATING_NEW';
458
458
  projectId: string;
459
- } |
459
+ } |
460
460
  {
461
461
  type: 'scratch-gui/project-state/DONE_FETCHING_DEFAULT';
462
462
  projectData: ProjectData;
463
- } |
463
+ } |
464
464
  {
465
465
  type: 'scratch-gui/project-state/DONE_FETCHING_WITH_ID';
466
466
  projectData: ProjectData;
467
- } |
467
+ } |
468
468
  {
469
469
  type: 'scratch-gui/project-state/DONE_LOADING_VM_TO_SAVE';
470
- } |
470
+ } |
471
471
  {
472
472
  type: 'scratch-gui/project-state/DONE_LOADING_VM_WITH_ID';
473
- } |
473
+ } |
474
474
  {
475
475
  type: 'scratch-gui/project-state/DONE_LOADING_VM_WITHOUT_ID';
476
- } |
476
+ } |
477
477
  {
478
478
  type: 'scratch-gui/project-state/DONE_REMIXING';
479
479
  projectId: string;
480
- } |
480
+ } |
481
481
  {
482
482
  type: 'scratch-gui/project-state/DONE_UPDATING';
483
- } |
483
+ } |
484
484
  {
485
485
  type: 'scratch-gui/project-state/DONE_UPDATING_BEFORE_COPY';
486
- } |
486
+ } |
487
487
  {
488
488
  type: 'scratch-gui/project-state/DONE_UPDATING_BEFORE_NEW';
489
- } |
489
+ } |
490
490
  {
491
491
  type: 'scratch-gui/project-state/RETURN_TO_SHOWING';
492
- } |
492
+ } |
493
493
  {
494
494
  type: 'scratch-gui/project-state/SET_PROJECT_ID';
495
495
  projectId: string;
496
- } |
496
+ } |
497
497
  {
498
498
  type: 'scratch-gui/project-state/START_AUTO_UPDATING';
499
- } |
499
+ } |
500
500
  {
501
501
  type: 'scratch-gui/project-state/START_CREATING_NEW';
502
- } |
502
+ } |
503
503
  {
504
504
  type: 'scratch-gui/project-state/START_ERROR';
505
505
  error: unknown;
506
- } |
506
+ } |
507
507
  {
508
508
  type: 'scratch-gui/project-state/START_FETCHING_NEW';
509
- } |
509
+ } |
510
510
  {
511
511
  type: 'scratch-gui/project-state/START_LOADING_VM_FILE_UPLOAD';
512
- } |
512
+ } |
513
513
  {
514
514
  type: 'scratch-gui/project-state/START_MANUAL_UPDATING';
515
- } |
515
+ } |
516
516
  {
517
517
  type: 'scratch-gui/project-state/START_REMIXING';
518
- } |
518
+ } |
519
519
  {
520
520
  type: 'scratch-gui/project-state/START_UPDATING_BEFORE_CREATING_COPY';
521
- } |
521
+ } |
522
522
  {
523
523
  type: 'scratch-gui/project-state/START_UPDATING_BEFORE_CREATING_NEW';
524
524
  } |
@@ -171,7 +171,7 @@ declare namespace ScratchPaint {
171
171
  {
172
172
  type: 'scratch-paint/eye-dropper/ACTIVATE_COLOR_PICKER';
173
173
  callback: ScratchPaintState['color']['eyeDropper']['callback'];
174
- previousMode: Mode;
174
+ previousMode: Paper.Tool;
175
175
  } |
176
176
  {
177
177
  type: 'scratch-paint/eye-dropper/DEACTIVATE_COLOR_PICKER';
@@ -0,0 +1,133 @@
1
+ /// <reference path="./scratch-vm.d.ts" />
2
+ /// <reference path="./scratch-render.d.ts" />
3
+
4
+ declare namespace Scratch {
5
+ namespace ArgumentType {
6
+ /** @deprecated not tested -- do not rely on yet */
7
+ const ANGLE: 'angle';
8
+ const BOOLEAN: 'Boolean';
9
+ /** @deprecated not tested -- do not rely on yet */
10
+ const COLOR: 'color';
11
+ const NUMBER: 'number';
12
+ const STRING: 'string';
13
+ /** @deprecated not tested -- do not rely on yet */
14
+ const MATRIX: 'matrix';
15
+ /** @deprecated not tested -- do not rely on yet */
16
+ const NOTE: 'note';
17
+ /** @deprecated not tested -- do not rely on yet */
18
+ const IMAGE: 'image';
19
+ }
20
+ type ArgumentType = (typeof ArgumentType)[keyof typeof ArgumentType];
21
+
22
+ namespace BlockType {
23
+ // The B in Boolean is supposed to be capitalized
24
+ const BOOLEAN: 'Boolean';
25
+ /** @deprecated not tested -- do not rely on yet */
26
+ const BUTTON: 'button';
27
+ const COMMAND: 'command';
28
+ /** @deprecated not tested -- do not rely on yet */
29
+ const CONDITIONAL: 'conditional';
30
+ const EVENT: 'event';
31
+ const HAT: 'hat';
32
+ /** @deprecated not tested -- do not rely on yet */
33
+ const LOOP: 'loop';
34
+ const REPORTER: 'reporter';
35
+ }
36
+ type BlockType = (typeof BlockType)[keyof typeof BlockType];
37
+
38
+ namespace TargetType {
39
+ const SPRITE: 'sprite';
40
+ const STAGE: 'stage';
41
+ }
42
+ type TargetType = (typeof TargetType)[keyof typeof TargetType];
43
+
44
+ /**
45
+ * scratch-vm instance. Only for unsandboxed extensions.
46
+ */
47
+ const vm: VM;
48
+
49
+ /**
50
+ * scratch-render instance. Only for unsandboxed extensions.
51
+ */
52
+ const renderer: RenderWebGL;
53
+
54
+ /**
55
+ * Technically this can be a translatable object, but in reality it will probably just be
56
+ * a string here.
57
+ */
58
+ type FormattableString = string;
59
+
60
+ interface ExtensionArgumentInfo {
61
+ type: ArgumentType;
62
+ defaultValue?: string | number;
63
+ menu?: string;
64
+ }
65
+
66
+ interface ExtensionBlock {
67
+ opcode: string;
68
+ blockType: BlockType;
69
+ text: FormattableString;
70
+ arguments?: Record<string, ExtensionArgumentInfo>;
71
+ // TODO: documentation mentions func, filter, branchCount, terminal, blockAllThreads
72
+ }
73
+
74
+ interface ExtensionMenu {
75
+ acceptReporters?: boolean;
76
+ items: Array<string | {
77
+ text: string;
78
+ value: string;
79
+ }>;
80
+ }
81
+
82
+ interface ExtensionInfo {
83
+ id: string;
84
+
85
+ /**
86
+ * Defaults to ID if not specified.
87
+ */
88
+ name?: FormattableString;
89
+
90
+ /**
91
+ * Should be a hex color code.
92
+ */
93
+ color1?: string;
94
+
95
+ /**
96
+ * Should be a hex color code.
97
+ */
98
+ color2?: string;
99
+
100
+ /**
101
+ * Should be a hex color code.
102
+ */
103
+ color3?: string;
104
+
105
+ /**
106
+ * Should be a data: URI
107
+ */
108
+ menuIconURI?: string;
109
+
110
+ /**
111
+ * Should be a data: URI
112
+ */
113
+ blockIconURI?: string;
114
+
115
+ docsURI?: string;
116
+
117
+ blocks: (ExtensionBlock | string)[];
118
+ menus?: Record<string, ExtensionMenu>;
119
+ }
120
+
121
+ interface Extension {
122
+ getInfo(): ExtensionInfo;
123
+ }
124
+
125
+ namespace extensions {
126
+ function register(extensionObject: Extension): void;
127
+
128
+ /**
129
+ * True if the extension is running unsandboxed.
130
+ */
131
+ const unsandboxed: boolean;
132
+ }
133
+ }
@@ -60,6 +60,7 @@ declare namespace VM {
60
60
  rotationCenterX: number;
61
61
  rotationCenterY: number;
62
62
  size: [number, number];
63
+ skinId: number;
63
64
  }
64
65
 
65
66
  interface Sound extends BaseAsset {
@@ -76,6 +77,8 @@ declare namespace VM {
76
77
  name: string;
77
78
  costumes: Costume[];
78
79
  sounds: Sound[];
80
+ clones: RenderedTarget[];
81
+ soundBank: AudioEngine.SoundBank | null;
79
82
  }
80
83
 
81
84
  interface Field {
@@ -297,6 +300,8 @@ declare namespace VM {
297
300
 
298
301
  comments: Record<string, Comment>;
299
302
 
303
+ createComment(id: string, blockId: string, text: string, x: number, y: number, width: number, height: number, minimized?: boolean): void;
304
+
300
305
  /**
301
306
  * Called by runtime when the green flag is pressed.
302
307
  */
@@ -813,6 +818,8 @@ declare namespace VM {
813
818
  _isDown: boolean;
814
819
  getIsDown(): boolean;
815
820
  postData(data: MouseData): void;
821
+ _activateClickHats(target: Target): void;
822
+ _pickTarget(x: number, y: number): Target;
816
823
  }
817
824
 
818
825
  interface MouseWheelData {
@@ -990,6 +997,11 @@ declare namespace VM {
990
997
  */
991
998
  start(): void;
992
999
 
1000
+ /**
1001
+ * Stop all timers.
1002
+ */
1003
+ quit(): void;
1004
+
993
1005
  /**
994
1006
  * Start "when green flag pressed" scripts.
995
1007
  */
@@ -1005,6 +1017,13 @@ declare namespace VM {
1005
1017
  */
1006
1018
  _step(): void;
1007
1019
 
1020
+ turboMode: boolean;
1021
+
1022
+ /**
1023
+ * If true, the runtime is running at 60 FPS. If false, the runtime is running at 30 FPS.
1024
+ */
1025
+ compatibilityMode: boolean;
1026
+
1008
1027
  renderer: IfRenderer<RenderWebGL, undefined>;
1009
1028
 
1010
1029
  attachRenderer(renderer: RenderWebGL): void;
@@ -1297,6 +1316,11 @@ declare class VM extends EventEmitter<VM.VirtualMachineEventMap> {
1297
1316
  */
1298
1317
  start(): void;
1299
1318
 
1319
+ /**
1320
+ * @see {VM.Runtime.quit}
1321
+ */
1322
+ quit(): void;
1323
+
1300
1324
  /**
1301
1325
  * @see {VM.Runtime.greenFlag}
1302
1326
  */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @deprecated ScratchX is deprecated. Do not use in new extensions.
3
+ */
4
+ declare namespace ScratchExtensions {
5
+ /**
6
+ * @deprecated ScratchX is deprecated. Do not use in new extensions.
7
+ */
8
+ function register(name: string, descriptor: unknown, extension: unknown): void;
9
+ }