Skip to content

Commit 98ae84c

Browse files
committed
add extendable join block, add xml fields first to fix extendables after sprite swapping
1 parent 44c475f commit 98ae84c

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/blocks/scratch3_operators.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Scratch3OperatorsBlocks {
2828
operator_not: this.not,
2929
operator_random: this.random,
3030
operator_join: this.join,
31+
operator_join_extendable: this.joinExtendable,
3132
operator_letter_of: this.letterOf,
3233
operator_length: this.length,
3334
operator_contains: this.contains,
@@ -102,6 +103,15 @@ class Scratch3OperatorsBlocks {
102103
return Cast.toString(args.STRING1) + Cast.toString(args.STRING2);
103104
}
104105

106+
joinExtendable (args) {
107+
let string = "";
108+
const argCount = +args.STRINGS;
109+
for (let i = 0; i < argCount; i++) {
110+
string += Cast.toString(args["STRINGS_" + i + "_STRING"]);
111+
}
112+
return string;
113+
}
114+
105115
letterOf (args) {
106116
const index = Cast.toNumber(args.LETTER) - 1;
107117
const str = Cast.toString(args.STRING);

src/compiler/compat-blocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const stacked = [
3636
const inputs = [
3737
'motion_xscroll',
3838
'motion_yscroll',
39+
'operator_join_extendable',
3940
'sensing_loud',
4041
'sensing_loudness',
4142
'sensing_userid',

src/engine/blocks.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,23 +1237,6 @@ class Blocks {
12371237
if (block.mutation) {
12381238
xmlString += this.mutationToXML(block.mutation);
12391239
}
1240-
// Add any inputs on this block.
1241-
for (const input in block.inputs) {
1242-
if (!Object.prototype.hasOwnProperty.call(block.inputs, input)) continue;
1243-
const blockInput = block.inputs[input];
1244-
// Only encode a value tag if the value input is occupied.
1245-
if (blockInput.block || blockInput.shadow) {
1246-
xmlString += `<value name="${xmlEscape(blockInput.name)}">`;
1247-
if (blockInput.block) {
1248-
xmlString += this.blockToXML(blockInput.block, comments);
1249-
}
1250-
if (blockInput.shadow && blockInput.shadow !== blockInput.block) {
1251-
// Obscured shadow.
1252-
xmlString += this.blockToXML(blockInput.shadow, comments);
1253-
}
1254-
xmlString += '</value>';
1255-
}
1256-
}
12571240
// Add any fields on this block.
12581241
for (const field in block.fields) {
12591242
if (!Object.prototype.hasOwnProperty.call(block.fields, field)) continue;
@@ -1273,6 +1256,23 @@ class Blocks {
12731256
}
12741257
xmlString += `>${value}</field>`;
12751258
}
1259+
// Add any inputs on this block.
1260+
for (const input in block.inputs) {
1261+
if (!Object.prototype.hasOwnProperty.call(block.inputs, input)) continue;
1262+
const blockInput = block.inputs[input];
1263+
// Only encode a value tag if the value input is occupied.
1264+
if (blockInput.block || blockInput.shadow) {
1265+
xmlString += `<value name="${xmlEscape(blockInput.name)}">`;
1266+
if (blockInput.block) {
1267+
xmlString += this.blockToXML(blockInput.block, comments);
1268+
}
1269+
if (blockInput.shadow && blockInput.shadow !== blockInput.block) {
1270+
// Obscured shadow.
1271+
xmlString += this.blockToXML(blockInput.shadow, comments);
1272+
}
1273+
xmlString += '</value>';
1274+
}
1275+
}
12761276
// Add blocks connected to the next connection.
12771277
if (block.next) {
12781278
xmlString += `<next>${this.blockToXML(block.next, comments)}</next>`;

0 commit comments

Comments
 (0)