soiz1 commited on
Commit
87121ab
·
verified ·
1 Parent(s): 43eab3e

Update src/engine/blocks.js

Browse files
Files changed (1) hide show
  1. src/engine/blocks.js +26 -6
src/engine/blocks.js CHANGED
@@ -9,6 +9,7 @@ const BlocksRuntimeCache = require('./blocks-runtime-cache');
9
  const log = require('../util/log');
10
  const Variable = require('./variable');
11
  const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
 
12
 
13
  /**
14
  * @fileoverview
@@ -88,7 +89,7 @@ class Blocks {
88
  * @type {object.<string, object>}
89
  */
90
  compiledScripts: {},
91
-
92
  /**
93
  * tw: A cache of procedure code opcodes to a parsed intermediate representation
94
  * @type {object.<string, object>}
@@ -513,7 +514,7 @@ class Blocks {
513
  currTarget.blocks.updateBlocksAfterVarRename(e.varId, e.newName);
514
  }
515
  }
516
- this.runtime.emit('variableChange', e.varType, e.varId, e.varName);
517
  this.emitProjectChanged();
518
  break;
519
  case 'var_delete': {
@@ -756,11 +757,28 @@ class Blocks {
756
  isSpriteLocalVariable = !(this.runtime.getTargetForStage().variables[block.fields.VARIABLE.id]);
757
  } else if (block.opcode === 'data_listcontents') {
758
  isSpriteLocalVariable = !(this.runtime.getTargetForStage().variables[block.fields.LIST.id]);
 
 
 
 
759
  }
760
 
 
 
 
 
 
 
 
 
 
 
 
 
761
  const isSpriteSpecific = isSpriteLocalVariable ||
762
  (this.runtime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
763
- this.runtime.monitorBlockInfo[block.opcode].isSpriteSpecific);
 
764
  if (isSpriteSpecific) {
765
  // If creating a new sprite specific monitor, the only possible target is
766
  // the current editing one b/c you cannot dynamically create monitors.
@@ -783,7 +801,9 @@ class Blocks {
783
  params: this._getBlockParams(block),
784
  // @todo(vm#565) for numerical values with decimals, some countries use comma
785
  value: '',
786
- mode: block.opcode === 'data_listcontents' ? 'list' : 'default'
 
 
787
  }));
788
  }
789
  }
@@ -901,7 +921,7 @@ class Blocks {
901
  * Block management: delete blocks and their associated scripts. Does nothing if a block
902
  * with the given ID does not exist.
903
  * @param {!string} blockId Id of block to delete
904
- * @param {boolean} preserveStack If we should reconect the bottom blocks to the top block
905
  */
906
  deleteBlock (blockId, preserveStack) {
907
  // @todo In runtime, stop threads running on this script.
@@ -1424,4 +1444,4 @@ BlocksRuntimeCache.getScripts = function (blocks, opcode) {
1424
  return scripts;
1425
  };
1426
 
1427
- module.exports = Blocks;
 
9
  const log = require('../util/log');
10
  const Variable = require('./variable');
11
  const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
12
+ const StringUtil = require('../util/string-util');
13
 
14
  /**
15
  * @fileoverview
 
89
  * @type {object.<string, object>}
90
  */
91
  compiledScripts: {},
92
+
93
  /**
94
  * tw: A cache of procedure code opcodes to a parsed intermediate representation
95
  * @type {object.<string, object>}
 
514
  currTarget.blocks.updateBlocksAfterVarRename(e.varId, e.newName);
515
  }
516
  }
517
+ this.runtime.emit('variableChange', e.varType, e.varId, e.newName, e.oldName);
518
  this.emitProjectChanged();
519
  break;
520
  case 'var_delete': {
 
757
  isSpriteLocalVariable = !(this.runtime.getTargetForStage().variables[block.fields.VARIABLE.id]);
758
  } else if (block.opcode === 'data_listcontents') {
759
  isSpriteLocalVariable = !(this.runtime.getTargetForStage().variables[block.fields.LIST.id]);
760
+ } else {
761
+ isSpriteLocalVariable = Object.values(block.fields).some(field =>
762
+ ("id" in field) && !(this.runtime.getTargetForStage().variables[field.id])
763
+ );
764
  }
765
 
766
+ // Provides an API for extensions to set reporters of themselves (that can be monitored)
767
+ // as sprite-specific
768
+ var extension_sprite_specific = ((info) => {
769
+ if (info == undefined)
770
+ return false;
771
+ const block_info = info.blocks.find(_block => {
772
+ return _block.info.opcode === StringUtil.splitFirst(block.opcode, "_")[1];
773
+ });
774
+ return block_info?.info?.isSpriteSpecific ?? false;
775
+ })(vm.runtime._blockInfo.find(a => a.id === StringUtil.splitFirst(block.opcode, "_")[0]));
776
+
777
+
778
  const isSpriteSpecific = isSpriteLocalVariable ||
779
  (this.runtime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
780
+ this.runtime.monitorBlockInfo[block.opcode].isSpriteSpecific) ||
781
+ extension_sprite_specific;
782
  if (isSpriteSpecific) {
783
  // If creating a new sprite specific monitor, the only possible target is
784
  // the current editing one b/c you cannot dynamically create monitors.
 
801
  params: this._getBlockParams(block),
802
  // @todo(vm#565) for numerical values with decimals, some countries use comma
803
  value: '',
804
+ mode: block.opcode === 'data_listcontents' ? 'list' : 'default',
805
+ variableType: Object.values(block.fields)[0]?.variableType,
806
+ variableId: Object.values(block.fields)[0]?.id
807
  }));
808
  }
809
  }
 
921
  * Block management: delete blocks and their associated scripts. Does nothing if a block
922
  * with the given ID does not exist.
923
  * @param {!string} blockId Id of block to delete
924
+ * @param {boolean} preserveStack If we should reconect the bottom blocks to the top block
925
  */
926
  deleteBlock (blockId, preserveStack) {
927
  // @todo In runtime, stop threads running on this script.
 
1444
  return scripts;
1445
  };
1446
 
1447
+ module.exports = Blocks;