scratch-blocks 2.0.0-spork.5 → 2.0.0-spork.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +6 -0
- package/msg/js/en.js +1 -0
- package/msg/json/en.json +2 -1
- package/msg/messages.js +1 -0
- package/msg/scratch_msgs.js +117 -37
- package/package.json +10 -10
- package/src/blocks/sensing.ts +12 -0
- package/src/constants.ts +9 -0
- package/src/index.ts +21 -2
- package/src/renderer/bowler_hat.ts +3 -2
- package/src/renderer/cat/cat_face.ts +226 -0
- package/src/renderer/cat/constants.ts +136 -0
- package/src/renderer/cat/drawer.ts +63 -0
- package/src/renderer/cat/path_object.ts +16 -0
- package/src/renderer/cat/render_info.ts +15 -0
- package/src/renderer/cat/renderer.ts +34 -0
- package/src/renderer/constants.ts +16 -2
- package/src/renderer/drawer.ts +17 -10
- package/src/renderer/path_object.ts +1 -1
- package/src/renderer/render_info.ts +15 -7
- package/src/renderer/renderer.ts +16 -6
- package/CHANGELOG.md +0 -1157
package/src/renderer/drawer.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
8
|
import type { RenderInfo } from "./render_info";
|
|
9
|
+
import { ConstantProvider } from "./constants";
|
|
9
10
|
|
|
10
11
|
export class Drawer extends Blockly.zelos.Drawer {
|
|
12
|
+
constants_: ConstantProvider;
|
|
11
13
|
info_: RenderInfo;
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
override drawStatementInput_(row: Blockly.blockRendering.Row) {
|
|
13
16
|
if (this.info_.isBowlerHatBlock()) {
|
|
14
17
|
// Bowler hat blocks have straight sides with no C-shape/indentation for
|
|
15
18
|
// statement blocks.
|
|
@@ -20,7 +23,7 @@ export class Drawer extends Blockly.zelos.Drawer {
|
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
drawRightSideRow_(row: Blockly.blockRendering.Row) {
|
|
26
|
+
override drawRightSideRow_(row: Blockly.blockRendering.Row) {
|
|
24
27
|
if (
|
|
25
28
|
this.info_.isBowlerHatBlock() &&
|
|
26
29
|
Blockly.blockRendering.Types.isSpacer(row)
|
|
@@ -36,21 +39,25 @@ export class Drawer extends Blockly.zelos.Drawer {
|
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
drawTop_() {
|
|
42
|
+
override drawTop_() {
|
|
40
43
|
super.drawTop_();
|
|
41
44
|
// This is a horrible hack, but the superclass' implementation of drawTop_()
|
|
42
45
|
// provides no way to cleanly override a hat's path without copying and
|
|
43
46
|
// pasting the entire implementation here. We know that there will only be
|
|
44
47
|
// one hat on a block, and its path is a known constant, so we just find and
|
|
45
48
|
// replace it with the desired bowler hat path here.
|
|
46
|
-
// If https://github.com/
|
|
47
|
-
// be revisited.
|
|
48
|
-
|
|
49
|
+
// If https://github.com/RaspberryPiFoundation/blockly/issues/7292 is
|
|
50
|
+
// resolved, this should be revisited.
|
|
51
|
+
const replacementTop = this.makeReplacementTop_();
|
|
52
|
+
if (replacementTop) {
|
|
49
53
|
const capHatPath = this.constants_.START_HAT.path;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
this.outlinePath_ = this.outlinePath_.replace(capHatPath, replacementTop);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
makeReplacementTop_() {
|
|
59
|
+
if (this.info_.isBowlerHatBlock()) {
|
|
60
|
+
return this.constants_.makeBowlerHatPath(this.info_.width);
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
63
|
}
|
|
@@ -17,7 +17,7 @@ export class PathObject extends Blockly.zelos.PathObject {
|
|
|
17
17
|
*
|
|
18
18
|
* @param block The source block.
|
|
19
19
|
*/
|
|
20
|
-
applyColour(block: Blockly.BlockSvg) {
|
|
20
|
+
override applyColour(block: Blockly.BlockSvg) {
|
|
21
21
|
super.applyColour(block);
|
|
22
22
|
|
|
23
23
|
// These blocks are special in that, while they are technically shadow
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Blockly from "blockly/core";
|
|
8
|
+
|
|
8
9
|
import { BowlerHat } from "./bowler_hat";
|
|
10
|
+
import { ConstantProvider } from "./constants";
|
|
9
11
|
|
|
10
12
|
export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
11
|
-
|
|
13
|
+
constants_: ConstantProvider;
|
|
14
|
+
|
|
15
|
+
override populateTopRow_() {
|
|
12
16
|
if (this.isBowlerHatBlock()) {
|
|
13
|
-
const bowlerHat =
|
|
17
|
+
const bowlerHat = this.makeBowlerHat();
|
|
14
18
|
this.topRow.elements.push(
|
|
15
19
|
new Blockly.blockRendering.SquareCorner(this.constants_)
|
|
16
20
|
);
|
|
@@ -25,14 +29,14 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
populateBottomRow_() {
|
|
32
|
+
override populateBottomRow_() {
|
|
29
33
|
super.populateBottomRow_();
|
|
30
34
|
if (this.isBowlerHatBlock()) {
|
|
31
35
|
this.bottomRow.minHeight = this.constants_.MEDIUM_PADDING;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
computeBounds_() {
|
|
39
|
+
override computeBounds_() {
|
|
36
40
|
super.computeBounds_();
|
|
37
41
|
if (this.isBowlerHatBlock()) {
|
|
38
42
|
// Resize the render info to the same width as the widest part of a
|
|
@@ -55,7 +59,7 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
getInRowSpacing_(
|
|
62
|
+
override getInRowSpacing_(
|
|
59
63
|
prev: Blockly.blockRendering.Measurable,
|
|
60
64
|
next: Blockly.blockRendering.Measurable
|
|
61
65
|
): number {
|
|
@@ -71,7 +75,7 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
71
75
|
return super.getInRowSpacing_(prev, next);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
getSpacerRowHeight_(
|
|
78
|
+
override getSpacerRowHeight_(
|
|
75
79
|
prev: Blockly.blockRendering.Row,
|
|
76
80
|
next: Blockly.blockRendering.Row
|
|
77
81
|
): number {
|
|
@@ -82,7 +86,7 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
82
86
|
return super.getSpacerRowHeight_(prev, next);
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
getElemCenterline_(
|
|
89
|
+
override getElemCenterline_(
|
|
86
90
|
row: Blockly.blockRendering.Row,
|
|
87
91
|
elem: Blockly.blockRendering.Measurable
|
|
88
92
|
): number {
|
|
@@ -107,4 +111,8 @@ export class RenderInfo extends Blockly.zelos.RenderInfo {
|
|
|
107
111
|
isBowlerHatBlock() {
|
|
108
112
|
return this.block_.hat === "bowler";
|
|
109
113
|
}
|
|
114
|
+
|
|
115
|
+
makeBowlerHat() {
|
|
116
|
+
return new BowlerHat(this.constants_);
|
|
117
|
+
}
|
|
110
118
|
}
|
package/src/renderer/renderer.ts
CHANGED
|
@@ -14,6 +14,16 @@ import { PathObject } from "./path_object";
|
|
|
14
14
|
* Custom renderer for Scratch-style blocks.
|
|
15
15
|
*/
|
|
16
16
|
export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
17
|
+
/**
|
|
18
|
+
* Get the CSS class name associated with this renderer.
|
|
19
|
+
* Note that all Scratch renderers share the same CSS class name.
|
|
20
|
+
*
|
|
21
|
+
* @returns The class name.
|
|
22
|
+
*/
|
|
23
|
+
override getClassName(): string {
|
|
24
|
+
return "scratch-renderer";
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* Create a new instance of the renderer's drawer.
|
|
19
29
|
*
|
|
@@ -22,7 +32,7 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
22
32
|
* block.
|
|
23
33
|
* @returns The drawer.
|
|
24
34
|
*/
|
|
25
|
-
makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo): Drawer {
|
|
35
|
+
override makeDrawer_(block: Blockly.BlockSvg, info: RenderInfo): Drawer {
|
|
26
36
|
return new Drawer(block, info);
|
|
27
37
|
}
|
|
28
38
|
|
|
@@ -32,7 +42,7 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
32
42
|
* @param block The block to measure.
|
|
33
43
|
* @returns The render info object.
|
|
34
44
|
*/
|
|
35
|
-
makeRenderInfo_(block: Blockly.BlockSvg): RenderInfo {
|
|
45
|
+
override makeRenderInfo_(block: Blockly.BlockSvg): RenderInfo {
|
|
36
46
|
return new RenderInfo(this, block);
|
|
37
47
|
}
|
|
38
48
|
|
|
@@ -41,7 +51,7 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
41
51
|
*
|
|
42
52
|
* @returns The constant provider.
|
|
43
53
|
*/
|
|
44
|
-
makeConstants_(): ConstantProvider {
|
|
54
|
+
override makeConstants_(): ConstantProvider {
|
|
45
55
|
return new ConstantProvider();
|
|
46
56
|
}
|
|
47
57
|
|
|
@@ -52,7 +62,7 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
52
62
|
* @param style The style object to use for colouring.
|
|
53
63
|
* @returns The renderer path object.
|
|
54
64
|
*/
|
|
55
|
-
makePathObject(
|
|
65
|
+
override makePathObject(
|
|
56
66
|
root: SVGElement,
|
|
57
67
|
style: Blockly.Theme.BlockStyle
|
|
58
68
|
): PathObject {
|
|
@@ -65,7 +75,7 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
65
75
|
* @param connection The connection to determine whether or not to highlight.
|
|
66
76
|
* @returns True if we should highlight the connection.
|
|
67
77
|
*/
|
|
68
|
-
shouldHighlightConnection(connection: Blockly.RenderedConnection): boolean {
|
|
78
|
+
override shouldHighlightConnection(connection: Blockly.RenderedConnection): boolean {
|
|
69
79
|
return (
|
|
70
80
|
connection.type === Blockly.ConnectionType.INPUT_VALUE &&
|
|
71
81
|
connection.getCheck()?.includes("Boolean")
|
|
@@ -73,4 +83,4 @@ export class ScratchRenderer extends Blockly.zelos.Renderer {
|
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
Blockly.blockRendering.register("
|
|
86
|
+
Blockly.blockRendering.register("scratch_classic", ScratchRenderer);
|