From f981e8747f9a2820a86407e06ba40e035966306e Mon Sep 17 00:00:00 2001 From: liam4 Date: Fri, 2 Sep 2016 00:48:14 -0300 Subject: [PATCH 1/3] Implement 'current' block --- src/blocks/scratch3_sensing.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index ee75cc43a..3271990f3 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -16,7 +16,9 @@ Scratch3SensingBlocks.prototype.getPrimitives = function() { 'sensing_resettimer': this.resetTimer, 'sensing_mousex': this.getMouseX, 'sensing_mousey': this.getMouseY, - 'sensing_mousedown': this.getMouseDown + 'sensing_mousedown': this.getMouseDown, + 'sensing_current': this.current, + 'sensing_currentmenu': this.currentMenu }; }; @@ -40,4 +42,28 @@ Scratch3SensingBlocks.prototype.getMouseDown = function (args, util) { return util.ioQuery('mouse', 'getIsDown'); }; +Scratch3SensingBlocks.prototype.current = function (args, util) { + var date = new Date(); + switch (args.CURRENTMENU) { + case 'year': + return date.getFullYear(); + case 'month': + return date.getMonth(); + case 'date': + return date.getDate(); + case 'dayofweek': + return date.getDay(); + case 'hour': + return date.getHours(); + case 'minute': + return date.getMinutes(); + case 'second': + return date.getSeconds(); + } +}; + +Scratch3SensingBlocks.prototype.currentMenu = function (args) { + return args.CURRENTMENU.toLowerCase(); +}; + module.exports = Scratch3SensingBlocks; From 602cb47a1e1495fb833a1f56e6facfa823db933f Mon Sep 17 00:00:00 2001 From: liam4 Date: Fri, 2 Sep 2016 01:01:17 -0300 Subject: [PATCH 2/3] Remove unused util variable --- src/blocks/scratch3_sensing.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index 3271990f3..44e5a9b3c 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -42,23 +42,16 @@ Scratch3SensingBlocks.prototype.getMouseDown = function (args, util) { return util.ioQuery('mouse', 'getIsDown'); }; -Scratch3SensingBlocks.prototype.current = function (args, util) { +Scratch3SensingBlocks.prototype.current = function (args) { var date = new Date(); switch (args.CURRENTMENU) { - case 'year': - return date.getFullYear(); - case 'month': - return date.getMonth(); - case 'date': - return date.getDate(); - case 'dayofweek': - return date.getDay(); - case 'hour': - return date.getHours(); - case 'minute': - return date.getMinutes(); - case 'second': - return date.getSeconds(); + case 'year': return date.getFullYear(); + case 'month': return date.getMonth() + 1; // getMonth is zero-based + case 'date': return date.getDate(); + case 'dayofweek': return date.getDay(); + case 'hour': return date.getHours(); + case 'minute': return date.getMinutes(); + case 'second': return date.getSeconds(); } }; From 1437a358e155e6dd4c0a7b2e668e3c359982c6b4 Mon Sep 17 00:00:00 2001 From: liam4 Date: Fri, 2 Sep 2016 10:20:54 -0300 Subject: [PATCH 3/3] getDay is zero-based where Sunday = 0; Sunday should be 1 --- src/blocks/scratch3_sensing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index 44e5a9b3c..c1ac19c29 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -48,7 +48,7 @@ Scratch3SensingBlocks.prototype.current = function (args) { case 'year': return date.getFullYear(); case 'month': return date.getMonth() + 1; // getMonth is zero-based case 'date': return date.getDate(); - case 'dayofweek': return date.getDay(); + case 'dayofweek': return date.getDay() + 1; // getDay is zero-based, Sun=0 case 'hour': return date.getHours(); case 'minute': return date.getMinutes(); case 'second': return date.getSeconds();