@turbowarp/types 0.0.4 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/types",
3
- "version": "0.0.4",
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
@@ -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;
@@ -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 {
@@ -817,6 +818,8 @@ declare namespace VM {
817
818
  _isDown: boolean;
818
819
  getIsDown(): boolean;
819
820
  postData(data: MouseData): void;
821
+ _activateClickHats(target: Target): void;
822
+ _pickTarget(x: number, y: number): Target;
820
823
  }
821
824
 
822
825
  interface MouseWheelData {
@@ -1014,6 +1017,13 @@ declare namespace VM {
1014
1017
  */
1015
1018
  _step(): void;
1016
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
+
1017
1027
  renderer: IfRenderer<RenderWebGL, undefined>;
1018
1028
 
1019
1029
  attachRenderer(renderer: RenderWebGL): void;
@@ -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
+ }