2016-06-30 00:11:47 -04:00
|
|
|
function Scratch3LooksBlocks(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.
|
|
|
|
*/
|
|
|
|
Scratch3LooksBlocks.prototype.getPrimitives = function() {
|
|
|
|
return {
|
2016-07-06 13:47:32 -04:00
|
|
|
'looks_say': this.say,
|
|
|
|
'looks_sayforsecs': this.sayforsecs,
|
|
|
|
'looks_think': this.think,
|
|
|
|
'looks_thinkforsecs': this.sayforsecs,
|
2016-07-01 12:56:59 -04:00
|
|
|
'looks_show': this.show,
|
|
|
|
'looks_hide': this.hide,
|
2016-06-30 00:11:47 -04:00
|
|
|
'looks_effectmenu': this.effectMenu,
|
|
|
|
'looks_changeeffectby': this.changeEffect,
|
|
|
|
'looks_seteffectto': this.setEffect,
|
|
|
|
'looks_cleargraphiceffects': this.clearEffects,
|
|
|
|
'looks_changesizeby': this.changeSize,
|
|
|
|
'looks_setsizeto': this.setSize,
|
|
|
|
'looks_size': this.getSize
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-07-06 13:47:32 -04:00
|
|
|
Scratch3LooksBlocks.prototype.say = function (args, util) {
|
|
|
|
util.target.setSay('say', args.MESSAGE);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.sayforsecs = function (args, util) {
|
|
|
|
util.target.setSay('say', args.MESSAGE);
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
setTimeout(function() {
|
|
|
|
// Clear say bubble and proceed.
|
|
|
|
util.target.setSay();
|
|
|
|
resolve();
|
|
|
|
}, 1000 * args.SECS);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.think = function (args, util) {
|
|
|
|
util.target.setSay('think', args.MESSAGE);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.thinkforsecs = function (args, util) {
|
|
|
|
util.target.setSay('think', args.MESSAGE);
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
setTimeout(function() {
|
|
|
|
// Clear say bubble and proceed.
|
|
|
|
util.target.setSay();
|
|
|
|
resolve();
|
|
|
|
}, 1000 * args.SECS);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-07-01 12:56:59 -04:00
|
|
|
Scratch3LooksBlocks.prototype.show = function (args, util) {
|
|
|
|
util.target.setVisible(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.hide = function (args, util) {
|
|
|
|
util.target.setVisible(false);
|
|
|
|
};
|
|
|
|
|
2016-06-30 00:11:47 -04:00
|
|
|
Scratch3LooksBlocks.prototype.effectMenu = function (args) {
|
|
|
|
return args.EFFECT.toLowerCase();
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.changeEffect = function (args, util) {
|
|
|
|
var newValue = args.CHANGE + util.target.effects[args.EFFECT];
|
|
|
|
util.target.setEffect(args.EFFECT, newValue);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.setEffect = function (args, util) {
|
|
|
|
util.target.setEffect(args.EFFECT, args.VALUE);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.clearEffects = function (args, util) {
|
|
|
|
util.target.clearEffects();
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.changeSize = function (args, util) {
|
|
|
|
util.target.setSize(util.target.size + args.CHANGE);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.setSize = function (args, util) {
|
|
|
|
util.target.setSize(args.SIZE);
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3LooksBlocks.prototype.getSize = function (args, util) {
|
|
|
|
return util.target.size;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Scratch3LooksBlocks;
|