Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/blocks/vertical_extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const OUTPUT_BOOLEAN = function (this: Blockly.Block) {
* flyout to toggle display of their current value in a chip on the stage.
*/
const MONITOR_BLOCK = function (this: Blockly.BlockSvg) {
// @ts-ignore
this.addIcon(new FlyoutCheckboxIcon(this));
(this as any).checkboxInFlyout = true;
};
Expand Down
1 change: 1 addition & 0 deletions src/checkbox_bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as Blockly from "blockly/core";
/**
* A checkbox shown next to reporter blocks in the flyout.
*/
// @ts-ignore
export class CheckboxBubble
implements Blockly.IBubble, Blockly.IRenderedElement
{
Expand Down
56 changes: 56 additions & 0 deletions src/colours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,62 @@
import * as Blockly from "blockly/core";

const Colours = {
/* PBEGIN RG ADDITIONS */
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary as scratch-gui expects this properties to exist on ScratchBlocks.Colours

one example:
https://github.com/scratchfoundation/scratch-gui/blob/develop/src/lib/blocks.js#L70

"motion": {
"primary": "#4C97FF",
"secondary": "#4280D7",
"tertiary": "#3373CC",
"quaternary": "#3373CC"
},
"looks": {
"primary": "#9966FF",
"secondary": "#855CD6",
"tertiary": "#774DCB",
"quaternary": "#774DCB"
},
"sounds": {
"primary": "#CF63CF",
"secondary": "#C94FC9",
"tertiary": "#BD42BD",
"quaternary": "#BD42BD"
},
"control": {
"primary": "#FFAB19",
"secondary": "#EC9C13",
"tertiary": "#CF8B17",
"quaternary": "#CF8B17"
},
"event": {
"primary": "#FFBF00",
"secondary": "#E6AC00",
"tertiary": "#CC9900",
"quaternary": "#CC9900"
},
"sensing": {
"primary": "#5CB1D6",
"secondary": "#47A8D1",
"tertiary": "#2E8EB8",
"quaternary": "#2E8EB8"
},
"pen": {
"primary": "#0fBD8C",
"secondary": "#0DA57A",
"tertiary": "#0B8E69",
"quaternary": "#0B8E69"
},
"operators": {
"primary": "#59C059",
"secondary": "#46B946",
"tertiary": "#389438",
"quaternary": "#389438"
},
"data": {
"primary": "#FF8C1A",
"secondary": "#FF8000",
"tertiary": "#DB6E00",
"quaternary": "#DB6E00"
},
/** END PRG ADDITION */
// SVG colours: these must be specified in #RRGGBB style
// To add an opacity, this must be specified as a separate property (for SVG fill-opacity)
text: "#FFFFFF",
Expand Down
2 changes: 2 additions & 0 deletions src/fields/field_colour_slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class FieldColourSlider extends FieldColour {

Blockly.DropDownDiv.setColour("#ffffff", "#dddddd");
Blockly.DropDownDiv.showPositionedByBlock(
// @ts-ignore
this,
this.getSourceBlock() as Blockly.BlockSvg
);
Expand Down Expand Up @@ -395,5 +396,6 @@ export class FieldColourSlider extends FieldColour {
* Register the field and any dependencies.
*/
export function registerFieldColourSlider() {
// @ts-ignore
Blockly.fieldRegistry.register("field_colour_slider", FieldColourSlider);
}
1 change: 1 addition & 0 deletions src/flyout_checkbox_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class FlyoutCheckboxIcon
}
}

// @ts-ignore
getType(): Blockly.icons.IconType<FlyoutCheckboxIcon> {
return this.type;
}
Expand Down
19 changes: 17 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* BEGIN RG ADDITION */
export * from "./colours";
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary as there's lots of places ScratchBlocks.Colours is referenced:

(one example)
https://github.com/scratchfoundation/scratch-gui/blob/develop/src/lib/blocks.js#L70

/* END RG ADDITION */

import * as Blockly from "blockly/core";
import "./blocks/colour";
import "./blocks/math";
Expand All @@ -20,7 +24,13 @@ import "./blocks/operators";
import "./blocks/procedures";
import "./blocks/sensing";
import "./blocks/sound";
import * as scratchBlocksUtils from "./scratch_blocks_utils";
/* BEGIN RG ADDITION */
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary because the scratch-gui code wants to overwrite the compareStrings method:

https://github.com/scratchfoundation/scratch-gui/blob/develop/src/lib/blocks.js#L344

import * as scratchBlocksUtilsModule from "./scratch_blocks_utils";
const scratchBlocksUtils = {
...scratchBlocksUtilsModule,
}
export { scratchBlocksUtils };
/* END RG ADDITION */
import * as ScratchVariables from "./variables";
import "./css";
import "./renderer/renderer";
Expand Down Expand Up @@ -70,7 +80,6 @@ export * from "./procedures";
export * from "../msg/scratch_msgs.js";
export * from "./constants";
export { glowStack };
export { scratchBlocksUtils };
export { CheckableContinuousFlyout };
export { ScratchVariables };
export { contextMenuItems };
Expand All @@ -81,6 +90,11 @@ export {
StatusButtonState,
} from "./status_indicator_label";

/* BEGIN RG ADDITION */
import { StatusIndicatorLabel } from "./status_indicator_label";
export { StatusIndicatorLabel as FlyoutExtensionCategoryHeader };
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary as scratch-gui expects for FlyoutExtensionCategoryHeader to be defined on ScratchBlocks. However, I don't know if the StatusIndicatorLabel actually corresponds to the FlyoutExtensionCategoryHeader.. they just both have a getExtensionState method, which is what the scratch-gui wants to interact with.

https://github.com/scratchfoundation/scratch-gui/blob/develop/src/lib/blocks.js#L326

/* END RG ADDITION */

export function inject(container: Element, options: Blockly.BlocklyOptions) {
registerScratchFieldAngle();
registerFieldColourSlider();
Expand All @@ -105,6 +119,7 @@ export function inject(container: Element, options: Blockly.BlocklyOptions) {
metricsManager: ContinuousMetrics,
},
});

const workspace = Blockly.inject(container, options);

buildGlowFilter(workspace);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export class ConstantProvider extends Blockly.zelos.ConstantProvider {
} else {
const style = {
colourPrimary:
"colourQuaternary" in colour
"colourQuaternary" in colour && Boolean(colour.colourQuaternary)
Copy link
Author

Choose a reason for hiding this comment

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

Without these checks, I'd get lots of Invalid colour: "undefined" errors. But is this code correct, @gonfunko ? As it just seems a little odd to be defining Primary Secondary and Tertiary always first trying to use the Quaternary setting..

? `${colour.colourQuaternary}`
: colour.colourTertiary,
colourSecondary:
"colourQuaternary" in colour
"colourQuaternary" in colour && Boolean(colour.colourQuaternary)
? `${colour.colourQuaternary}`
: colour.colourTertiary,
colourTertiary:
"colourQuaternary" in colour
"colourQuaternary" in colour && Boolean(colour.colourQuaternary)
? `${colour.colourQuaternary}`
: colour.colourTertiary,
colourQuaternary:
"colourQuaternary" in colour
"colourQuaternary" in colour && Boolean(colour.colourQuaternary)
? `${colour.colourQuaternary}`
: colour.colourTertiary,
hat: "",
Expand Down
1 change: 1 addition & 0 deletions src/scratch_block_paster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ScratchBlockPaster extends Blockly.clipboard.BlockPaster {
// been turned off) if needed.
const commentIcon = block.getIcon(Blockly.icons.IconType.COMMENT);
if (commentIcon) {
// @ts-ignore
(commentIcon as ScratchCommentIcon).fireCreateEvent();
}

Expand Down
1 change: 1 addition & 0 deletions src/scratch_comment_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface CommentState {
/**
* Custom comment icon that draws no icon indicator, used for block comments.
*/
// @ts-ignore
export class ScratchCommentIcon
extends Blockly.icons.Icon
implements Blockly.ISerializable, Blockly.IHasBubble
Expand Down
1 change: 1 addition & 0 deletions src/status_indicator_label_flyout_inflater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class StatusIndicatorLabelFlyoutInflater extends Blockly.LabelFlyoutInflater {
* label on.
* @returns The newly created status indicator label.
*/
// @ts-ignore
load(
state: Blockly.utils.toolbox.LabelInfo,
flyout: Blockly.IFlyout
Expand Down