mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-24 21:19:43 -04:00
add category info to extension add & update events
This commit is contained in:
parent
833d33355c
commit
bd1aaecdf3
3 changed files with 9 additions and 14 deletions
|
@ -787,11 +787,9 @@ class Runtime extends EventEmitter {
|
|||
|
||||
this._fillExtensionCategory(categoryInfo, extensionInfo);
|
||||
|
||||
const fieldTypeDefinitionsForScratch = [];
|
||||
for (const fieldTypeName in categoryInfo.customFieldTypes) {
|
||||
if (extensionInfo.customFieldTypes.hasOwnProperty(fieldTypeName)) {
|
||||
const fieldTypeInfo = categoryInfo.customFieldTypes[fieldTypeName];
|
||||
fieldTypeDefinitionsForScratch.push(fieldTypeInfo.scratchBlocksDefinition);
|
||||
|
||||
// Emit events for custom field types from extension
|
||||
this.emit(Runtime.EXTENSION_FIELD_ADDED, {
|
||||
|
@ -801,9 +799,7 @@ class Runtime extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
const allBlocks = fieldTypeDefinitionsForScratch.concat(categoryInfo.blocks).concat(categoryInfo.menus);
|
||||
|
||||
this.emit(Runtime.EXTENSION_ADDED, allBlocks);
|
||||
this.emit(Runtime.EXTENSION_ADDED, categoryInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -812,18 +808,16 @@ class Runtime extends EventEmitter {
|
|||
* @private
|
||||
*/
|
||||
_refreshExtensionPrimitives (extensionInfo) {
|
||||
let extensionBlocks = [];
|
||||
for (const categoryInfo of this._blockInfo) {
|
||||
if (extensionInfo.id === categoryInfo.id) {
|
||||
categoryInfo.name = maybeFormatMessage(extensionInfo.name);
|
||||
categoryInfo.blocks = [];
|
||||
categoryInfo.menus = [];
|
||||
this._fillExtensionCategory(categoryInfo, extensionInfo);
|
||||
extensionBlocks = extensionBlocks.concat(categoryInfo.blocks, categoryInfo.menus);
|
||||
|
||||
this.emit(Runtime.BLOCKSINFO_UPDATE, categoryInfo);
|
||||
}
|
||||
}
|
||||
|
||||
this.emit(Runtime.BLOCKSINFO_UPDATE, extensionBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,14 +109,14 @@ class VirtualMachine extends EventEmitter {
|
|||
this.runtime.on(Runtime.BLOCK_DRAG_END, (blocks, topBlockId) => {
|
||||
this.emit(Runtime.BLOCK_DRAG_END, blocks, topBlockId);
|
||||
});
|
||||
this.runtime.on(Runtime.EXTENSION_ADDED, blocksInfo => {
|
||||
this.emit(Runtime.EXTENSION_ADDED, blocksInfo);
|
||||
this.runtime.on(Runtime.EXTENSION_ADDED, categoryInfo => {
|
||||
this.emit(Runtime.EXTENSION_ADDED, categoryInfo);
|
||||
});
|
||||
this.runtime.on(Runtime.EXTENSION_FIELD_ADDED, (fieldName, fieldImplementation) => {
|
||||
this.emit(Runtime.EXTENSION_FIELD_ADDED, fieldName, fieldImplementation);
|
||||
});
|
||||
this.runtime.on(Runtime.BLOCKSINFO_UPDATE, blocksInfo => {
|
||||
this.emit(Runtime.BLOCKSINFO_UPDATE, blocksInfo);
|
||||
this.runtime.on(Runtime.BLOCKSINFO_UPDATE, categoryInfo => {
|
||||
this.emit(Runtime.BLOCKSINFO_UPDATE, categoryInfo);
|
||||
});
|
||||
this.runtime.on(Runtime.BLOCKS_NEED_UPDATE, () => {
|
||||
this.emitWorkspaceUpdate();
|
||||
|
|
|
@ -160,7 +160,8 @@ const testLoop = function (t, loop) {
|
|||
test('registerExtensionPrimitives', t => {
|
||||
const runtime = new Runtime();
|
||||
|
||||
runtime.on(Runtime.EXTENSION_ADDED, blocksInfo => {
|
||||
runtime.on(Runtime.EXTENSION_ADDED, categoryInfo => {
|
||||
const blocksInfo = categoryInfo.blocks;
|
||||
t.equal(blocksInfo.length, testExtensionInfo.blocks.length);
|
||||
|
||||
blocksInfo.forEach(blockInfo => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue