From 57c18ad4cc53d5cc9ff46130aedf57e073b6fad1 Mon Sep 17 00:00:00 2001 From: Johnny Oshika Date: Wed, 26 Jul 2023 22:09:49 -0700 Subject: [PATCH 1/3] feat: add skipSerializerRegistration option to workspace-backpack --- plugins/workspace-backpack/src/options.d.ts | 1 + plugins/workspace-backpack/src/options.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/plugins/workspace-backpack/src/options.d.ts b/plugins/workspace-backpack/src/options.d.ts index 0906cdaa24..cddb363899 100644 --- a/plugins/workspace-backpack/src/options.d.ts +++ b/plugins/workspace-backpack/src/options.d.ts @@ -19,6 +19,7 @@ export interface BackpackContextMenuOptions { export interface BackpackOptions { allowEmptyBackpackOpen?: boolean; useFilledBackpackImage?: boolean; + skipSerializerRegistration?: boolean; contextMenu?: BackpackContextMenuOptions; } /** diff --git a/plugins/workspace-backpack/src/options.js b/plugins/workspace-backpack/src/options.js index 008c8d0c02..d73634aa17 100644 --- a/plugins/workspace-backpack/src/options.js +++ b/plugins/workspace-backpack/src/options.js @@ -26,6 +26,7 @@ export let BackpackContextMenuOptions; * @typedef {{ * allowEmptyBackpackOpen: (boolean|undefined), * useFilledBackpackImage: (boolean|undefined), + * skipSerializerRegistration: (boolean|undefined), * contextMenu:(!BackpackContextMenuOptions|undefined) * }} */ @@ -41,6 +42,7 @@ export function parseOptions(options) { const defaults = { allowEmptyBackpackOpen: true, useFilledBackpackImage: false, + skipSerializerRegistration: false, contextMenu: { emptyBackpack: true, removeFromBackpack: true, @@ -60,6 +62,9 @@ export function parseOptions(options) { options.allowEmptyBackpackOpen ?? defaults.allowEmptyBackpackOpen, useFilledBackpackImage: options.useFilledBackpackImage ?? defaults.useFilledBackpackImage, + skipSerializerRegistration: + options.skipSerializerRegistration ?? + defaults.skipSerializerRegistration, contextMenu: { ...defaults.contextMenu, ...options.contextMenu, From c465677dc017bc4197e3240edb12e5f91ee88a1a Mon Sep 17 00:00:00 2001 From: Johnny Oshika Date: Wed, 26 Jul 2023 22:11:13 -0700 Subject: [PATCH 2/3] feat: skip workspace-backpack serializer registration if skipSerializerRegistration option is true --- plugins/workspace-backpack/src/backpack.js | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/workspace-backpack/src/backpack.js b/plugins/workspace-backpack/src/backpack.js index d9633c49fa..474c1a9971 100644 --- a/plugins/workspace-backpack/src/backpack.js +++ b/plugins/workspace-backpack/src/backpack.js @@ -153,6 +153,29 @@ export class Backpack extends Blockly.DragTarget { * @private */ this.SPRITE_SIZE_ = 80; + + this.registerSerializer(); + } + + /** + * Registers serializer if options.skipSerializerRegistration is false + * and it hasn't been registered already. + * @private + */ + registerSerializer() { + if (this.options_.skipSerializerRegistration) { + return; + } + + if (Blockly.registry.hasItem( + Blockly.registry.Type.SERIALIZER, + 'backpack')) { + return; + } + + Blockly.serialization.registry.register( + 'backpack', + new BackpackSerializer()); } /** @@ -890,6 +913,4 @@ class BackpackSerializer { } } -Blockly.serialization.registry.register( - 'backpack', - new BackpackSerializer()); + From acb0b2adda0152168bb5bc25f1aa573501a78a92 Mon Sep 17 00:00:00 2001 From: Johnny Oshika Date: Wed, 26 Jul 2023 21:49:31 -0700 Subject: [PATCH 3/3] docs: update workspace-backpac README with skipSerializerRegistration option --- plugins/workspace-backpack/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/workspace-backpack/README.md b/plugins/workspace-backpack/README.md index 3018bffe6d..68a33d73bd 100644 --- a/plugins/workspace-backpack/README.md +++ b/plugins/workspace-backpack/README.md @@ -47,6 +47,7 @@ This plugin takes an optional configuration object. { allowEmptyBackpackOpen: (boolean|undefined), useFilledBackpackImage: (boolean|undefined), + skipSerializerRegistration: (boolean|undefined), contextMenu: { emptyBackpack: (boolean|undefined), removeFromBackpack: (boolean|undefined), @@ -80,6 +81,7 @@ passed in options that is undefined: const defaultOptions = { allowEmptyBackpackOpen: true, useFilledBackpackImage: false, + skipSerializerRegistration: false, contextMenu: { emptyBackpack: true, removeFromBackpack: true, @@ -97,6 +99,8 @@ being opened if the backpack is empty. The `useFilledBackpackImage` property, if set to `true`, will change the backpack image when the backpack has something in it. +The `skipSerializerRegistration` property, if set to `true`, will not register the backpack serializer with the workspace serializer. Set this to `true` if you don't want the backpack to be serialized alongside the workspace. + The `disablePreconditionChecks` property will prevent the "Copy to Backpack" context menu option from disabling the context menu option if the block is already in the Backpack. Setting this flag to `true` to disable the check can be