From 431d4bd66b72e4860b42d3bd40dddc9f0f23aa90 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Wed, 6 Jun 2018 13:39:23 -0400 Subject: [PATCH 1/3] Add when touching hat --- src/blocks/scratch3_event.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index ba496a172..631546a9a 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -24,6 +24,7 @@ class Scratch3EventBlocks { */ getPrimitives () { return { + event_whentouchingobject: this.touchingObject, event_broadcast: this.broadcast, event_broadcastandwait: this.broadcastAndWait, event_whengreaterthan: this.hatGreaterThanPredicate @@ -41,6 +42,10 @@ class Scratch3EventBlocks { event_whenthisspriteclicked: { restartExistingThreads: true }, + event_whentouchingobject: { + restartExistingThreads: false, + edgeActivated: true + }, event_whenstageclicked: { restartExistingThreads: true }, @@ -57,6 +62,18 @@ class Scratch3EventBlocks { }; } + touchingObject (args, util) { + const requestedObject = args.TOUCHINGOBJECTMENU; + if (requestedObject === '_mouse_') { + const mouseX = util.ioQuery('mouse', 'getClientX'); + const mouseY = util.ioQuery('mouse', 'getClientY'); + return util.target.isTouchingPoint(mouseX, mouseY); + } else if (requestedObject === '_edge_') { + return util.target.isTouchingEdge(); + } + return util.target.isTouchingSprite(requestedObject); + } + hatGreaterThanPredicate (args, util) { const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase(); const value = Cast.toNumber(args.VALUE); From 1a72512a620da1b99669027de6d8b79ed9fd2883 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Wed, 6 Jun 2018 16:34:58 -0400 Subject: [PATCH 2/3] Moving touchingObject into rendered target --- src/blocks/scratch3_event.js | 10 +--------- src/blocks/scratch3_sensing.js | 11 +---------- src/sprites/rendered-target.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index 631546a9a..8e3a302cc 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -63,15 +63,7 @@ class Scratch3EventBlocks { } touchingObject (args, util) { - const requestedObject = args.TOUCHINGOBJECTMENU; - if (requestedObject === '_mouse_') { - const mouseX = util.ioQuery('mouse', 'getClientX'); - const mouseY = util.ioQuery('mouse', 'getClientY'); - return util.target.isTouchingPoint(mouseX, mouseY); - } else if (requestedObject === '_edge_') { - return util.target.isTouchingEdge(); - } - return util.target.isTouchingSprite(requestedObject); + return util.target.touchingObject(args.TOUCHINGOBJECTMENU); } hatGreaterThanPredicate (args, util) { diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index f140997cf..ff0beac89 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -150,16 +150,7 @@ class Scratch3SensingBlocks { } touchingObject (args, util) { - const requestedObject = args.TOUCHINGOBJECTMENU; - if (requestedObject === '_mouse_') { - const mouseX = util.ioQuery('mouse', 'getClientX'); - const mouseY = util.ioQuery('mouse', 'getClientY'); - return util.target.isTouchingPoint(mouseX, mouseY); - } else if (requestedObject === '_edge_') { - return util.target.isTouchingEdge(); - } - return util.target.isTouchingSprite(requestedObject); - + return util.target.touchingObject(args.TOUCHINGOBJECTMENU); } touchingColor (args, util) { diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index b6df05e6c..6beb72a27 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -724,6 +724,23 @@ class RenderedTarget extends Target { return null; } + /** + * Return whether touching the mouse, an edge, or a sprite. + * @param {string} requestedObject an id for mouse or edge, or a sprite name. + * @return {boolean} True if the sprite is touching the object. + */ + touchingObject (requestedObject) { + if (requestedObject === '_mouse_') { + if (!this.runtime.ioDevices.mouse) return false; + const mouseX = this.runtime.ioDevices.mouse.getClientX(); + const mouseY = this.runtime.ioDevices.mouse.getClientY(); + return this.isTouchingPoint(mouseX, mouseY); + } else if (requestedObject === '_edge_') { + return this.isTouchingEdge(); + } + return this.isTouchingSprite(requestedObject); + } + /** * Return whether touching a point. * @param {number} x X coordinate of test point. From db7c56e08b753bc9d79f324e5a0f28c3ed19406d Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Thu, 7 Jun 2018 14:12:23 -0400 Subject: [PATCH 3/3] Change function name and comment for clarity --- src/blocks/scratch3_event.js | 2 +- src/blocks/scratch3_sensing.js | 2 +- src/sprites/rendered-target.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index 8e3a302cc..a486bda09 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -63,7 +63,7 @@ class Scratch3EventBlocks { } touchingObject (args, util) { - return util.target.touchingObject(args.TOUCHINGOBJECTMENU); + return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU); } hatGreaterThanPredicate (args, util) { diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index ff0beac89..9e1d37a50 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -150,7 +150,7 @@ class Scratch3SensingBlocks { } touchingObject (args, util) { - return util.target.touchingObject(args.TOUCHINGOBJECTMENU); + return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU); } touchingColor (args, util) { diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 6beb72a27..3acd83b0f 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -725,11 +725,11 @@ class RenderedTarget extends Target { } /** - * Return whether touching the mouse, an edge, or a sprite. + * Return whether this target is touching the mouse, an edge, or a sprite. * @param {string} requestedObject an id for mouse or edge, or a sprite name. * @return {boolean} True if the sprite is touching the object. */ - touchingObject (requestedObject) { + isTouchingObject (requestedObject) { if (requestedObject === '_mouse_') { if (!this.runtime.ioDevices.mouse) return false; const mouseX = this.runtime.ioDevices.mouse.getClientX();