mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Make "when clicked" blocks target dependent.
This involves adding a new opcode, event_whenstageclicked, and adding a method to the blocks container to update the opcode pair depending on whether the target is the stage. This method is then called in two places: first after the sb2 import parses the blocks (not done in the sb2 parsing itself because no other blocks are target specific) and then again when blocks are shared between targets. Also added tests for the block container method, and a fixture project that tests the opcode splitting on sb2 import.
This commit is contained in:
parent
2b985fa083
commit
140094a7ad
8 changed files with 82 additions and 0 deletions
|
@ -593,6 +593,21 @@ class Blocks {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep blocks up to date after they are shared between targets.
|
||||
* @param {boolean} isStage If the new target is a stage.
|
||||
*/
|
||||
updateTargetSpecificBlocks (isStage) {
|
||||
const blocks = this._blocks;
|
||||
for (const blockId in blocks) {
|
||||
if (isStage && blocks[blockId].opcode === 'event_whenthisspriteclicked') {
|
||||
blocks[blockId].opcode = 'event_whenstageclicked';
|
||||
} else if (!isStage && blocks[blockId].opcode === 'event_whenstageclicked') {
|
||||
blocks[blockId].opcode = 'event_whenthisspriteclicked';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update blocks after a sound, costume, or backdrop gets renamed.
|
||||
* Any block referring to the old name of the asset should get updated
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue