Skip to content

Commit

Permalink
Lily/LooksPlus: fix "this sprite" in clones (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jun 20, 2023
1 parent fc48645 commit f76fab4
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions extensions/Lily/LooksPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
return true;
};

/**
* @param {VM.BlockUtility} util
* @param {unknown} targetName
*/
const getSpriteTargetByName = (util, targetName) => {
const nameString = Scratch.Cast.toString(targetName);
const target = util.target;
if (target.getName() === nameString) {
return target;
}
return util.runtime.getSpriteTargetByName(nameString);
};

class LooksPlus {
getInfo() {
return {
Expand Down Expand Up @@ -313,29 +326,29 @@
}

showSprite(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (target) {
target.setVisible(true);
}
}

hideSprite(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (target) {
target.setVisible(false);
}
}

spriteVisible(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
return false;
}
return Scratch.Cast.toBoolean(target.visible);
}

setLayerTo(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
return;
}
Expand All @@ -346,15 +359,15 @@
}

spriteLayerNumber(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
return 0;
}
return target.getLayerOrder();
}

effectValue(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
return 0;
}
Expand Down Expand Up @@ -395,7 +408,7 @@
}

targetCostumeNumber(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
return 0;
}
Expand Down Expand Up @@ -464,7 +477,7 @@
}

costumeContent(args, util) {
const target = Scratch.vm.runtime.getSpriteTargetByName(args.TARGET);
const target = getSpriteTargetByName(util, args.TARGET);
if (!target) {
console.error('Target does not exist');
return '';
Expand Down

0 comments on commit f76fab4

Please sign in to comment.