Use a global mirror state

This commit is contained in:
Corey Frang 2018-04-03 18:09:05 -04:00 committed by Michael "Z" Goddard
parent 90166dc732
commit 46b4ef4d80
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 12 additions and 5 deletions

View file

@ -117,7 +117,6 @@ class Scratch3VideoSensingBlocks {
const offset = time - this._lastUpdate; const offset = time - this._lastUpdate;
if (offset > Scratch3VideoSensingBlocks.INTERVAL) { if (offset > Scratch3VideoSensingBlocks.INTERVAL) {
const frame = this.runtime.ioDevices.video.getFrame({ const frame = this.runtime.ioDevices.video.getFrame({
mirror: true,
format: Video.FORMAT_IMAGE_DATA, format: Video.FORMAT_IMAGE_DATA,
dimensions: Scratch3VideoSensingBlocks.DIMENSIONS dimensions: Scratch3VideoSensingBlocks.DIMENSIONS
}); });
@ -340,12 +339,14 @@ class Scratch3VideoSensingBlocks {
} }
videoToggle (args) { videoToggle (args) {
// imported blocks have VIDEO_STATE "off", "on", "on-flipped" as opposed to the numerics?
const state = Number(args.VIDEO_STATE); const state = Number(args.VIDEO_STATE);
// 1 == off, 2 & 3 are on (3 is flipped) // 1 == off, 2 & 3 are on (3 is flipped)
if (state > 1) { if (args.VIDEO_STATE === 'off' || state === 1) {
this.runtime.ioDevices.video.requestVideo();
} else {
this.runtime.ioDevices.video.disableVideo(); this.runtime.ioDevices.video.disableVideo();
} else {
this.runtime.ioDevices.video.requestVideo();
this.runtime.ioDevices.video.mirror = args.VIDEO_STATE === 'on' || state === 2;
} }
} }

View file

@ -8,6 +8,12 @@ class Video {
*/ */
this.runtime = runtime; this.runtime = runtime;
/**
* Default value for mirrored frames.
* @type boolean
*/
this.mirror = true;
/** /**
* Cache frames for this many ms. * Cache frames for this many ms.
* @type number * @type number
@ -136,7 +142,7 @@ class Video {
*/ */
getFrame ({ getFrame ({
dimensions = Video.DIMENSIONS, dimensions = Video.DIMENSIONS,
mirror = true, mirror = this.mirror,
format = Video.FORMAT_IMAGE_DATA, format = Video.FORMAT_IMAGE_DATA,
cacheTimeout = this._frameCacheTimeout cacheTimeout = this._frameCacheTimeout
}) { }) {