@@ -31,6 +31,9 @@ import Blockly from 'blockly/core';
31
31
import { getDefaultProfile } from '../../../project' ;
32
32
import { colorPalette } from '../propc' ;
33
33
34
+ const leftDblQuoteMark = '\u201C' ;
35
+ const rightDblQuoteMark = '\u201D' ;
36
+
34
37
/**
35
38
* Block for defining a procedure with no return value.
36
39
* Procedures DefNoReturn
@@ -436,7 +439,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
436
439
} ;
437
440
438
441
/**
439
- * Procedure Call No Return
442
+ * Block Run Function
443
+ * Procedure Call block that has no return value
440
444
*
441
445
* @type {{
442
446
* init: Blockly.Blocks.procedures_callnoreturn.init,
@@ -462,42 +466,67 @@ Blockly.Blocks['procedures_callnoreturn'] = {
462
466
* @this Blockly.Block
463
467
*/
464
468
init : function ( ) {
469
+ // Look into the current profile
465
470
const profile = getDefaultProfile ( ) ;
466
- if ( profile . description === 'Scribbler Robot' ) {
467
- this . setHelpUrl ( Blockly . MSG_S3_FUNCTIONS_HELPURL ) ;
468
- } else {
469
- this . setHelpUrl ( Blockly . MSG_FUNCTIONS_HELPURL ) ;
470
- }
471
+ this . setHelpUrl ( ( profile . name === 's3' ) ?
472
+ Blockly . MSG_S3_FUNCTIONS_HELPURL :Blockly . MSG_FUNCTIONS_HELPURL ) ;
471
473
this . setTooltip ( Blockly . MSG_PROCEDURES_CALLNORETURN_TOOLTIP ) ;
472
474
this . setColour ( colorPalette . getColor ( 'functions' ) ) ;
475
+
473
476
this . appendDummyInput ( 'TOPROW' )
474
- . appendField ( 'run function \u201C' + this . id + '\u201D' , 'NAME' ) ;
477
+ . appendField (
478
+ `run function ${ leftDblQuoteMark } ${ this . id } ${ rightDblQuoteMark } ` ,
479
+ 'NAME' ) ;
480
+
475
481
this . setPreviousStatement ( true ) ;
476
482
this . setNextStatement ( true ) ;
483
+
484
+ /**
485
+ * Function parameters array
486
+ * @type {*[] }
487
+ * @private
488
+ */
477
489
this . arguments_ = [ ] ;
490
+
491
+ /**
492
+ * Function parameter data types
493
+ * @type {*[] }
494
+ * @private
495
+ */
478
496
this . argumentVarModels_ = [ ] ;
497
+
498
+ /**
499
+ * No idea what a quark connection is or what it does
500
+ * @type {{} }
501
+ * @private
502
+ */
479
503
this . quarkConnections_ = { } ;
504
+
505
+ /**
506
+ * More quarkness but now with ID fields
507
+ * @type {null }
508
+ * @private
509
+ */
480
510
this . quarkIds_ = null ;
481
511
482
512
/**
483
513
* Set the previous disabled state to false (off)
484
- *
485
514
* @type {boolean }
486
515
* @private
487
516
*/
488
517
this . previousDisabledState_ = false ;
489
518
} ,
490
519
491
520
/**
492
- * Returns the name of the procedure this block calls.
521
+ * Returns the name of the function block that this block calls.
493
522
* @return {string } Procedure name.
494
523
* @this Blockly.Block
524
+ * @description The NAME field is guaranteed to exist, null will never be returned.
495
525
*/
496
526
getProcedureCall : function ( ) {
497
- // The NAME field is guaranteed to exist, null will never be returned.
498
- return /** @type {string } */ (
499
- ( this . getFieldValue ( 'NAME' ) )
500
- . split ( '\u201C' ) ) [ 1 ] . slice ( 0 , - 1 ) ;
527
+ return /** @type {string } */ ( ( this . getFieldValue ( 'NAME' ) )
528
+ . split ( leftDblQuoteMark ) ) [ 1 ]
529
+ . slice ( 0 , - 1 ) ;
501
530
} ,
502
531
503
532
/**
@@ -509,7 +538,9 @@ Blockly.Blocks['procedures_callnoreturn'] = {
509
538
*/
510
539
renameProcedure : function ( oldName , newName ) {
511
540
if ( Blockly . Names . equals ( oldName , this . getProcedureCall ( ) ) ) {
512
- this . setFieldValue ( 'run function \u201C' + newName + '\u201D' , 'NAME' ) ;
541
+ this . setFieldValue (
542
+ `run function ${ leftDblQuoteMark } ${ newName } ${ rightDblQuoteMark } ` ,
543
+ 'NAME' ) ;
513
544
}
514
545
} ,
515
546
@@ -533,8 +564,10 @@ Blockly.Blocks['procedures_callnoreturn'] = {
533
564
// Existing param IDs.
534
565
// Note that quarkConnections_ may include IDs that no longer exist, but
535
566
// which might reappear if a param is reattached in the mutator.
536
- const defBlock = Blockly . Procedures . getDefinition ( this . getProcedureCall ( ) ,
567
+ const defBlock = Blockly . Procedures . getDefinition (
568
+ this . getProcedureCall ( ) ,
537
569
this . workspace ) ;
570
+
538
571
const mutatorOpen = defBlock && defBlock . mutator &&
539
572
defBlock . mutator . isVisible ( ) ;
540
573
if ( ! mutatorOpen ) {
@@ -547,12 +580,12 @@ Blockly.Blocks['procedures_callnoreturn'] = {
547
580
}
548
581
// Test arguments (arrays of strings) for changes. '\n' is not a valid
549
582
// argument name character, so it is a valid delimiter here.
550
- if ( paramNames . join ( '\n' ) == this . arguments_ . join ( '\n' ) ) {
583
+ if ( paramNames . join ( '\n' ) === this . arguments_ . join ( '\n' ) ) {
551
584
// No change.
552
585
this . quarkIds_ = paramIds ;
553
586
return ;
554
587
}
555
- if ( paramIds . length != paramNames . length ) {
588
+ if ( paramIds . length !== paramNames . length ) {
556
589
throw new RangeError ( 'paramNames and paramIds must be the same length.' ) ;
557
590
}
558
591
this . setCollapsed ( false ) ;
@@ -712,50 +745,73 @@ Blockly.Blocks['procedures_callnoreturn'] = {
712
745
* @this Blockly.Block
713
746
*/
714
747
onchange : function ( event ) {
748
+ console . log ( `Event: ${ event . type } ` ) ;
749
+
750
+ if ( event . type === Blockly . Events . BLOCK_MOVE ) {
751
+ try {
752
+ console . log ( `Block is moving` ) ;
753
+ } catch ( err ) {
754
+ console . log ( `Block move error: ${ err . message } ` ) ;
755
+ }
756
+ }
757
+
758
+ // Get the block attached to the top of this block
715
759
const tBlock = this . previousConnection . targetBlock ( ) ;
716
- if ( tBlock ) {
717
- if ( tBlock . toString ( ) . indexOf ( 'new processor ' ) === 0 ) {
718
- // Solo-497
719
- // Cannot set nextStatement to false if there is a block attached
720
- // below the current block. Detach the block first.
721
- const nextBlock = this . getNextBlock ( ) ;
722
- if ( nextBlock !== null ) {
723
- console . log ( `NextBlock: ${ nextBlock . type . toString ( ) } ` ) ;
724
- // nextBlock.nextConnection.disconnect();
725
- }
726
- try {
727
- this . setNextStatement ( false ) ;
728
- } catch ( event ) {
729
- console . log ( event . message ) ;
730
- this . nextConnection . disconnect ( ) ;
760
+
761
+ try {
762
+ // If a block is attached, and it is a new processor block, disconnect
763
+ // the block attached to the bottom of this block, if one is attached.
764
+ // The new processor block supports a single function call and that
765
+ // function call cannot chain to any other blocks.
766
+ if ( tBlock ) {
767
+ if ( tBlock . toString ( ) . indexOf ( 'new processor ' ) === 0 ) {
768
+ // Solo-497
769
+ // Cannot set nextStatement to false if there is a block attached
770
+ // below the current block. Detach the block first.
771
+ const nextBlock = this . getNextBlock ( ) ;
772
+ console . log ( `RunFunction: Bottom block attachment is: ${ nextBlock } ` ) ;
773
+
774
+ if ( nextBlock !== null ) {
775
+ console . log ( `NextBlock: ${ nextBlock . type . toString ( ) } ` ) ;
776
+ this . nextConnection . disconnect ( ) ;
777
+ }
731
778
this . setNextStatement ( false ) ;
779
+ } else {
780
+ this . setNextStatement ( true ) ;
732
781
}
733
782
} else {
734
783
this . setNextStatement ( true ) ;
735
784
}
736
- } else {
737
- this . setNextStatement ( true ) ;
785
+ } catch ( event ) {
786
+ console . log ( event . message ) ;
787
+ this . nextConnection . disconnect ( ) ;
788
+ this . setNextStatement ( false ) ;
738
789
}
790
+
739
791
if ( ! this . workspace || this . workspace . isFlyout ) {
740
792
// Block is deleted or is in a flyout.
741
793
return ;
742
794
}
795
+
743
796
if ( ! event . recordUndo ) {
744
797
// Events not generated by user. Skip handling.
745
798
return ;
746
799
}
747
- if ( event . type == Blockly . Events . BLOCK_CREATE &&
748
- event . ids . indexOf ( this . id ) != - 1 ) {
800
+
801
+ if ( event . type === Blockly . Events . BLOCK_CREATE &&
802
+ event . ids . indexOf ( this . id ) !== - 1 ) {
749
803
// Look for the case where a procedure call was created (usually through
750
804
// paste) and there is no matching definition. In this case, create
751
805
// an empty definition block with the correct signature.
752
806
const name = this . getProcedureCall ( ) ;
753
807
let def = Blockly . Procedures . getDefinition ( name , this . workspace ) ;
754
- if ( def && ( def . type != this . defType_ ||
755
- JSON . stringify ( def . arguments_ ) != JSON . stringify ( this . arguments_ ) ) ) {
808
+ if ( def &&
809
+ ( def . type !== this . defType_ ||
810
+ JSON . stringify ( def . arguments_ ) !== JSON . stringify ( this . arguments_ ) ) ) {
756
811
// The signatures don't match.
757
812
def = null ;
758
813
}
814
+
759
815
if ( ! def ) {
760
816
Blockly . Events . setGroup ( event . group ) ;
761
817
/**
@@ -787,7 +843,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
787
843
Blockly . Xml . domToWorkspace ( xml , this . workspace ) ;
788
844
Blockly . Events . setGroup ( false ) ;
789
845
}
790
- } else if ( event . type == Blockly . Events . BLOCK_DELETE ) {
846
+ } else if ( event . type === Blockly . Events . BLOCK_DELETE ) {
791
847
// Look for the case where a procedure definition has been deleted,
792
848
// leaving this block (a procedure call) orphaned. In this case, delete
793
849
// the orphan.
@@ -798,11 +854,11 @@ Blockly.Blocks['procedures_callnoreturn'] = {
798
854
this . dispose ( true , false ) ;
799
855
Blockly . Events . setGroup ( false ) ;
800
856
}
801
- } else if ( event . type == Blockly . Events . CHANGE &&
802
- event . element == 'disabled' ) {
857
+ } else if ( event . type === Blockly . Events . CHANGE &&
858
+ event . element === 'disabled' ) {
803
859
const name = this . getProcedureCall ( ) ;
804
860
const def = Blockly . Procedures . getDefinition ( name , this . workspace ) ;
805
- if ( def && def . id == event . blockId ) {
861
+ if ( def && def . id === event . blockId ) {
806
862
// in most cases the old group should be ''
807
863
const oldGroup = Blockly . Events . getGroup ( ) ;
808
864
if ( oldGroup ) {
@@ -900,8 +956,11 @@ Blockly.propc.procedures_defnoreturn = Blockly.propc.procedures_defreturn;
900
956
Blockly . propc . procedures_callreturn = function ( ) {
901
957
// Call a procedure with a return value.
902
958
const funcName = Blockly . propc . variableDB_ . getName (
903
- ( ( this . getFieldValue ( 'NAME' ) ) . split ( '\u201C' ) ) [ 1 ] . slice ( 0 , - 1 ) ,
904
- Blockly . Procedures . NAME_TYPE ) ;
959
+ ( ( this . getFieldValue ( 'NAME' ) )
960
+ . split ( leftDblQuoteMark ) ) [ 1 ]
961
+ . slice ( 0 , - 1 ) ,
962
+ // Blockly.Procedures.NAME_TYPE);
963
+ Blockly . PROCEDURE_CATEGORY_NAME ) ;
905
964
const args = [ ] ;
906
965
for ( let x = 0 ; x < this . arguments_ . length ; x ++ ) {
907
966
args [ x ] = Blockly . propc . valueToCode ( this , 'ARG' + x ,
0 commit comments