@@ -23,6 +23,10 @@ var parent_block: Block
2323@export var control_part : ControlPart = ControlPart .TOP :
2424 set = _set_control_part
2525
26+ ## Only relevant if block_type is VALUE.
27+ @export var is_pointy_value : bool = false :
28+ set = _set_is_pointy_value
29+
2630
2731func _set_color (new_color ):
2832 color = new_color
@@ -40,6 +44,11 @@ func _set_control_part(new_control_part):
4044 queue_redraw ()
4145
4246
47+ func _set_is_pointy_value (new_is_pointy_value ):
48+ is_pointy_value = new_is_pointy_value
49+ queue_redraw ()
50+
51+
4352func _ready ():
4453 parent_block = BlockTreeUtil .get_parent_block (self )
4554 parent_block .focus_entered .connect (queue_redraw )
@@ -77,9 +86,29 @@ func _get_knob_shape(displacement: Vector2 = Vector2.ZERO) -> PackedVector2Array
7786
7887func _get_entry_shape () -> PackedVector2Array :
7988 var box_shape = _get_box_shape (size )
89+ var ellipsis = PackedVector2Array (
90+ [
91+ Vector2 (5 , - 4.012612 ),
92+ Vector2 (10 , - 7.240165 ),
93+ Vector2 (15 , - 9.822201 ),
94+ Vector2 (20 , - 11.84718 ),
95+ Vector2 (25 , - 13.37339 ),
96+ Vector2 (30 , - 14.43944 ),
97+ Vector2 (35 , - 15.06994 ),
98+ Vector2 (40 , - 15.27864 ),
99+ Vector2 (45 , - 15.06994 ),
100+ Vector2 (50 , - 14.43944 ),
101+ Vector2 (55 , - 13.37339 ),
102+ Vector2 (60 , - 11.84718 ),
103+ Vector2 (65 , - 9.822201 ),
104+ Vector2 (70 , - 7.240165 ),
105+ Vector2 (75 , - 4.012612 ),
106+ Vector2 (80 , 0 ),
107+ ]
108+ )
80109 var bottom_knob_shape = _get_knob_shape (Vector2 (Constants .KNOB_X , size .y ))
81110 bottom_knob_shape .reverse ()
82- return box_shape .slice (0 , 3 ) + bottom_knob_shape + box_shape .slice (3 )
111+ return box_shape .slice (0 , 1 ) + ellipsis + box_shape . slice ( 1 , 3 ) + bottom_knob_shape + box_shape .slice (3 )
83112
84113
85114func _get_statement_shape () -> PackedVector2Array :
@@ -90,6 +119,73 @@ func _get_statement_shape() -> PackedVector2Array:
90119 return box_shape .slice (0 , 1 ) + top_knob_shape + box_shape .slice (1 , 3 ) + bottom_knob_shape + box_shape .slice (3 )
91120
92121
122+ # Note: This is a especial case of _get_round_value_shape() with resolution = 2,
123+ # but it's easier this way.
124+ func _get_pointy_value_shape () -> PackedVector2Array :
125+ var radius_x = min (size .x , size .y ) / 2
126+ var radius_y = max (radius_x , size .y / 2 )
127+ return PackedVector2Array (
128+ [
129+ Vector2 (radius_x , 0 ),
130+ Vector2 (size .x - radius_x , 0 ),
131+ Vector2 (size .x , radius_y ),
132+ Vector2 (size .x - radius_x , size .y ),
133+ Vector2 (radius_x , size .y ),
134+ Vector2 (0 , radius_y ),
135+ Vector2 (radius_x , 0 ),
136+ ]
137+ )
138+
139+
140+ func _get_round_value_shape () -> PackedVector2Array :
141+ # Normally radius_y will be equal to radius_x. But if the block is more vertical
142+ # than horizontal, we'll have to deform the arc shapes.
143+ var radius_x = min (size .x , size .y ) / 2
144+ var radius_y = max (radius_x , size .y / 2 )
145+
146+ var right_arc = []
147+ for i in range (Constants .ROUND_RESOLUTION ):
148+ var angle = - PI / 2 + PI * i / Constants .ROUND_RESOLUTION
149+ (
150+ right_arc
151+ . append (
152+ Vector2 (
153+ cos (angle ) * radius_x + size .x - radius_x ,
154+ (sin (angle ) + 1 ) * radius_y ,
155+ )
156+ )
157+ )
158+ var left_arc = []
159+ for i in range (Constants .ROUND_RESOLUTION ):
160+ var angle = PI / 2 + PI * i / Constants .ROUND_RESOLUTION
161+ (
162+ left_arc
163+ . append (
164+ Vector2 (
165+ (cos (angle ) + 1 ) * radius_x ,
166+ (sin (angle ) + 1 ) * radius_y ,
167+ )
168+ )
169+ )
170+ return PackedVector2Array (
171+ (
172+ [
173+ Vector2 (radius_x , 0 ),
174+ Vector2 (size .x - radius_x , 0 ),
175+ ]
176+ + right_arc
177+ + [
178+ Vector2 (size .x - radius_x , size .y ),
179+ Vector2 (radius_x , size .y ),
180+ ]
181+ + left_arc
182+ + [
183+ Vector2 (radius_x , 0 ),
184+ ]
185+ )
186+ )
187+
188+
93189func _get_control_top_fill_shape () -> PackedVector2Array :
94190 var box_shape = _get_box_shape (size )
95191 var top_knob_shape = _get_knob_shape (Vector2 (Constants .KNOB_X , 0.0 ))
@@ -131,6 +227,14 @@ func _draw():
131227 var shape = _get_statement_shape ()
132228 fill_polygon = shape
133229 stroke_polygon = shape
230+ Types .BlockType .VALUE :
231+ var shape
232+ if is_pointy_value :
233+ shape = _get_pointy_value_shape ()
234+ else :
235+ shape = _get_round_value_shape ()
236+ fill_polygon = shape
237+ stroke_polygon = shape
134238 Types .BlockType .CONTROL :
135239 if control_part == ControlPart .TOP :
136240 fill_polygon = _get_control_top_fill_shape ()
0 commit comments