-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental Lily/AllMenus extension (#510)
- Loading branch information
1 parent
859808e
commit a4291f5
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(function (Scratch) { | ||
'use strict'; | ||
|
||
var blockXML; | ||
const blacklist = ['looks_costumenumbername', 'extension_wedo_tilt_menu']; | ||
|
||
Scratch.vm.addListener('BLOCKSINFO_UPDATE', refreshMenus); | ||
|
||
function refreshMenus() { | ||
if (!window.ScratchBlocks) return; | ||
Scratch.vm.removeListener('BLOCKSINFO_UPDATE', refreshMenus); | ||
|
||
let allBlocks = Object.keys(ScratchBlocks.Blocks); | ||
|
||
allBlocks = allBlocks.filter( | ||
item => item.includes('menu') && | ||
!blacklist.includes(item) | ||
); | ||
|
||
const menuBlocks = allBlocks.map( | ||
item => '<block id="' + item + '" type="' + item + '"/>' | ||
); | ||
|
||
blockXML = menuBlocks.join(''); | ||
Scratch.vm.runtime.extensionManager.refreshBlocks(); | ||
} | ||
|
||
class AllMenus { | ||
constructor () { | ||
Scratch.vm.runtime.on('EXTENSION_ADDED', () => { | ||
refreshMenus(); | ||
}); | ||
} | ||
|
||
getInfo() { | ||
return { | ||
id: 'lmsAllMenus', | ||
name: 'All Menus', | ||
blocks: [ | ||
{ | ||
blockType: Scratch.BlockType.XML, | ||
xml: blockXML | ||
} | ||
] | ||
}; | ||
} | ||
} | ||
|
||
refreshMenus(); | ||
|
||
Scratch.extensions.register(new AllMenus()); | ||
})(Scratch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters