Skip to content

Commit 0178d57

Browse files
authored
Extension Regular Expressions: Port Support (#553)
* fix for port * might as well make this consistent
1 parent bfb2ceb commit 0178d57

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

static/extensions/DogeisCut/dogeiscutRegularExpressions.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
}
1212

1313
const BlockType = Scratch.BlockType
14+
const BlockShape = Scratch.BlockShape
1415
const ArgumentType = Scratch.ArgumentType
1516
const Cast = Scratch.Cast
1617
const vm = Scratch.vm;
1718

18-
if (Scratch.gui) {
19-
Scratch.gui.getBlockly().then(ScratchBlocks => {
20-
ScratchBlocks.BlockSvg.registerCustomShape(
21-
"dogeiscutRegularExpressions-RegularExpression",{
19+
if (!vm.runtime.pmVersion) {
20+
if (Scratch.gui) {
21+
Scratch.gui.getBlockly().then(ScratchBlocks => {
22+
ScratchBlocks.BlockSvg.registerCustomShape(
23+
"dogeiscutRegularExpressions-RegularExpression", {
2224
emptyInputPath: "m 16 0 h 16 h 32 l -16 32 h -16 h -16 h -16 z",
2325
emptyInputWidth: 16 * ScratchBlocks.BlockSvg.GRID_UNIT,
2426
leftPath: (block) => {
@@ -45,8 +47,9 @@
4547
return (row.height - 16) / 2;
4648
}
4749
}
48-
);
49-
})
50+
);
51+
})
52+
}
5053
}
5154

5255
function span(text) {
@@ -244,12 +247,12 @@
244247
Type: RegularExpressionType,
245248
Block: {
246249
blockType: BlockType.REPORTER,
247-
blockShape: 'dogeiscutRegularExpressions-RegularExpression',
250+
blockShape: vm.runtime.pmVersion ? BlockShape.SLANTED : 'dogeiscutRegularExpressions-RegularExpression',
248251
forceOutputType: "Regular Expression",
249252
disableMonitor: true
250253
},
251254
Argument: {
252-
shape: 'dogeiscutRegularExpressions-RegularExpression',
255+
shape: vm.runtime.pmVersion ? BlockShape.SLANTED : 'dogeiscutRegularExpressions-RegularExpression',
253256
exemptFromNormalization: true,
254257
check: ["Regular Expression"],
255258
},
@@ -279,9 +282,9 @@
279282
// blockType: BlockType.BUTTON,
280283
// text: '⚠ Add Missing Dependencies ⚠',
281284
// func: "addDependencies",
282-
// hideFromPalette: !!vm.runtime.ext_jwArray & !!vm.runtime.ext_dogeiscutObject,
285+
// hideFromPalette: !!vm.jwArray & !!vm.dogeiscutObject,
283286
// },
284-
// ...(!vm.runtime.ext_jwArray || !vm.runtime.ext_dogeiscutObject ? ['---'] : []),
287+
// ...(!vm.jwArray || !vm.dogeiscutObject ? ['---'] : []),
285288
{
286289
opcode: 'regex',
287290
text: 'regular expression [PATTERN] [FLAGS]',
@@ -398,8 +401,8 @@
398401
},
399402
REGEX: dogeiscutRegularExpression.Argument,
400403
},
401-
hideFromPalette: !vm.runtime.ext_jwArray,
402-
...(vm.runtime.ext_jwArray ? vm.jwArray.Block : {}),
404+
hideFromPalette: !vm.jwArray,
405+
...(vm.jwArray ? vm.jwArray.Block : {}),
403406
},
404407
{
405408
opcode: 'match',
@@ -411,8 +414,8 @@
411414
defaultValue: "foo"
412415
},
413416
},
414-
hideFromPalette: !vm.runtime.ext_jwArray,
415-
...(vm.runtime.ext_jwArray ? vm.jwArray.Block : {}),
417+
hideFromPalette: !vm.jwArray,
418+
...(vm.jwArray ? vm.jwArray.Block : {}),
416419
},
417420
{
418421
opcode: 'matchAll',
@@ -424,8 +427,8 @@
424427
defaultValue: "foo"
425428
},
426429
},
427-
hideFromPalette: !vm.runtime.ext_jwArray,
428-
...(vm.runtime.ext_jwArray ? vm.jwArray.Block : {}),
430+
hideFromPalette: !vm.jwArray,
431+
...(vm.jwArray ? vm.jwArray.Block : {}),
429432
},
430433
'---',
431434
{
@@ -438,8 +441,8 @@
438441
defaultValue: "foo"
439442
},
440443
},
441-
hideFromPalette: !vm.runtime.ext_dogeiscutObject,
442-
...(vm.runtime.ext_dogeiscutObject ? vm.dogeiscutObject.Block : {}),
444+
hideFromPalette: !vm.dogeiscutObject,
445+
...(vm.dogeiscutObject ? vm.dogeiscutObject.Block : {}),
443446
},
444447
{
445448
opcode: 'getLastIndex',
@@ -476,12 +479,12 @@
476479
async addDependencies() {
477480
let string ='Due to missing extensions, the blocks in this extension have been reduced.\n'
478481
string += 'By confirming this prompt, the following extensions will automatically be added for you:\n\n'
479-
if (!vm.runtime.ext_jwArray) string += '• Arrays by jwklong\n'
480-
if (!vm.runtime.ext_dogeiscutObject) string += '• Objects by DogeisCut\n'
482+
if (!vm.jwArray) string += '• Arrays by jwklong\n'
483+
if (!vm.dogeiscutObject) string += '• Objects by DogeisCut\n'
481484
if (confirm(string)) {
482485
// technically i only need to load objects since that will load arrays, but just in case
483-
if (!vm.runtime.ext_jwArray) vm.extensionManager.loadExtensionIdSync('jwArray')
484-
if (!vm.runtime.ext_dogeiscutObject) await vm.extensionManager.loadExtensionURL("https://extensions.penguinmod.com/extensions/DogeisCut/dogeiscutObject.js")
486+
if (!vm.jwArray) vm.extensionManager.loadExtensionIdSync('jwArray')
487+
if (!vm.dogeiscutObject) await vm.extensionManager.loadExtensionURL("https://extensions.penguinmod.com/extensions/DogeisCut/dogeiscutObject.js")
485488
vm.runtime.requestBlocksUpdate()
486489
vm.runtime.requestToolboxExtensionsUpdate()
487490
vm.emitWorkspaceUpdate()
@@ -584,8 +587,8 @@
584587
}
585588

586589
(async () => {
587-
if (!vm.runtime.ext_dogeiscutObject) await vm.extensionManager.loadExtensionURL("https://extensions.penguinmod.com/extensions/DogeisCut/dogeiscutObject.js")
588-
if (!vm.runtime.ext_jwArray) vm.extensionManager.loadExtensionIdSync('jwArray')
590+
if (!vm.dogeiscutObject) await vm.extensionManager.loadExtensionURL("https://extensions.penguinmod.com/extensions/DogeisCut/dogeiscutObject.js")
591+
if (!vm.jwArray) vm.extensionManager.loadExtensionIdSync('jwArray')
589592
vm.runtime.requestBlocksUpdate()
590593
vm.runtime.requestToolboxExtensionsUpdate()
591594
vm.emitWorkspaceUpdate()

0 commit comments

Comments
 (0)