diff --git a/extensions/PwLDev/vibration.js b/extensions/PwLDev/vibration.js index 9a907e2d4b..1ed99106b3 100644 --- a/extensions/PwLDev/vibration.js +++ b/extensions/PwLDev/vibration.js @@ -1,6 +1,6 @@ // Name: Vibration // ID: pwldevvibration -// Description: Control the device's vibration. Only works on Android. +// Description: Control the device's vibration. Only works on Chrome for Android. // By: PwLDev // License: MPL-2.0 @@ -22,7 +22,7 @@ blocks: [ { blockType: Scratch.BlockType.LABEL, - text: Scratch.translate("Only works on Android."), + text: Scratch.translate("Only works on Chrome for Android."), }, { opcode: "start", @@ -35,6 +35,17 @@ }, }, }, + { + opcode: "startPattern", + blockType: Scratch.BlockType.COMMAND, + text: Scratch.translate("play vibration pattern [PATTERN]"), + arguments: { + PATTERN: { + type: Scratch.ArgumentType.STRING, + defaultValue: "1, 0.5, 1, 0.5, 1", + }, + }, + }, { opcode: "stop", blockType: Scratch.BlockType.COMMAND, @@ -50,6 +61,17 @@ } } + startPattern(args) { + if (navigator.vibrate) { + const pattern = Scratch.Cast.toString(args.PATTERN) + .match(/[\w\-.]+/g) // Make into array + ?.map((val) => Scratch.Cast.toNumber(val) * 1000); // Convert to numbers in milliseconds + if (pattern) { + navigator.vibrate(pattern); + } + } + } + stop() { if (navigator.vibrate) { navigator.vibrate(0);