Add VideoState enum to Scratch3VideoSensingBlocks

This commit is contained in:
Michael "Z" Goddard 2018-04-06 13:11:10 -04:00
parent fe7aa8a78f
commit d4037808a7
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 50 additions and 16 deletions

View file

@ -7,6 +7,22 @@ const Video = require('../../io/video');
const VideoMotion = require('./library'); const VideoMotion = require('./library');
/**
* States the video sensing activity can be set to.
* @readonly
* @enum {string}
*/
const VideoState = {
/** Video turned off. */
OFF: 'off',
/** Video turned on with default y axis mirroring. */
ON: 'on',
/** Video turned on without default y axis mirroring. */
ON_FLIPPED: 'on-flipped'
};
/** /**
* Class for the motion-related blocks in Scratch 3.0 * Class for the motion-related blocks in Scratch 3.0
* @param {Runtime} runtime - the runtime instantiating this block package. * @param {Runtime} runtime - the runtime instantiating this block package.
@ -140,7 +156,7 @@ class Scratch3VideoSensingBlocks {
return info.map((entry, index) => { return info.map((entry, index) => {
const obj = {}; const obj = {};
obj.text = entry.name; obj.text = entry.name;
obj.value = String(index + 1); obj.value = entry.value || String(index + 1);
return obj; return obj;
}); });
} }
@ -213,11 +229,35 @@ class Scratch3VideoSensingBlocks {
return 2; return 2;
} }
/**
* States the video sensing activity can be set to.
* @readonly
* @enum {string}
*/
static get VideoState () {
return VideoState;
}
/**
* An array of info on video state options for the "turn video [STATE]" block.
* @type {object[]} an array of objects
* @param {string} name - the translatable name to display in the video state menu
* @param {string} value - the serializable value stored in the block
*/
get VIDEO_STATE_INFO () { get VIDEO_STATE_INFO () {
return [ return [
{name: 'off'}, {
{name: 'on'}, name: 'off',
{name: 'on-flipped'} value: VideoState.OFF
},
{
name: 'on',
value: VideoState.ON
},
{
name: 'on flipped',
value: VideoState.ON_FLIPPED
}
]; ];
} }
@ -266,7 +306,7 @@ class Scratch3VideoSensingBlocks {
VIDEO_STATE: { VIDEO_STATE: {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
menu: 'VIDEO_STATE', menu: 'VIDEO_STATE',
defaultValue: 1 defaultValue: VideoState.ON
} }
} }
}, },
@ -339,13 +379,13 @@ class Scratch3VideoSensingBlocks {
} }
videoToggle (args) { videoToggle (args) {
const state = Number(args.VIDEO_STATE); const state = args.VIDEO_STATE;
// 1 == off, 2 & 3 are on (3 is flipped) if (state === VideoState.OFF) {
if (state === 1) {
this.runtime.ioDevices.video.disableVideo(); this.runtime.ioDevices.video.disableVideo();
} else { } else {
this.runtime.ioDevices.video.enableVideo(); this.runtime.ioDevices.video.enableVideo();
this.runtime.ioDevices.video.mirror = state === 2; // Mirror if state is ON. Do not mirror if state is ON_FLIPPED.
this.runtime.ioDevices.video.mirror = state === VideoState.ON;
} }
} }

View file

@ -629,13 +629,7 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension
} }
} else if (expectedArg.inputOp === 'videoSensing.menu.VIDEO_STATE') { } else if (expectedArg.inputOp === 'videoSensing.menu.VIDEO_STATE') {
if (shadowObscured) { if (shadowObscured) {
fieldValue = 2; fieldValue = 'on';
} else if (fieldValue === 'off') {
fieldValue = 1;
} else if (fieldValue === 'on') {
fieldValue = 2;
} else if (fieldValue === 'on-flipped') {
fieldValue = 3;
} }
} else if (shadowObscured) { } else if (shadowObscured) {
// Filled drop-down menu. // Filled drop-down menu.