Merge pull request #1878 from towerofnix/clamp-ghost

Clamp ghost effect
This commit is contained in:
Karishma Chadha 2019-01-06 17:42:43 -05:00 committed by GitHub
commit 808cb2cd60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ const RenderedTarget = require('../sprites/rendered-target');
const uid = require('../util/uid'); const uid = require('../util/uid');
const StageLayering = require('../engine/stage-layering'); const StageLayering = require('../engine/stage-layering');
const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id'); const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
const MathUtil = require('../util/math-util');
/** /**
* @typedef {object} BubbleState - the bubble state associated with a particular target. * @typedef {object} BubbleState - the bubble state associated with a particular target.
@ -67,6 +68,14 @@ class Scratch3LooksBlocks {
return 330; return 330;
} }
/**
* Limit for ghost effect
* @const {object}
*/
static get EFFECT_GHOST_LIMIT (){
return {min: 0, max: 100};
}
/** /**
* @param {Target} target - collect bubble state for this target. Probably, but not necessarily, a RenderedTarget. * @param {Target} target - collect bubble state for this target. Probably, but not necessarily, a RenderedTarget.
* @returns {BubbleState} the mutable bubble state associated with that target. This will be created if necessary. * @returns {BubbleState} the mutable bubble state associated with that target. This will be created if necessary.
@ -479,13 +488,23 @@ class Scratch3LooksBlocks {
const effect = Cast.toString(args.EFFECT).toLowerCase(); const effect = Cast.toString(args.EFFECT).toLowerCase();
const change = Cast.toNumber(args.CHANGE); const change = Cast.toNumber(args.CHANGE);
if (!util.target.effects.hasOwnProperty(effect)) return; if (!util.target.effects.hasOwnProperty(effect)) return;
const newValue = change + util.target.effects[effect]; let newValue = change + util.target.effects[effect];
if (effect === 'ghost') {
newValue = MathUtil.clamp(newValue,
Scratch3LooksBlocks.EFFECT_GHOST_LIMIT.min,
Scratch3LooksBlocks.EFFECT_GHOST_LIMIT.max);
}
util.target.setEffect(effect, newValue); util.target.setEffect(effect, newValue);
} }
setEffect (args, util) { setEffect (args, util) {
const effect = Cast.toString(args.EFFECT).toLowerCase(); const effect = Cast.toString(args.EFFECT).toLowerCase();
const value = Cast.toNumber(args.VALUE); let value = Cast.toNumber(args.VALUE);
if (effect === 'ghost') {
value = MathUtil.clamp(value,
Scratch3LooksBlocks.EFFECT_GHOST_LIMIT.min,
Scratch3LooksBlocks.EFFECT_GHOST_LIMIT.max);
}
util.target.setEffect(effect, value); util.target.setEffect(effect, value);
} }