@@ -3,8 +3,9 @@ class_name BlockCanvas
3
3
extends MarginContainer
4
4
5
5
const EXTEND_MARGIN : float = 800
6
- const BLOCK_AUTO_PLACE_MARGIN : Vector2 = Vector2 (16 , 8 )
7
- const DEFAULT_WINDOW_MARGIN : Vector2 = Vector2 (24 , 24 )
6
+ const BLOCK_AUTO_PLACE_MARGIN : Vector2 = Vector2 (25 , 8 )
7
+ const DEFAULT_WINDOW_MARGIN : Vector2 = Vector2 (25 , 25 )
8
+ const SNAP_GRID : Vector2 = Vector2 (25 , 25 )
8
9
const ZOOM_FACTOR : float = 1.1
9
10
10
11
@onready var _window : Control = % Window
@@ -27,6 +28,7 @@ const ZOOM_FACTOR: float = 1.1
27
28
@onready var _mouse_override : Control = % MouseOverride
28
29
@onready var _zoom_label : Label = % ZoomLabel
29
30
31
+ var _current_bsd : BlockScriptData
30
32
var _block_scenes_by_class = {}
31
33
var _panning := false
32
34
var zoom : float :
@@ -59,7 +61,11 @@ func _populate_block_scenes_by_class():
59
61
60
62
61
63
func add_block (block : Block , position : Vector2 = Vector2 .ZERO ) -> void :
62
- block .position = canvas_to_window (position )
64
+ if block is EntryBlock :
65
+ block .position = canvas_to_window (position ).snapped (SNAP_GRID )
66
+ else :
67
+ block .position = canvas_to_window (position )
68
+
63
69
_window .add_child (block )
64
70
65
71
@@ -74,7 +80,9 @@ func get_blocks() -> Array[Block]:
74
80
75
81
func arrange_block (block : Block , nearby_block : Block ) -> void :
76
82
add_block (block )
77
- block .global_position = (nearby_block .global_position + (nearby_block .get_size () * Vector2 .RIGHT ) + BLOCK_AUTO_PLACE_MARGIN )
83
+ var rect = nearby_block .get_global_rect ()
84
+ rect .position += (rect .size * Vector2 .RIGHT ) + BLOCK_AUTO_PLACE_MARGIN
85
+ block .global_position = rect .position
78
86
79
87
80
88
func set_child (n : Node ):
@@ -105,7 +113,9 @@ func bsd_selected(bsd: BlockScriptData):
105
113
_load_bsd (bsd )
106
114
_window .visible = true
107
115
_zoom_label .visible = true
108
- reset_window_position ()
116
+
117
+ if bsd != _current_bsd :
118
+ reset_window_position ()
109
119
elif edited_node == null :
110
120
_empty_box .visible = true
111
121
elif BlockCodePlugin .node_has_block_code (edited_node ):
@@ -123,6 +133,8 @@ func bsd_selected(bsd: BlockScriptData):
123
133
_selected_node_label .text = _selected_node_label_format .format ({"node" : edited_node .name })
124
134
_add_block_code_button .disabled = false
125
135
136
+ _current_bsd = bsd
137
+
126
138
127
139
func _load_bsd (bsd : BlockScriptData ):
128
140
for tree in bsd .block_trees .array :
0 commit comments