From fc4f0735269d93a570edadcbca74ecab5d0ebbc8 Mon Sep 17 00:00:00 2001
From: Ken <kenny2minecraft@gmail.com>
Date: Mon, 28 Aug 2017 19:44:34 +0000
Subject: [PATCH] Add glide (number) secs to [dropdown] block (#662)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Add glide to dropdown block

* Use helper functions instead of copy-paste

* Wrong syntax for array 😒

* Aha

* Fix some Travis issues

* Aha!! This should work

* Wow, Travis is strict about spacing!

* Make requested changes

Rename function getTarget to getTargetXY
Rename parameter TO to targetName
---
 src/blocks/scratch3_motion.js | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/blocks/scratch3_motion.js b/src/blocks/scratch3_motion.js
index d15ad8abb..d040337c8 100644
--- a/src/blocks/scratch3_motion.js
+++ b/src/blocks/scratch3_motion.js
@@ -25,6 +25,7 @@ class Scratch3MotionBlocks {
             motion_pointindirection: this.pointInDirection,
             motion_pointtowards: this.pointTowards,
             motion_glidesecstoxy: this.glide,
+            motion_glideto: this.glideTo,
             motion_ifonedgebounce: this.ifOnEdgeBounce,
             motion_setrotationstyle: this.setRotationStyle,
             motion_changexby: this.changeX,
@@ -51,24 +52,31 @@ class Scratch3MotionBlocks {
         util.target.setXY(x, y);
     }
 
-    goTo (args, util) {
+    getTargetXY (targetName, util) {
         let targetX = 0;
         let targetY = 0;
-        if (args.TO === '_mouse_') {
+        if (targetName === '_mouse_') {
             targetX = util.ioQuery('mouse', 'getX');
             targetY = util.ioQuery('mouse', 'getY');
-        } else if (args.TO === '_random_') {
+        } else if (targetName === '_random_') {
             const stageWidth = this.runtime.constructor.STAGE_WIDTH;
             const stageHeight = this.runtime.constructor.STAGE_HEIGHT;
             targetX = Math.round(stageWidth * (Math.random() - 0.5));
             targetY = Math.round(stageHeight * (Math.random() - 0.5));
         } else {
-            const goToTarget = this.runtime.getSpriteTargetByName(args.TO);
+            const goToTarget = this.runtime.getSpriteTargetByName(targetName);
             if (!goToTarget) return;
             targetX = goToTarget.x;
             targetY = goToTarget.y;
         }
-        util.target.setXY(targetX, targetY);
+        return [targetX, targetY];
+    }
+
+    goTo (args, util) {
+        const targetXY = this.getTargetXY(args.TO, util);
+        if (targetXY) {
+            util.target.setXY(targetXY[0], targetXY[1]);
+        }
     }
 
     turnRight (args, util) {
@@ -139,6 +147,13 @@ class Scratch3MotionBlocks {
             util.yield();
         }
     }
+    
+    glideTo (args, util) {
+        const targetXY = this.getTargetXY(args.TO, util);
+        if (targetXY) {
+            this.glide({SECS: args.SECS, X: targetXY[0], Y: targetXY[1]}, util);
+        }
+    }
 
     ifOnEdgeBounce (args, util) {
         const bounds = util.target.getBounds();