Clamp ghost effect

Cherry-picked from 35c8890425 (#1887)
This commit is contained in:
Florrie 2018-12-28 10:39:42 -04:00
parent c449f14280
commit fbb6d63e03

View file

@ -4,6 +4,7 @@ const RenderedTarget = require('../sprites/rendered-target');
const uid = require('../util/uid');
const StageLayering = require('../engine/stage-layering');
const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
const MathUtil = require('../util/math-util');
/**
* @typedef {object} BubbleState - the bubble state associated with a particular target.
@ -67,6 +68,14 @@ class Scratch3LooksBlocks {
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.
* @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 change = Cast.toNumber(args.CHANGE);
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);
}
setEffect (args, util) {
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);
}