Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sprite Lab] add behaviorPicker block and field type #50702

Merged
merged 7 commits into from
Mar 15, 2023

Conversation

mikeharv
Copy link
Contributor

@mikeharv mikeharv commented Mar 10, 2023

Context and Request

In Sprite Lab, students have to open the toolbox multiple times to set up a behavior-related command. It is only possible to switch behaviors by deleting a block and dragging out a new one.
image

The curriculum team would like to streamline this process by using a pre-populated dropdown, similar to the experience in Poetry:
image
We cannot simply copy this block into the GameLabJr pool. This is because the behavior list in Poetry is hard-coded. (In Poetry, students cannot edit/add/delete behaviors.)
Because Sprite Lab has a higher ceiling, the desired block requires a new field that can dynamically look for all behaviors and auto-populate the dropdown. It also needs to be linked up to the modal function editor.

How it works

The new block works (and generates JavaScript code) just like the existing behavior blocks.
imageimageimage

In a typical use case, the dropdown will be populated with options based on all behaviors that defined in the main workspace, including shared behaviors and user-created behaviors.

bp1-standard.use.mp4

If the modal function editor is enabled, the block also includes an edit button that will open the BehaviorEditor with the selected behavior option. There is also a "Create new behavior" option that will open the editor with a new blank behavior that is immediately added to the dropdown and selected using the name chosen by the user.

bp2-modal.mp4

If the modal editor is disabled, we do not show the button or the option to create a new behavior. It is not possible to create new behaviors using this block under this scenario, nor is it possible through other means.
image

If there are no behaviors currently defined on the workspace we will either show the option to create one (modal editor enabled) or an option that simply generated undefined (no modal). This is possible within a level; it's also the normal expectation when viewing the block in a levelbuilder context, such as on the edit and index pages for the GameLabJr block pool.
image
image
imageimage

Blocks in a read-only workspace such as the level instructions will not find any behaviors to populate the list, however a levelbuilder can still list whatever behavior they want by specifying it directly in the block XML. This is similar to the process of customizing the default option in start blocks or a toolbox.
image
image

While workspace-defined behaviors are currently unsupported in Sprite Lab (or Poetry) using Google Blockly, the new block still renders and generates code correctly. Shown here in a Poetry project:
image
image

To work correctly with the modal Function Editor, this feature also requires an update to our CDO Blockly repo.

When the name of a behavior is changed in the modal editor, we need to find each gamelab_behaviorPicker block and detect whether it is selected the current behavior. For user-created behaviors, the behavior name and id are interchangeable and therefore we must update the selected option with the new id. For shared behaviors, the ids are locked. Updating the selected option to use the current id ensures that the user will see the edited behavior name as the dropdown option label. Other blocks should not be touched.

bp3-rename.mp4

If a user-created behavior is deleted, we detected blocks that are selecting that behavior and update them to show the undefined (Create new behavior) option.

bp4-delete.mp4

Links

Jira: https://codedotorg.atlassian.net/browse/SL-643

Testing story

Deployment strategy

This PR requires a change to the Blockly repo. It should be merged alongside a bump to the Blockly version in this repo.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@mikeharv mikeharv marked this pull request as ready for review March 13, 2023 21:34
@mikeharv mikeharv requested a review from a team as a code owner March 13, 2023 21:34
@mikeharv mikeharv requested a review from a team March 13, 2023 21:48
Copy link
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (pending blockly changes)

@mikeharv mikeharv merged commit ba320f5 into staging Mar 15, 2023
@mikeharv mikeharv deleted the mike/behavior-dropdown-block branch March 15, 2023 13:07
@mikeharv mikeharv changed the title [Sprite Lab] add backgroundPicker block and field type [Sprite Lab] add behaviorPicker block and field type Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants