Skip to content

Commit e214795

Browse files
authored
Add files via upload
1 parent 2afb69b commit e214795

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* generated by pull.js */
2+
const manifest = {
3+
"editorOnly": true,
4+
"noTranslations": true,
5+
"name": "Rearrangeable custom block inputs",
6+
"description": "Allows rearranging custom block parameters on the \"Make a block\" screen.",
7+
"credits": [
8+
{
9+
"name": "Chrome_Cat",
10+
"link": "https://scratch.mit.edu/users/Chrome_Cat/"
11+
}
12+
],
13+
"userscripts": [
14+
{
15+
"url": "userscript.js"
16+
}
17+
],
18+
"userstyles": [
19+
{
20+
"url": "arrows.css"
21+
}
22+
],
23+
"settings": [
24+
{
25+
"dynamic": true,
26+
"name": "Insert new inputs after selected input",
27+
"id": "InsertInputsAfter",
28+
"type": "boolean",
29+
"default": false
30+
}
31+
],
32+
"tags": [
33+
"recommended"
34+
],
35+
"enabledByDefault": true,
36+
"dynamicDisable": true
37+
};
38+
export default manifest;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* generated by pull.js */
2+
import _js from "./userscript.js";
3+
import _css from "!css-loader!./arrows.css";
4+
export const resources = {
5+
"userscript.js": _js,
6+
"arrows.css": _css,
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.blocklyTextShiftArrow {
2+
position: absolute;
3+
top: -50px;
4+
left: 50%;
5+
margin-left: -12.5px;
6+
cursor: pointer;
7+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// https://github.com/scratchfoundation/scratch-blocks/blob/f210e042988b91bcdc2abeca7a2d85e178edadb2/blocks_vertical/procedures.js#L205
2+
export function modifiedCreateAllInputs(connectionMap) {
3+
// Split the proc into components, by %n, %b, %s and %l (ignoring escaped).
4+
var procComponents = this.procCode_.split(/(?=[^\\]%[nbsl])/);
5+
procComponents = procComponents.map(function (c) {
6+
return c.trim(); // Strip whitespace.
7+
});
8+
9+
// Create arguments and labels as appropriate.
10+
var argumentCount = 0;
11+
for (var i = 0, component; (component = procComponents[i]); i++) {
12+
var labelText;
13+
// Don't treat %l as an argument
14+
if (component.substring(0, 1) == "%" && component.substring(1, 2) !== "l") {
15+
var argumentType = component.substring(1, 2);
16+
if (!(argumentType == "n" || argumentType == "b" || argumentType == "s")) {
17+
throw new Error("Found an custom procedure with an invalid type: " + argumentType);
18+
}
19+
labelText = component.substring(2).trim();
20+
21+
var id = this.argumentIds_[argumentCount];
22+
23+
var input = this.appendValueInput(id);
24+
if (argumentType == "b") {
25+
input.setCheck("Boolean");
26+
}
27+
this.populateArgument_(argumentType, argumentCount, connectionMap, id, input);
28+
argumentCount++;
29+
} else {
30+
labelText = component == "%l" ? " " : component.replace("%l", "").trim();
31+
}
32+
this.addProcedureLabel_(labelText.replace(/\\%/, "%"));
33+
}
34+
35+
// remove all traces of %l at the earliest possible time
36+
this.procCode_ = this.procCode_.replace(/%l /g, "");
37+
}
38+
39+
//https://github.com/scratchfoundation/scratch-blocks/blob/f210e042988b91bcdc2abeca7a2d85e178edadb2/blocks_vertical/procedures.js#L565
40+
export function modifiedUpdateDeclarationProcCode(prefixLabels = false) {
41+
this.procCode_ = "";
42+
this.displayNames_ = [];
43+
this.argumentIds_ = [];
44+
for (var i = 0; i < this.inputList.length; i++) {
45+
if (i != 0) {
46+
this.procCode_ += " ";
47+
}
48+
var input = this.inputList[i];
49+
if (input.type == 5) {
50+
// replaced Blocky.DUMMY_VALUE with 5
51+
this.procCode_ += (prefixLabels ? "%l " : "") + input.fieldRow[0].getValue(); // modified to prepend %l delimiter, which prevents label merging
52+
} else if (input.type == 1) {
53+
// replaced Blocky.INPUT_VALUE with 1
54+
// Inspect the argument editor.
55+
var target = input.connection.targetBlock();
56+
this.displayNames_.push(target.getFieldValue("TEXT"));
57+
this.argumentIds_.push(input.name);
58+
if (target.type == "argument_editor_boolean") {
59+
this.procCode_ += "%b";
60+
} else {
61+
this.procCode_ += "%s";
62+
}
63+
} else {
64+
throw new Error("Unexpected input type on a procedure mutator root: " + input.type);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)