mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Move data to blocks files
This commit is contained in:
parent
757dccd565
commit
0958db2618
6 changed files with 62 additions and 29 deletions
|
@ -242,6 +242,15 @@ class Scratch3LooksBlocks {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMonitored () {
|
||||||
|
return {
|
||||||
|
size: {isSpriteSpecific: true},
|
||||||
|
costumeorder: {isSpriteSpecific: true},
|
||||||
|
backdroporder: {},
|
||||||
|
backdropname: {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
say (args, util) {
|
say (args, util) {
|
||||||
// @TODO in 2.0 calling say/think resets the right/left bias of the bubble
|
// @TODO in 2.0 calling say/think resets the right/left bias of the bubble
|
||||||
this._updateBubble(util.target, 'say', String(args.MESSAGE));
|
this._updateBubble(util.target, 'say', String(args.MESSAGE));
|
||||||
|
|
|
@ -38,6 +38,14 @@ class Scratch3MotionBlocks {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMonitored () {
|
||||||
|
return {
|
||||||
|
xposition: {isSpriteSpecific: true},
|
||||||
|
yposition: {isSpriteSpecific: true},
|
||||||
|
direction: {isSpriteSpecific: true}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
moveSteps (args, util) {
|
moveSteps (args, util) {
|
||||||
const steps = Cast.toNumber(args.STEPS);
|
const steps = Cast.toNumber(args.STEPS);
|
||||||
const radians = MathUtil.degToRad(90 - util.target.direction);
|
const radians = MathUtil.degToRad(90 - util.target.direction);
|
||||||
|
|
|
@ -49,6 +49,16 @@ class Scratch3SensingBlocks {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMonitored () {
|
||||||
|
return {
|
||||||
|
answer: {},
|
||||||
|
loudness: {},
|
||||||
|
timer: {},
|
||||||
|
of: {},
|
||||||
|
current: {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
_onAnswer (answer) {
|
_onAnswer (answer) {
|
||||||
this._answer = answer;
|
this._answer = answer;
|
||||||
const questionObj = this._questionList.shift();
|
const questionObj = this._questionList.shift();
|
||||||
|
|
|
@ -103,6 +103,12 @@ class Scratch3SoundBlocks {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMonitored () {
|
||||||
|
return {
|
||||||
|
volume: {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
playSound (args, util) {
|
playSound (args, util) {
|
||||||
const index = this._getSoundIndex(args.SOUND_MENU, util);
|
const index = this._getSoundIndex(args.SOUND_MENU, util);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
|
|
|
@ -176,6 +176,13 @@ class Runtime extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
this._refreshTargets = false;
|
this._refreshTargets = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map to look up all monitor block information by opcode.
|
||||||
|
* @type {object}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.monitorBlockInfo = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ordered map of all monitors, which are MonitorReporter objects.
|
* Ordered map of all monitors, which are MonitorReporter objects.
|
||||||
*/
|
*/
|
||||||
|
@ -225,6 +232,9 @@ class Runtime extends EventEmitter {
|
||||||
// Register all given block packages.
|
// Register all given block packages.
|
||||||
this._registerBlockPackages();
|
this._registerBlockPackages();
|
||||||
|
|
||||||
|
// Populate monitorBlockInfo
|
||||||
|
this._registerMonitorInfo();
|
||||||
|
|
||||||
// Register and initialize "IO devices", containers for processing
|
// Register and initialize "IO devices", containers for processing
|
||||||
// I/O related data.
|
// I/O related data.
|
||||||
/** @type {Object.<string, Object>} */
|
/** @type {Object.<string, Object>} */
|
||||||
|
@ -451,6 +461,22 @@ class Runtime extends EventEmitter {
|
||||||
this.emit(Runtime.EXTENSION_ADDED, categoryInfo.blocks.concat(categoryInfo.menus));
|
this.emit(Runtime.EXTENSION_ADDED, categoryInfo.blocks.concat(categoryInfo.menus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate this.monitorBlockInfo
|
||||||
|
*/
|
||||||
|
_registerMonitorInfo () {
|
||||||
|
for (const packageName in defaultBlockPackages) {
|
||||||
|
if (defaultBlockPackages.hasOwnProperty(packageName)) {
|
||||||
|
// @todo pass a different runtime depending on package privilege?
|
||||||
|
const packageObject = new (defaultBlockPackages[packageName])(this);
|
||||||
|
// Collect monitored from package.
|
||||||
|
if (packageObject.getMonitored) {
|
||||||
|
this.monitorBlockInfo = Object.assign({}, this.monitorBlockInfo, packageObject.getMonitored());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the scratch-blocks JSON for a menu. Note that scratch-blocks treats menus as a special kind of block.
|
* Build the scratch-blocks JSON for a menu. Note that scratch-blocks treats menus as a special kind of block.
|
||||||
* @param {string} menuName - the name of the menu
|
* @param {string} menuName - the name of the menu
|
||||||
|
|
|
@ -575,44 +575,18 @@ class VirtualMachine extends EventEmitter {
|
||||||
* @param {!Blockly.Event} e Any Blockly event.
|
* @param {!Blockly.Event} e Any Blockly event.
|
||||||
*/
|
*/
|
||||||
monitorBlockListener (e) {
|
monitorBlockListener (e) {
|
||||||
const tempMonitoredBlocks = [
|
|
||||||
'volume',
|
|
||||||
'tempo',
|
|
||||||
'answer',
|
|
||||||
'loudness',
|
|
||||||
'videoon',
|
|
||||||
'timer',
|
|
||||||
'of',
|
|
||||||
'current',
|
|
||||||
'username',
|
|
||||||
'xposition',
|
|
||||||
'yposition',
|
|
||||||
'direction',
|
|
||||||
'size',
|
|
||||||
'backdropname',
|
|
||||||
'costumeorder',
|
|
||||||
'backdroporder'
|
|
||||||
];
|
|
||||||
const tempMonitoredPerSpriteBlocks = [
|
|
||||||
'xposition',
|
|
||||||
'yposition',
|
|
||||||
'direction',
|
|
||||||
'size',
|
|
||||||
'costumeorder'
|
|
||||||
];
|
|
||||||
// Filter events by type, since monitor blocks only need to listen to these events.
|
// Filter events by type, since monitor blocks only need to listen to these events.
|
||||||
// Monitor blocks shouldn't be destroyed when flyout blocks are deleted.
|
// Monitor blocks shouldn't be destroyed when flyout blocks are deleted.
|
||||||
if (['create', 'change'].indexOf(e.type) !== -1) {
|
if (['create', 'change'].indexOf(e.type) !== -1) {
|
||||||
// TEMPORARY ----
|
|
||||||
let blockType = e.blockId.split('_');
|
let blockType = e.blockId.split('_');
|
||||||
blockType = blockType[blockType.length - 1];
|
blockType = blockType[blockType.length - 1];
|
||||||
if (tempMonitoredBlocks.indexOf(blockType) === -1) {
|
if (!this.runtime.monitorBlockInfo.hasOwnProperty(blockType)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tempMonitoredPerSpriteBlocks.indexOf(blockType) !== -1) {
|
if (!this.runtime.monitorBlockInfo.hasOwnProperty(blockType) ||
|
||||||
|
this.runtime.monitorBlockInfo[blockType].isSpriteSpecific) {
|
||||||
e.isSpriteSpecific = true;
|
e.isSpriteSpecific = true;
|
||||||
}
|
}
|
||||||
// -----
|
|
||||||
this.runtime.monitorBlocks.blocklyListen(e, this.runtime);
|
this.runtime.monitorBlocks.blocklyListen(e, this.runtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue