diff --git a/playground/index.html b/playground/index.html index 2d256e7a2..3565073a0 100644 --- a/playground/index.html +++ b/playground/index.html @@ -252,7 +252,7 @@ </value> <value name="CHANGE"> <shadow type="math_number"> - <field name="NUM">10</field> + <field name="NUM">25</field> </shadow> </value> </block> @@ -262,7 +262,7 @@ </value> <value name="VALUE"> <shadow type="math_number"> - <field name="NUM">10</field> + <field name="NUM">0</field> </shadow> </value> </block> diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js new file mode 100644 index 000000000..af8ed9d70 --- /dev/null +++ b/src/blocks/scratch3_looks.js @@ -0,0 +1,54 @@ +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 { + '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 + }; +}; + +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; diff --git a/src/engine/runtime.js b/src/engine/runtime.js index c51800cdb..8159729f5 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -6,6 +6,7 @@ var util = require('util'); var defaultBlockPackages = { 'scratch3_control': require('../blocks/scratch3_control'), 'scratch3_event': require('../blocks/scratch3_event'), + 'scratch3_looks': require('../blocks/scratch3_looks'), 'scratch3_motion': require('../blocks/scratch3_motion'), 'scratch3_operators': require('../blocks/scratch3_operators') }; diff --git a/src/sprites/clone.js b/src/sprites/clone.js index b69c68d7a..cfee61556 100644 --- a/src/sprites/clone.js +++ b/src/sprites/clone.js @@ -24,6 +24,18 @@ Clone.prototype.y = 0; Clone.prototype.direction = 90; +Clone.prototype.size = 100; + +Clone.prototype.effects = { + 'color': 0, + 'fisheye': 0, + 'whirl': 0, + 'pixelate': 0, + 'mosaic': 0, + 'brightness': 0, + 'ghost': 0 +}; + Clone.prototype.setXY = function (x, y) { this.x = x; this.y = y; @@ -39,4 +51,25 @@ Clone.prototype.setDirection = function (direction) { }); }; +Clone.prototype.setSize = function (size) { + this.size = MathUtil.clamp(size, 5, 535); + self.renderer.updateDrawableProperties(this.drawableID, { + scale: this.size + }); +}; + +Clone.prototype.setEffect = function (effectName, value) { + this.effects[effectName] = value; + var props = {}; + props[effectName] = this.effects[effectName]; + self.renderer.updateDrawableProperties(this.drawableID, props); +}; + +Clone.prototype.clearEffects = function () { + for (var effectName in this.effects) { + this.effects[effectName] = 0; + } + self.renderer.updateDrawableProperties(this.drawableID, this.effects); +}; + module.exports = Clone;