-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshaped-renderer.js
More file actions
149 lines (145 loc) · 5.07 KB
/
shaped-renderer.js
File metadata and controls
149 lines (145 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class ShapedConstantsProvider extends Blockly.blockRendering.ConstantProvider {
constructor() {
super()
this.SET_PATH = this.setPath()
this.LOGIC_PATH = this.logicPath()
this.NUMBER_PATH = this.numberPath()
this.FUNCTION_PATH = this.functionPath()
this.SQUARE_PATH = this.squarePath()
}
shapeFor(connection) {
const checks = connection.getCheck();
switch (connection.type) {
case Blockly.INPUT_VALUE:
case Blockly.OUTPUT_VALUE:
switch (checks.join()) {
case "Set":
return this.SET_PATH
case "Boolean":
return this.LOGIC_PATH
case "Number":
return this.NUMBER_PATH
case "Set,Number":
case "Number,Set":
return this.SQUARE_PATH
}
return this.LOGIC_PATH;
case Blockly.PREVIOUS_STATEMENT:
case Blockly.NEXT_STATEMENT:
if (checks) {
switch (checks[0]) {
case "FunctionElement":
return this.FUNCTION_PATH
}
}
return this.NOTCH;
default:
throw Error('Unknown type');
}
}
setPath() {
// Modify
const offsetFactor = 0.2
const pointWeight = 1
const edgeWeight = 0
// Don't modify
const offset = offsetFactor * this.TAB_WIDTH
const bracketWidth = (1 - offsetFactor) * this.TAB_WIDTH
let path = (shape) => {
return (
Blockly.utils.svgPaths.line([
Blockly.utils.svgPaths.point(-offset, 0)
]) +
Blockly.utils.svgPaths.curve("c", [
Blockly.utils.svgPaths.point(-bracketWidth, edgeWeight * (this.TAB_HEIGHT / 5) * shape),
Blockly.utils.svgPaths.point(bracketWidth * (pointWeight - 1), (this.TAB_HEIGHT / 2) * shape),
Blockly.utils.svgPaths.point(-bracketWidth, (this.TAB_HEIGHT / 2) * shape)
]) +
Blockly.utils.svgPaths.curve("c", [
Blockly.utils.svgPaths.point(bracketWidth * pointWeight, 0),
Blockly.utils.svgPaths.point(0, (2 - edgeWeight) * (this.TAB_HEIGHT / 5) * shape),
Blockly.utils.svgPaths.point(bracketWidth, (this.TAB_HEIGHT / 2) * shape)
]) +
Blockly.utils.svgPaths.line([
Blockly.utils.svgPaths.point(offset, 0)
])
)
}
return {
width: this.TAB_WIDTH,
height: this.TAB_HEIGHT,
pathDown: path(1),
pathUp: path(-1)
}
}
logicPath() {
let path = (shape) => {
return (
Blockly.utils.svgPaths.lineTo(-this.TAB_WIDTH, this.TAB_HEIGHT / 2 * shape) +
Blockly.utils.svgPaths.lineTo(this.TAB_WIDTH, this.TAB_HEIGHT / 2 * shape)
)
}
return {
width: this.TAB_WIDTH,
height: this.TAB_HEIGHT,
pathDown: path(1),
pathUp: path(-1)
}
}
numberPath() {
let path = (shape) => {
return (
"a " + (this.TAB_WIDTH) + " " + (this.TAB_HEIGHT / 2) + " 0 0 " + (shape == -1 ? "1" : "0") + " 0 " + (1.9 * this.TAB_WIDTH * shape) // because the function for it is shite
)
}
return {
width: this.TAB_WIDTH,
height: this.TAB_HEIGHT,
pathDown: path(1),
pathUp: path(-1)
}
}
functionPath() {
let path = (shape) => {
return (
Blockly.utils.svgPaths.line([
Blockly.utils.svgPaths.point(0, this.NOTCH_HEIGHT),
Blockly.utils.svgPaths.point(this.NOTCH_WIDTH * shape, 0),
Blockly.utils.svgPaths.point(0, -this.NOTCH_HEIGHT)
])
)
}
return {
type: this.SHAPES.NOTCH,
width: this.NOTCH_WIDTH,
height: this.NOTCH_HEIGHT,
pathLeft: path(1),
pathRight: path(-1)
}
}
squarePath() {
let path = (shape) => {
return Blockly.utils.svgPaths.line([
Blockly.utils.svgPaths.point(-this.TAB_WIDTH, 0),
Blockly.utils.svgPaths.point(0, this.TAB_HEIGHT * shape),
Blockly.utils.svgPaths.point(this.TAB_WIDTH, 0)
])
}
return {
width: this.TAB_WIDTH,
height: this.TAB_HEIGHT,
pathDown: path(1),
pathUp: path(-1)
}
}
}
class ShapedRenderer extends Blockly.thrasos.Renderer {
constructor(name) {
super(name);
}
makeConstants_() {
return new ShapedConstantsProvider();
}
};
Blockly.blockRendering.register('shaped_renderer', ShapedRenderer);
console.log("Renderer registered")