Skip to content

Commit 629e260

Browse files
committed
Fix select-self leaving out important options
1 parent 75c8f1d commit 629e260

File tree

1 file changed

+83
-64
lines changed

1 file changed

+83
-64
lines changed

features/select-self/script.js

Lines changed: 83 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,98 @@
11
export default async function ({ feature, console }) {
2+
let MENU_TYPES = [
3+
"motion_glideto_menu",
4+
"motion_goto_menu",
5+
"motion_pointtowards_menu",
6+
"sensing_touchingobjectmenu",
7+
"sensing_of_object_menu",
8+
"sensing_distancetomenu",
9+
];
10+
let ORIGINAL_DATA = {
11+
motion_glideto_menu: [
12+
["random position", "_random_"],
13+
["mouse-pointer", "_mouse_"],
14+
],
15+
motion_goto_menu: [
16+
["random position", "_random_"],
17+
["mouse-pointer", "_mouse_"],
18+
],
19+
motion_pointtowards_menu: [["random position", "_random_"]],
20+
sensing_touchingobjectmenu: [
21+
["mouse-pointer", "_mouse_"],
22+
["edge", "_edge_"],
23+
],
24+
sensing_of_object_menu: [["Stage", "_stage_"]],
25+
sensing_distancetomenu: [["mouse-pointer", "_mouse_"]],
26+
};
27+
28+
let blocks = [];
29+
30+
ScratchTools.waitForElements(
31+
"g.blocklyDraggable > g[data-shapes='argument round']",
32+
function (block) {
33+
if (!Blockly) return;
34+
35+
block = Blockly.getMainWorkspace().getBlockById(block.dataset.id);
36+
if (!block) return;
37+
38+
if (MENU_TYPES.includes(block.type)) {
39+
let menu = block.inputList[0].fieldRow[0].menuGenerator_;
40+
41+
if (!blocks.includes(block.id)) {
42+
blocks.push(block.id);
43+
}
244

3-
let MENU_TYPES = ["motion_glideto_menu", "motion_goto_menu", "motion_pointtowards_menu", "sensing_touchingobjectmenu", "sensing_of_object_menu"]
4-
5-
let blocks = []
45+
updateMenu(block.id);
46+
}
47+
}
48+
);
649

7-
ScratchTools.waitForElements(
8-
"g.blocklyDraggable > g[data-shapes='argument round']",
9-
function (block) {
10-
if (!Blockly) return;
50+
feature.traps.vm.on("targetsUpdate", function (el) {
51+
for (var i in blocks) {
52+
updateMenu(blocks[i]);
53+
}
54+
});
1155

12-
block = Blockly.getMainWorkspace().getBlockById(block.dataset.id);
13-
if (!block) return;
56+
feature.addEventListener("disabled", function () {
57+
for (var i in blocks) {
58+
updateMenu(blocks[i]);
59+
}
60+
});
1461

15-
if (MENU_TYPES.includes(block.type)) {
16-
let menu = block.inputList[0].fieldRow[0].menuGenerator_;
62+
feature.addEventListener("enabled", function () {
63+
for (var i in blocks) {
64+
updateMenu(blocks[i]);
65+
}
66+
});
1767

18-
if (!blocks.includes(block.id)) {
19-
blocks.push(block.id)
20-
}
68+
function updateMenu(blockId) {
69+
let SPRITES = [];
2170

22-
updateMenu(block.id)
23-
}
24-
}
71+
let targets = feature.traps.vm.runtime.targets.filter(
72+
(target) => !target.isStage && target.isOriginal
2573
);
2674

27-
feature.traps.vm.on("targetsUpdate", function (el) {
28-
for (var i in blocks) {
29-
updateMenu(blocks[i])
30-
}
31-
})
75+
for (var i in targets) {
76+
SPRITES.push(targets[i].sprite.name);
77+
}
3278

33-
feature.addEventListener("disabled", function () {
34-
for (var i in blocks) {
35-
updateMenu(blocks[i])
36-
}
37-
})
79+
let block = Blockly.getMainWorkspace().getBlockById(blockId);
3880

39-
feature.addEventListener("enabled", function () {
40-
for (var i in blocks) {
41-
updateMenu(blocks[i])
42-
}
43-
})
81+
if (!block) return;
4482

45-
function updateMenu(blockId) {
46-
let SPRITES = []
83+
block.inputList[0].fieldRow[0].menuGenerator_ = function () {
84+
let data = ORIGINAL_DATA[block.type];
4785

48-
let targets = feature.traps.vm.runtime.targets.filter((target) => !target.isStage && target.isOriginal)
49-
50-
for (var i in targets) {
51-
SPRITES.push(targets[i].sprite.name)
86+
for (var i in SPRITES) {
87+
if (
88+
feature.self.enabled ||
89+
feature.traps.vm.runtime._editingTarget?.sprite?.name !== SPRITES[i]
90+
) {
91+
data.push([SPRITES[i], SPRITES[i]]);
5292
}
93+
}
5394

54-
let block = Blockly.getMainWorkspace().getBlockById(blockId);
55-
56-
if (!block) return;
57-
58-
block.inputList[0].fieldRow[0].menuGenerator_ = function () {
59-
let data = [
60-
[
61-
"random position",
62-
"_random_"
63-
],
64-
[
65-
"mouse-pointer",
66-
"_mouse_"
67-
]
68-
]
69-
70-
for (var i in SPRITES) {
71-
if (feature.self.enabled || feature.traps.vm.runtime._editingTarget?.sprite?.name !== SPRITES[i]) {
72-
data.push([SPRITES[i], SPRITES[i]])
73-
}
74-
}
75-
76-
return data
77-
}
78-
}
79-
}
95+
return data;
96+
};
97+
}
98+
}

0 commit comments

Comments
 (0)