Skip to content

Commit

Permalink
Lily/ClonesPlus, Lily/LooksPlus, Skyhigh173/json: editingTarget can b…
Browse files Browse the repository at this point in the history
…e null (#1727)

for example, extensions can be loaded while the project is still loading

should resolve
https://discordapp.com/channels/837024174865776680/1285154510527922186
  • Loading branch information
GarboMuffin authored Oct 16, 2024
1 parent 33afff0 commit 93983a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions extensions/Lily/ClonesPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@
getSprites() {
let spriteNames = [];
const targets = Scratch.vm.runtime.targets;
const myself = Scratch.vm.runtime.getEditingTarget().sprite.name;
const editingTarget = Scratch.vm.runtime.getEditingTarget();
for (let index = 1; index < targets.length; index++) {
const curTarget = targets[index].sprite;
let display = curTarget.name;
if (myself === curTarget.name) {
const curTarget = targets[index];
let display = curTarget.getName();
if (editingTarget === curTarget) {
display = Scratch.translate({
default: "myself",
description: "Item in a dropdown that refers to the current sprite",
Expand All @@ -656,7 +656,7 @@
if (targets[index].isOriginal) {
const jsonOBJ = {
text: display,
value: curTarget.name,
value: curTarget.getName(),
};
spriteNames.push(jsonOBJ);
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/Lily/LooksPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,12 @@
getSprites() {
const spriteNames = [];
const targets = Scratch.vm.runtime.targets;
const myself = Scratch.vm.runtime.getEditingTarget().getName();
const editingTarget = Scratch.vm.runtime.getEditingTarget();
for (let index = 1; index < targets.length; index++) {
const target = targets[index];
if (target.isOriginal) {
const targetName = target.getName();
if (targetName === myself) {
if (target === editingTarget) {
spriteNames.unshift({
text: "this sprite",
value: targetName,
Expand Down
10 changes: 6 additions & 4 deletions extensions/Skyhigh173/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,12 @@
getLists() {
const globalLists = Object.values(
vm.runtime.getTargetForStage().variables
).filter((x) => x.type == "list");
const localLists = Object.values(vm.editingTarget.variables).filter(
(x) => x.type == "list"
);
).filter((x) => x.type === "list");
const localLists = vm.editingTarget
? Object.values(vm.editingTarget.variables).filter(
(x) => x.type === "list"
)
: [];
const uniqueLists = [...new Set([...globalLists, ...localLists])];
if (uniqueLists.length === 0) {
return [
Expand Down

0 comments on commit 93983a2

Please sign in to comment.