mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #2038 from ktbee/cast-sprite-names-to-string
Cast sprite name to string before getSpriteTargetByName
This commit is contained in:
commit
19a4329c8b
4 changed files with 6 additions and 0 deletions
|
@ -87,6 +87,7 @@ class Scratch3MotionBlocks {
|
||||||
targetX = Math.round(stageWidth * (Math.random() - 0.5));
|
targetX = Math.round(stageWidth * (Math.random() - 0.5));
|
||||||
targetY = Math.round(stageHeight * (Math.random() - 0.5));
|
targetY = Math.round(stageHeight * (Math.random() - 0.5));
|
||||||
} else {
|
} else {
|
||||||
|
targetName = Cast.toString(targetName);
|
||||||
const goToTarget = this.runtime.getSpriteTargetByName(targetName);
|
const goToTarget = this.runtime.getSpriteTargetByName(targetName);
|
||||||
if (!goToTarget) return;
|
if (!goToTarget) return;
|
||||||
targetX = goToTarget.x;
|
targetX = goToTarget.x;
|
||||||
|
@ -127,6 +128,7 @@ class Scratch3MotionBlocks {
|
||||||
util.target.setDirection(Math.round(Math.random() * 360) - 180);
|
util.target.setDirection(Math.round(Math.random() * 360) - 180);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
args.TOWARDS = Cast.toString(args.TOWARDS);
|
||||||
const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS);
|
const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS);
|
||||||
if (!pointTarget) return;
|
if (!pointTarget) return;
|
||||||
targetX = pointTarget.x;
|
targetX = pointTarget.x;
|
||||||
|
|
|
@ -191,6 +191,7 @@ class Scratch3SensingBlocks {
|
||||||
targetX = util.ioQuery('mouse', 'getScratchX');
|
targetX = util.ioQuery('mouse', 'getScratchX');
|
||||||
targetY = util.ioQuery('mouse', 'getScratchY');
|
targetY = util.ioQuery('mouse', 'getScratchY');
|
||||||
} else {
|
} else {
|
||||||
|
args.DISTANCETOMENU = Cast.toString(args.DISTANCETOMENU);
|
||||||
const distTarget = this.runtime.getSpriteTargetByName(
|
const distTarget = this.runtime.getSpriteTargetByName(
|
||||||
args.DISTANCETOMENU
|
args.DISTANCETOMENU
|
||||||
);
|
);
|
||||||
|
@ -282,6 +283,7 @@ class Scratch3SensingBlocks {
|
||||||
if (args.OBJECT === '_stage_') {
|
if (args.OBJECT === '_stage_') {
|
||||||
attrTarget = this.runtime.getTargetForStage();
|
attrTarget = this.runtime.getTargetForStage();
|
||||||
} else {
|
} else {
|
||||||
|
args.OBJECT = Cast.toString(args.OBJECT);
|
||||||
attrTarget = this.runtime.getSpriteTargetByName(args.OBJECT);
|
attrTarget = this.runtime.getSpriteTargetByName(args.OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const log = require('../util/log');
|
const log = require('../util/log');
|
||||||
const MathUtil = require('../util/math-util');
|
const MathUtil = require('../util/math-util');
|
||||||
const StringUtil = require('../util/string-util');
|
const StringUtil = require('../util/string-util');
|
||||||
|
const Cast = require('../util/cast');
|
||||||
const Clone = require('../util/clone');
|
const Clone = require('../util/clone');
|
||||||
const Target = require('../engine/target');
|
const Target = require('../engine/target');
|
||||||
const StageLayering = require('../engine/stage-layering');
|
const StageLayering = require('../engine/stage-layering');
|
||||||
|
@ -840,6 +841,7 @@ class RenderedTarget extends Target {
|
||||||
* @return {boolean} True iff touching a clone of the sprite.
|
* @return {boolean} True iff touching a clone of the sprite.
|
||||||
*/
|
*/
|
||||||
isTouchingSprite (spriteName) {
|
isTouchingSprite (spriteName) {
|
||||||
|
spriteName = Cast.toString(spriteName);
|
||||||
const firstClone = this.runtime.getSpriteTargetByName(spriteName);
|
const firstClone = this.runtime.getSpriteTargetByName(spriteName);
|
||||||
if (!firstClone || !this.renderer) {
|
if (!firstClone || !this.renderer) {
|
||||||
return false;
|
return false;
|
||||||
|
|
BIN
test/fixtures/execute/sprite-number-name.sb2
vendored
Normal file
BIN
test/fixtures/execute/sprite-number-name.sb2
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue