pxt-common-packages 10.3.8 → 10.3.9
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/libs/azureiot/built/debug/binary.js +461 -461
- package/libs/color/built/debug/binary.js +8 -8
- package/libs/color-sensor/built/debug/binary.js +8 -8
- package/libs/controller/built/debug/binary.js +15488 -15343
- package/libs/controller---none/built/debug/binary.js +15467 -15322
- package/libs/datalogger/built/debug/binary.js +63 -63
- package/libs/edge-connector/built/debug/binary.js +8 -8
- package/libs/esp32/built/debug/binary.js +462 -462
- package/libs/game/_locales/game-jsdoc-strings.json +8 -3
- package/libs/game/_locales/game-strings.json +10 -0
- package/libs/game/ask.ts +0 -1
- package/libs/game/built/debug/binary.js +16092 -15947
- package/libs/game/game.ts +194 -45
- package/libs/game/gameutil.ts +0 -2
- package/libs/game/info.ts +98 -36
- package/libs/game/ns.ts +5 -0
- package/libs/game/numberprompt.ts +0 -1
- package/libs/game/particleeffects.ts +30 -0
- package/libs/game/prompt.ts +0 -1
- package/libs/game/pxt.json +1 -0
- package/libs/game/textDialogs.ts +275 -40
- package/libs/lcd/built/debug/binary.js +8 -8
- package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
- package/libs/lora/built/debug/binary.js +8 -8
- package/libs/matrix-keypad/built/debug/binary.js +8 -8
- package/libs/mixer/instrument.ts +20 -1
- package/libs/mixer/melody.ts +13 -15
- package/libs/mixer/playable.ts +181 -0
- package/libs/mixer/pxt.json +1 -0
- package/libs/mixer/soundEffect.ts +19 -2
- package/libs/mqtt/built/debug/binary.js +176 -176
- package/libs/multiplayer/ns.ts +6 -0
- package/libs/multiplayer/player.ts +21 -3
- package/libs/multiplayer/pxt.json +1 -0
- package/libs/music/ns.ts +1 -1
- package/libs/net/built/debug/binary.js +176 -176
- package/libs/net-game/built/debug/binary.js +20403 -20258
- package/libs/palette/built/debug/binary.js +16086 -15941
- package/libs/pixel/built/debug/binary.js +8 -8
- package/libs/power/built/debug/binary.js +8 -8
- package/libs/proximity/built/debug/binary.js +8 -8
- package/libs/radio/built/debug/binary.js +8 -8
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- package/libs/rotary-encoder/built/debug/binary.js +8 -8
- package/libs/screen/built/debug/binary.js +50 -50
- package/libs/servo/built/debug/binary.js +8 -8
- package/libs/sprite-scaling/built/debug/binary.js +16091 -15946
- package/libs/storyboard/built/debug/binary.js +16091 -15946
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
namespace music {
|
|
2
|
+
export enum PlaybackMode {
|
|
3
|
+
//% block="until done"
|
|
4
|
+
UntilDone,
|
|
5
|
+
//% block="in background"
|
|
6
|
+
InBackground,
|
|
7
|
+
//% block="looping in background"
|
|
8
|
+
LoopingInBackground
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let stateStack: PlayableState[];
|
|
12
|
+
|
|
13
|
+
class PlayableState {
|
|
14
|
+
looping: Playable[];
|
|
15
|
+
constructor() {
|
|
16
|
+
this.looping = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
stopLooping() {
|
|
20
|
+
for (const p of this.looping) {
|
|
21
|
+
p.stopped = true;
|
|
22
|
+
}
|
|
23
|
+
this.looping = [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function state() {
|
|
28
|
+
_init();
|
|
29
|
+
return stateStack[stateStack.length - 1];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _init() {
|
|
33
|
+
if (stateStack) return;
|
|
34
|
+
stateStack = [new PlayableState()];
|
|
35
|
+
|
|
36
|
+
game.addScenePushHandler(() => {
|
|
37
|
+
stateStack.push(new PlayableState());
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
game.addScenePopHandler(() => {
|
|
41
|
+
stateStack.pop();
|
|
42
|
+
if (stateStack.length === 0) stateStack.push(new PlayableState());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class Playable {
|
|
47
|
+
stopped: boolean;
|
|
48
|
+
constructor() {
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
play(playbackMode: PlaybackMode) {
|
|
53
|
+
// subclass
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
loop() {
|
|
57
|
+
state().looping.push(this);
|
|
58
|
+
this.stopped = false;
|
|
59
|
+
|
|
60
|
+
control.runInParallel(() => {
|
|
61
|
+
while (!this.stopped) {
|
|
62
|
+
this.play(PlaybackMode.UntilDone);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class MelodyPlayable extends Playable {
|
|
69
|
+
constructor(public melody: Melody) {
|
|
70
|
+
super();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
play(playbackMode: PlaybackMode) {
|
|
74
|
+
if (playbackMode === PlaybackMode.InBackground) {
|
|
75
|
+
this.melody.play(music.volume());
|
|
76
|
+
}
|
|
77
|
+
else if (playbackMode === PlaybackMode.UntilDone) {
|
|
78
|
+
this.melody.playUntilDone(music.volume());
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.melody.loop(music.volume());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export class TonePlayable extends Playable {
|
|
87
|
+
constructor(public pitch: number, public duration: number) {
|
|
88
|
+
super();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
play(playbackMode: PlaybackMode) {
|
|
92
|
+
if (playbackMode === PlaybackMode.InBackground) {
|
|
93
|
+
control.runInParallel(() => music.playTone(this.pitch, this.duration));
|
|
94
|
+
}
|
|
95
|
+
else if (playbackMode === PlaybackMode.UntilDone) {
|
|
96
|
+
music.playTone(this.pitch, this.duration);
|
|
97
|
+
if (this.duration > 2000) {
|
|
98
|
+
pause(this.duration);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.loop();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//% blockId="music_playable_play"
|
|
108
|
+
//% block="play $toPlay $playbackMode"
|
|
109
|
+
//% toPlay.shadow=music_melody_playable
|
|
110
|
+
//% group="Sounds"
|
|
111
|
+
export function play(toPlay: Playable, playbackMode: PlaybackMode) {
|
|
112
|
+
toPlay.play(playbackMode);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//% blockId="music_melody_playable"
|
|
116
|
+
//% block="sound $melody"
|
|
117
|
+
//% toolboxParent=music_playable_play
|
|
118
|
+
//% toolboxParentArgument=toPlay
|
|
119
|
+
//% group="Sounds"
|
|
120
|
+
//% duplicateShadowOnDrag
|
|
121
|
+
//% blockHidden
|
|
122
|
+
export function melodyPlayable(melody: Melody): Playable {
|
|
123
|
+
return new MelodyPlayable(melody);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
//% blockId="music_string_playable"
|
|
128
|
+
//% block="melody $melody at tempo $tempo|(bpm)"
|
|
129
|
+
//% toolboxParent=music_playable_play
|
|
130
|
+
//% toolboxParentArgument=toPlay
|
|
131
|
+
//% weight=85 blockGap=8
|
|
132
|
+
//% help=music/melody-editor
|
|
133
|
+
//% group="Songs"
|
|
134
|
+
//% duplicateShadowOnDrag
|
|
135
|
+
//% melody.shadow=melody_editor
|
|
136
|
+
//% tempo.min=40 tempo.max=500
|
|
137
|
+
//% tempo.defl=120
|
|
138
|
+
export function stringPlayable(melody: string, tempo: number): Playable {
|
|
139
|
+
let notes: string[] = melody.split(" ").filter(n => !!n);
|
|
140
|
+
let formattedMelody = "";
|
|
141
|
+
let newOctave = false;
|
|
142
|
+
|
|
143
|
+
// build melody string, replace '-' with 'R' and add tempo
|
|
144
|
+
// creates format like "C5-174 B4 A G F E D C "
|
|
145
|
+
for (let i = 0; i < notes.length; i++) {
|
|
146
|
+
if (notes[i] === "-") {
|
|
147
|
+
notes[i] = "R";
|
|
148
|
+
} else if (notes[i] === "C5") {
|
|
149
|
+
newOctave = true;
|
|
150
|
+
} else if (newOctave) { // change the octave if necesary
|
|
151
|
+
notes[i] += "4";
|
|
152
|
+
newOctave = false;
|
|
153
|
+
}
|
|
154
|
+
// add tempo after first note
|
|
155
|
+
if (i == 0) {
|
|
156
|
+
formattedMelody += notes[i] + "-" + tempo + " ";
|
|
157
|
+
} else {
|
|
158
|
+
formattedMelody += notes[i] + " ";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return new MelodyPlayable(new Melody(formattedMelody));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//% blockId="music_tone_playable"
|
|
166
|
+
//% block="tone $note for $duration"
|
|
167
|
+
//% toolboxParent=music_playable_play
|
|
168
|
+
//% toolboxParentArgument=toPlay
|
|
169
|
+
//% group="Tone"
|
|
170
|
+
//% duplicateShadowOnDrag
|
|
171
|
+
//% note.shadow=device_note
|
|
172
|
+
//% duration.shadow=device_beat
|
|
173
|
+
//% parts="headphone"
|
|
174
|
+
export function tonePlayable(note: number, duration: number): Playable {
|
|
175
|
+
return new TonePlayable(note, duration);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function _stopPlayables() {
|
|
179
|
+
state().stopLooping();
|
|
180
|
+
}
|
|
181
|
+
}
|
package/libs/mixer/pxt.json
CHANGED
|
@@ -39,7 +39,7 @@ enum SoundExpressionPlayMode {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
namespace music {
|
|
42
|
-
export class SoundEffect {
|
|
42
|
+
export class SoundEffect extends Playable {
|
|
43
43
|
waveShape: WaveShape;
|
|
44
44
|
startFrequency: number;
|
|
45
45
|
endFrequency: number;
|
|
@@ -50,6 +50,7 @@ namespace music {
|
|
|
50
50
|
interpolation: InterpolationCurve;
|
|
51
51
|
|
|
52
52
|
constructor() {
|
|
53
|
+
super();
|
|
53
54
|
this.waveShape = WaveShape.Sine;
|
|
54
55
|
this.startFrequency = 5000;
|
|
55
56
|
this.endFrequency = 1;
|
|
@@ -77,6 +78,20 @@ namespace music {
|
|
|
77
78
|
volume
|
|
78
79
|
);
|
|
79
80
|
}
|
|
81
|
+
|
|
82
|
+
play(playbackMode: PlaybackMode) {
|
|
83
|
+
const toPlay = this.toBuffer(music.volume());
|
|
84
|
+
if (playbackMode === PlaybackMode.InBackground) {
|
|
85
|
+
queuePlayInstructions(0, toPlay);
|
|
86
|
+
}
|
|
87
|
+
else if (playbackMode === PlaybackMode.UntilDone) {
|
|
88
|
+
queuePlayInstructions(0, toPlay);
|
|
89
|
+
pause(this.duration)
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.loop();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
|
|
@@ -87,11 +102,11 @@ namespace music {
|
|
|
87
102
|
*/
|
|
88
103
|
//% blockId=soundExpression_playSoundEffect
|
|
89
104
|
//% block="play sound $sound $mode"
|
|
90
|
-
//% sound.shadow=soundExpression_createSoundEffect
|
|
91
105
|
//% weight=30
|
|
92
106
|
//% help=music/play-sound-effect
|
|
93
107
|
//% blockGap=8
|
|
94
108
|
//% group="Sounds"
|
|
109
|
+
//% deprecated=1
|
|
95
110
|
export function playSoundEffect(sound: SoundEffect, mode: SoundExpressionPlayMode) {
|
|
96
111
|
const toPlay = sound.toBuffer(music.volume());
|
|
97
112
|
|
|
@@ -139,6 +154,8 @@ namespace music {
|
|
|
139
154
|
//% inlineInputMode="variable"
|
|
140
155
|
//% inlineInputModeLimit=3
|
|
141
156
|
//% expandableArgumentBreaks="3,5"
|
|
157
|
+
//% toolboxParent=music_playable_play
|
|
158
|
+
//% toolboxParentArgument=toPlay
|
|
142
159
|
//% weight=20
|
|
143
160
|
//% group="Sounds"
|
|
144
161
|
export function createSoundEffect(waveShape: WaveShape, startFrequency: number, endFrequency: number, startVolume: number, endVolume: number, duration: number, effect: SoundExpressionEffect, interpolation: InterpolationCurve): SoundEffect {
|