2016-08-15 21:37:36 -04:00
|
|
|
function Scratch3SensingBlocks(runtime) {
|
|
|
|
/**
|
|
|
|
* The runtime instantiating this block package.
|
|
|
|
* @type {Runtime}
|
|
|
|
*/
|
|
|
|
this.runtime = runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the block primitives implemented by this package.
|
|
|
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
|
|
|
*/
|
|
|
|
Scratch3SensingBlocks.prototype.getPrimitives = function() {
|
|
|
|
return {
|
|
|
|
'sensing_timer': this.getTimer,
|
|
|
|
'sensing_resettimer': this.resetTimer,
|
|
|
|
'sensing_mousex': this.getMouseX,
|
|
|
|
'sensing_mousey': this.getMouseY,
|
2016-09-01 23:48:14 -04:00
|
|
|
'sensing_mousedown': this.getMouseDown,
|
|
|
|
'sensing_current': this.current,
|
|
|
|
'sensing_currentmenu': this.currentMenu
|
2016-08-15 21:37:36 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.getTimer = function (args, util) {
|
|
|
|
return util.ioQuery('clock', 'projectTimer');
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.resetTimer = function (args, util) {
|
|
|
|
util.ioQuery('clock', 'resetProjectTimer');
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.getMouseX = function (args, util) {
|
|
|
|
return util.ioQuery('mouse', 'getX');
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.getMouseY = function (args, util) {
|
|
|
|
return util.ioQuery('mouse', 'getY');
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.getMouseDown = function (args, util) {
|
|
|
|
return util.ioQuery('mouse', 'getIsDown');
|
|
|
|
};
|
|
|
|
|
2016-09-02 00:01:17 -04:00
|
|
|
Scratch3SensingBlocks.prototype.current = function (args) {
|
2016-09-01 23:48:14 -04:00
|
|
|
var date = new Date();
|
|
|
|
switch (args.CURRENTMENU) {
|
2016-09-02 00:01:17 -04:00
|
|
|
case 'year': return date.getFullYear();
|
|
|
|
case 'month': return date.getMonth() + 1; // getMonth is zero-based
|
|
|
|
case 'date': return date.getDate();
|
2016-09-02 09:20:54 -04:00
|
|
|
case 'dayofweek': return date.getDay() + 1; // getDay is zero-based, Sun=0
|
2016-09-02 00:01:17 -04:00
|
|
|
case 'hour': return date.getHours();
|
|
|
|
case 'minute': return date.getMinutes();
|
|
|
|
case 'second': return date.getSeconds();
|
2016-09-01 23:48:14 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SensingBlocks.prototype.currentMenu = function (args) {
|
|
|
|
return args.CURRENTMENU.toLowerCase();
|
|
|
|
};
|
|
|
|
|
2016-08-15 21:37:36 -04:00
|
|
|
module.exports = Scratch3SensingBlocks;
|