Skip to content

Commit 5e30d0c

Browse files
authored
Merge branch 'main' into custom-monitor-opacity
2 parents 571346b + f7e850c commit 5e30d0c

File tree

18 files changed

+1951
-0
lines changed

18 files changed

+1951
-0
lines changed

api/feature/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { default as self } from "./self.js";
22
import { default as traps } from "./traps.js";
33
import { default as auth } from "./auth.js";
4+
import { default as server } from "./server.js";
45

56
export default function (data) {
67
var feature = new Feature(data);
78
feature.self = self(data.id);
89
feature.traps = traps()
910
feature.auth = auth()
11+
feature.server = server()
1012
feature.page = {
1113
appendToSharedSpace: ScratchTools.appendToSharedSpace,
1214
waitForElement: ScratchTools.waitForElement,

api/feature/server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function (id) {
2+
return {
3+
url: "https://data.scratchtools.app",
4+
endpoint: function(path) {
5+
return "https://data.scratchtools.app" + path
6+
},
7+
}
8+
}

features/chomp-blocks/data.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "Extend Wrapped C Blocks",
3+
"description": "Automatically extends C blocks to wrap around blocks that it is being placed over when dragging.",
4+
"credits": [
5+
{
6+
"username": "CST1229",
7+
"url": "https://github.com/CST1229/"
8+
}
9+
],
10+
"tags": [],
11+
"scripts": [{ "file": "script.js", "runOn": "/projects/*" }],
12+
"dynamic": true,
13+
"type": ["Editor"]
14+
}

features/chomp-blocks/script.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
export default async function ({ feature, console }) {
2+
await feature.page.waitForElement(".blocklyWorkspace")
3+
4+
const ScratchBlocks = feature.traps.blocks();
5+
6+
// Rerender the dragged block when updating the insertion marker
7+
const ogConnectMarker = ScratchBlocks.InsertionMarkerManager.prototype.connectMarker_;
8+
ScratchBlocks.InsertionMarkerManager.prototype.connectMarker_ = function () {
9+
ogConnectMarker.call(this);
10+
if (!feature.self.disabled && this.firstMarker_) {
11+
const block = this?.workspace_?.currentGesture_?.blockDragger_?.draggingBlock_;
12+
block.noMoveConnection = true;
13+
if (block) block.render(false);
14+
}
15+
};
16+
const ogDisconnectMarker = ScratchBlocks.InsertionMarkerManager.prototype.disconnectMarker_;
17+
ScratchBlocks.InsertionMarkerManager.prototype.disconnectMarker_ = function () {
18+
ogDisconnectMarker.call(this);
19+
if (!feature.self.disabled && this.firstMarker_) {
20+
const block = this?.workspace_?.currentGesture_?.blockDragger_?.draggingBlock_;
21+
block.noMoveConnection = true;
22+
if (block) block.render(false);
23+
}
24+
};
25+
26+
const ogDraw = ScratchBlocks.BlockSvg.prototype.renderDraw_;
27+
const ogMoveConnections = ScratchBlocks.BlockSvg.prototype.renderMoveConnections_;
28+
ScratchBlocks.BlockSvg.prototype.renderDraw_ = function (iconWidth, inputRows) {
29+
if (feature.self.disabled) return ogDraw.call(this, iconWidth, inputRows);
30+
31+
// If the block contains a statement (C) input and has an insertion marker,
32+
// use that to calculate the height of the statement inputs
33+
let computeBlock = this;
34+
if (this?.workspace?.currentGesture_?.blockDragger_?.draggedConnectionManager_) {
35+
const dragger = this.workspace.currentGesture_.blockDragger_;
36+
const manager = dragger.draggedConnectionManager_;
37+
if (
38+
manager.markerConnection_ &&
39+
manager.firstMarker_ &&
40+
dragger.draggingBlock_ == this &&
41+
dragger.draggingBlock_.type == manager.firstMarker_.type
42+
) {
43+
if (inputRows.some((row) => row.some((input) => input.type === ScratchBlocks.NEXT_STATEMENT))) {
44+
computeBlock = manager.firstMarker_;
45+
}
46+
}
47+
}
48+
49+
// Change the height of substacks
50+
// (If we set inputRows to computeBlock.renderCompute_,
51+
// the references to the inputs would be wrong
52+
// so they just won't update properly)
53+
if (computeBlock !== this) {
54+
const _inputRows = computeBlock.renderCompute_(iconWidth);
55+
for (let i = 0; i < inputRows.length; i++) {
56+
const row = inputRows[i];
57+
let update = false;
58+
for (const input of row) {
59+
if (input.type === ScratchBlocks.NEXT_STATEMENT) update = true;
60+
}
61+
if (update) row.height = Math.max(row.height, _inputRows[i].height);
62+
}
63+
}
64+
65+
ogDraw.call(this, iconWidth, inputRows);
66+
67+
// Moving the connections of a block while it's being dragged breaks it,
68+
// so don't
69+
if (computeBlock === this && !this.noMoveConnection) ogMoveConnections.call(this);
70+
this.noMoveConnection = false;
71+
};
72+
ScratchBlocks.BlockSvg.prototype.renderMoveConnections_ = function () {
73+
if (feature.self.disabled) return ogMoveConnections.call(this);
74+
// Do nothing (this function is instead called by renderDraw_)
75+
};
76+
}

features/features.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
"id": "change-monitor-opacity",
55
"versionAdded": "v4.0.0"
66
},
7+
{
8+
"version": 2,
9+
"id": "project-reactions",
10+
"versionAdded": "v4.0.0"
11+
},
12+
{
13+
"version": 2,
14+
"id": "chomp-blocks",
15+
"versionAdded": "v4.0.0"
16+
},
717
{
818
"version": 2,
919
"id": "custom-explore",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"title": "Project Reactions",
3+
"description": "Allows you to react to projects with different emojis.",
4+
"credits": [
5+
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
6+
],
7+
"type": ["Website"],
8+
"tags": ["New"],
9+
"dynamic": true,
10+
"scripts": [
11+
{
12+
"file": "script.js",
13+
"runOn": "/projects/*"
14+
}
15+
],
16+
"styles": [
17+
{
18+
"file": "style.css",
19+
"runOn": "/projects/*"
20+
}
21+
],
22+
"components": [
23+
{
24+
"type": "info",
25+
"content": "Users will not receive a notification when you react to their projects."
26+
}
27+
],
28+
"resources": [
29+
{ "name": "project-reactions-beaming", "path": "/emojis/beaming.svg" },
30+
{ "name": "project-reactions-crying", "path": "/emojis/crying.svg" },
31+
{ "name": "project-reactions-fire", "path": "/emojis/fire.svg" },
32+
{ "name": "project-reactions-hands", "path": "/emojis/hands.svg" },
33+
{
34+
"name": "project-reactions-heart-eyes",
35+
"path": "/emojis/heart-eyes.svg"
36+
},
37+
{
38+
"name": "project-reactions-heart-face",
39+
"path": "/emojis/heart-face.svg"
40+
},
41+
{ "name": "project-reactions-hearts", "path": "/emojis/hearts.svg" },
42+
{ "name": "project-reactions-laughing", "path": "/emojis/laughing.svg" },
43+
{ "name": "project-reactions-popper", "path": "/emojis/popper.svg" },
44+
{ "name": "project-reactions-thumbsup", "path": "/emojis/thumbsup.svg" }
45+
]
46+
}
Lines changed: 100 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)