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

feat: move backpack to use interface for backpackability #2314

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions plugins/workspace-backpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ Blockly.Msg['EMPTY_BACKPACK'] = 'Opróżnij plecak'; // Polish
- `addBlock`: Adds Block to backpack.
- `addBlocks`: Adds Blocks to backpack.
- `removeBlock`: Removes Block to backpack.
- `containsBlock`: Returns whether the Block is in the backpack.
- `addBackpackable`: Adds Backpackable to backpack.
- `addBackpackables`: Adds Backpackable to backpack.
- `removeBackpackable`: Removes Backpackable to backpack.
- `containsBackpackable`: Returns whether the Backpackable is in the backpack.
- `addItem`: Adds item to backpack.
- `removeItem`: Removes item from the backpack.
- `setContents`: Sets backpack contents.
Expand Down Expand Up @@ -201,6 +206,17 @@ The Backpack Flyout uses the registered Flyout for either
for `Blockly.Trashcan`. If a custom class is registered for either of these
types, then the Backpack Flyout may need to be tested for compatibility.

### Draggables

If you have a custom draggable object, you can make it possible to add it to
the backpack by implementing the [`Backpackable`][backpackable] interface.

This interface requires the draggable to have a method that converts it into
[`FlyoutItemInfo`][flyout-info]. As of 2024-04-08 flyouts only support displaying blocks, buttons, and labels.
BeksOmega marked this conversation as resolved.
Show resolved Hide resolved

## License

Apache 2.0

[flyout-info]: https://developers.google.com/blockly/reference/js/blockly.utils_namespace.toolbox_namespace.flyoutiteminfo_typealias.md
[backpackable]: https://github.com/google/blockly-samples/blob/master/plugins/workspace-backpack/src/backpack.ts
4 changes: 2 additions & 2 deletions plugins/workspace-backpack/src/backpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,12 @@ export class Backpack
}

/**
* @param backpackable The backpackable we want to check for existance within
* @param backpackable The backpackable we want to check for existence within
* the backpack.
* @return whether the backpack contains a duplicate of the provided
* backpackable.
*/
containsBackpackable(backpackable: Backpackable) {
containsBackpackable(backpackable: Backpackable): boolean {
return backpackable
.toFlyoutInfo()
.every((info) => this.contents_.indexOf(JSON.stringify(info)) !== -1);
Expand Down
Loading