Skip to content

Commit 95d6b66

Browse files
committed
bring mice home with home button.
1 parent 2fcf887 commit 95d6b66

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

js/activity.js

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ function Activity() {
2020
LEADING = 0;
2121
_THIS_IS_TURTLE_BLOCKS_ = !_THIS_IS_MUSIC_BLOCKS_;
2222

23-
var _ERRORMSGTIMEOUT_ = 15000;
23+
var _ERRORMSGTIMEOUT_ = 15000;
2424
var cellSize = 55;
25-
var searchSuggestions = [];
26-
var homeButtonContainers = [];
25+
var searchSuggestions = [];
26+
var homeButtonContainers = [];
2727

2828
var that = this;
2929

30-
_findBlocks = this._findBlocks;
3130
_doFastButton = this._doFastButton;
3231
_doSlowButton = this._doSlowButton;
3332
doHardStopButton = this.doHardStopButton;
@@ -375,7 +374,7 @@ function Activity() {
375374
* Recenters blocks by finding their position on the screen
376375
* and moving them accordingly
377376
*/
378-
this._findBlocks = function () {
377+
_findBlocks = function () {
379378
// _showHideAuxMenu(false);
380379
if (!blocks.visible) {
381380
_changeBlockVisibility();
@@ -395,8 +394,6 @@ function Activity() {
395394
toppos = 90;
396395
}
397396

398-
399-
400397
palettes.updatePalettes();
401398
var x = Math.floor(leftpos * turtleBlocksScale);
402399
var y = Math.floor(toppos * turtleBlocksScale);
@@ -478,6 +475,16 @@ function Activity() {
478475
// Blocks are all home, so reset go-home-button.
479476
setHomeContainers(false, true);
480477
boundary.hide();
478+
479+
// Return mice to the center of the screen.
480+
for (var turtle = 0; turtle < turtles.turtleList.length; turtle++) {
481+
console.log('bringing turtle ' + turtle + 'home');
482+
var savedPenState = turtles.turtleList[turtle].penState;
483+
turtles.turtleList[turtle].penState = false;
484+
turtles.turtleList[turtle].doSetXY(0, 0);
485+
turtles.turtleList[turtle].doSetHeading(0);
486+
turtles.turtleList[turtle].penState = savedPenState;
487+
}
481488
};
482489

483490
/*
@@ -1256,50 +1263,40 @@ function Activity() {
12561263
refreshCanvas();
12571264
};
12581265

1259-
1260-
var myCanvas = docById('myCanvas')
1261-
1262-
var __heightBasedScroll = function (event) {
1263-
1264-
actualReszieHandler(); //check size during init
1265-
1266-
window.addEventListener("resize",resizeThrottler,false);
1267-
1268-
var resizeTimeout;
1269-
1270-
function resizeThrottler() {
1271-
//ignore resize events as long as an actualResizeHandler execution is in queue
1272-
if(!resizeTimeout) {
1273-
resizeTimeout = setTimeout(function () {
1274-
resizeTimeout = null;
1275-
actualReszieHandler();
1276-
1277-
// The actualResizeHandler will execute at the rate of 15fps
1278-
}, 66);
1279-
}
1280-
1281-
}
1282-
1283-
}
1284-
1285-
1266+
var myCanvas = docById('myCanvas')
1267+
1268+
var __heightBasedScroll = function (event) {
1269+
actualReszieHandler(); //check size during init
1270+
window.addEventListener("resize",resizeThrottler,false);
1271+
var resizeTimeout;
1272+
1273+
function resizeThrottler() {
1274+
// Ignore resize events as long as an actualResizeHandler
1275+
// execution is in queue.
1276+
if(!resizeTimeout) {
1277+
resizeTimeout = setTimeout(function () {
1278+
resizeTimeout = null;
1279+
actualReszieHandler();
1280+
// The actualResizeHandler will execute at the
1281+
// rate of 15 FPS.
1282+
}, 66);
1283+
}
1284+
};
1285+
};
12861286

1287-
function actualReszieHandler () {
1288-
1289-
//handle the resize event
1290-
1291-
var h = window.innerHeight;
1287+
function actualReszieHandler () {
1288+
// Handle the resize event
1289+
var h = window.innerHeight;
12921290

1293-
if (h < 500) { //activate on mobile
1294-
myCanvas.addEventListener('wheel', __paletteWheelHandler,false)
1295-
}else {
1296-
//cleanup event listeners
1297-
myCanvas.removeEventListener('wheel', __paletteWheelHandler)
1298-
}
1299-
1300-
}
1301-
__heightBasedScroll()
1291+
if (h < 500) { //activate on mobile
1292+
myCanvas.addEventListener('wheel', __paletteWheelHandler, false);
1293+
} else {
1294+
// Cleanup event listeners
1295+
myCanvas.removeEventListener('wheel', __paletteWheelHandler);
1296+
}
1297+
};
13021298

1299+
__heightBasedScroll()
13031300

13041301
var __wheelHandler = function (event) {
13051302
// vertical scroll
@@ -1336,7 +1333,6 @@ function Activity() {
13361333
};
13371334

13381335
docById('myCanvas').addEventListener('wheel', __wheelHandler, false);
1339-
13401336

13411337
var __stageMouseUpHandler = function (event) {
13421338
stageMouseDown = false;
@@ -2014,7 +2010,8 @@ function Activity() {
20142010
} else if (palettes.activePalette != null) {
20152011
palettes.activePalette.scrollEvent(-palettes.activePalette.scrollDiff, 1);
20162012
} else {
2017-
this._findBlocks();
2013+
// Bring all the blocks "home".
2014+
_findBlocks();
20182015
}
20192016
stage.update();
20202017
break;
@@ -3248,10 +3245,10 @@ function Activity() {
32483245

32493246
homeButtonContainers = [];
32503247
homeButtonContainers.push(_makeButton(GOHOMEBUTTON, _('Home') + ' [' + _('Home').toUpperCase() + ']', x, y, btnSize, 0));
3251-
that._loadButtonDragHandler(homeButtonContainers[0], x, y, that._findBlocks, null, null, null, null);
3248+
that._loadButtonDragHandler(homeButtonContainers[0], x, y, _findBlocks, null, null, null, null);
32523249

32533250
homeButtonContainers.push(_makeButton(GOHOMEFADEDBUTTON, _('Home') + ' [' + _('Home').toUpperCase() + ']', x, y - btnSize, btnSize, 0));
3254-
that._loadButtonDragHandler(homeButtonContainers[1], x, y, that._findBlocks, null, null, null, null);
3251+
that._loadButtonDragHandler(homeButtonContainers[1], x, y, _findBlocks, null, null, null, null);
32553252
homeButtonContainers[1].visible = false;
32563253

32573254
homeButtonContainers[0].y = this._innerHeight - 27.5; // toolbarHeight + 95.5 + 6;

0 commit comments

Comments
 (0)