Register missing broadcasts when importing a sprite - #7
Merged
Conversation
Sprite imports run fixUpVariableReferences to merge or create global variables referenced by the sprite's blocks, but broadcast fields were excluded, so broadcasts from an imported sprite only worked after the editor workspace recreated them. Include BROADCAST_OPTION fields so broadcasts merge with existing same-named ones or get created on the stage, headless included. Fixes #3 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3.
When a sprite is imported (
vm.addSprite),installTargetscallsfixUpVariableReferences()to merge or create any global variables the sprite's blocks reference, but it fetched references without theoptIncludeBroadcastflag, soBROADCAST_OPTIONfields were skipped and the broadcast variable was never created on the stage. Broadcast blocks bail silently whenlookupBroadcastMsgfinds nothing. In the editor, scratch-blocks masks this by creating the variable during workspace load, which is why "see inside" made the project work.The fix passes the broadcast flag so broadcast references flow through the same machinery as variables and lists: a broadcast whose name already exists on the stage gets its block fields re-pointed to the existing variable's id, and a new broadcast is created on the stage under the imported id. The
_broadcastCleanupNeededsweep only deletes broadcasts no block references, so the new ones survive.Compared to the PenguinMod fix linked in the issue, this also handles the
event_whenbroadcastreceivedhat field, merges with existing same-named broadcasts instead of creating duplicates, and covers sprite2 imports.Added a unit test covering both paths (merge with existing broadcast, create missing one);
test/unit/engine_target.jspasses 35/35.🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.