Skip to content

Commit 626ab89

Browse files
committed
Move DragManager.get_tree_scope to InstructionTree
This static function has nothing to do with the DragManager class since it's simply walking a tree of Nodes and looking for a Block that has a non-empty scope property set. I'm not sure it really fits in InstructionTree either, but that's a better fit at least. This avoids some dependency issues between DragManager, its inner Drag class, and BlockCanvas. https://phabricator.endlessm.com/T35494
1 parent f3cbacb commit 626ab89

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

addons/block_code/drag_manager/drag.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extends Control
33

44
const BlockCanvas = preload("res://addons/block_code/ui/block_canvas/block_canvas.gd")
55
const Constants = preload("res://addons/block_code/ui/constants.gd")
6-
const DragManager = preload("res://addons/block_code/drag_manager/drag_manager.gd")
6+
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
77
const Types = preload("res://addons/block_code/types/types.gd")
88

99
enum DragAction { NONE, PLACE, REMOVE }
@@ -142,7 +142,7 @@ func _snaps_to(node: Node) -> bool:
142142
if _block_scope != top_block.get_entry_statement():
143143
return false
144144
elif top_block:
145-
var tree_scope := DragManager.get_tree_scope(top_block)
145+
var tree_scope := InstructionTree.get_tree_scope(top_block)
146146
if tree_scope != "" and _block_scope != tree_scope:
147147
return false
148148

addons/block_code/drag_manager/drag_manager.gd

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ signal block_modified
66

77
const BlockCanvas = preload("res://addons/block_code/ui/block_canvas/block_canvas.gd")
88
const Drag = preload("res://addons/block_code/drag_manager/drag.gd")
9+
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
910
const Picker = preload("res://addons/block_code/ui/picker/picker.gd")
1011

1112
@export var picker_path: NodePath
@@ -49,7 +50,7 @@ func drag_block(block: Block, copied_from: Block = null):
4950

5051
block.disconnect_signals()
5152

52-
var block_scope := get_tree_scope(block)
53+
var block_scope := InstructionTree.get_tree_scope(block)
5354
if block_scope != "":
5455
_block_canvas.set_scope(block_scope)
5556

@@ -92,16 +93,3 @@ func connect_block_canvas_signals(block: Block):
9293
block.drag_started.connect(drag_block)
9394
if block.modified.get_connections().size() == 0:
9495
block.modified.connect(func(): block_modified.emit())
95-
96-
97-
## Returns the scope of the first non-empty scope child block
98-
static func get_tree_scope(node: Node) -> String:
99-
if node is Block:
100-
if node.scope != "":
101-
return node.scope
102-
103-
for c in node.get_children():
104-
var scope := get_tree_scope(c)
105-
if scope != "":
106-
return scope
107-
return ""

addons/block_code/instruction_tree/instruction_tree.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,16 @@ static func _generate_script_from_entry_blocks(entry_statement: String, entry_bl
120120
script += "\tpass\n\n"
121121

122122
return script
123+
124+
125+
## Returns the scope of the first non-empty scope child block
126+
static func get_tree_scope(node: Node) -> String:
127+
if node is Block:
128+
if node.scope != "":
129+
return node.scope
130+
131+
for c in node.get_children():
132+
var scope := get_tree_scope(c)
133+
if scope != "":
134+
return scope
135+
return ""

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func set_scope(scope: String):
218218
if scope == block.get_entry_statement():
219219
valid = true
220220
else:
221-
var tree_scope := DragManager.get_tree_scope(block)
221+
var tree_scope := InstructionTree.get_tree_scope(block)
222222
if tree_scope == "" or scope == tree_scope:
223223
valid = true
224224

0 commit comments

Comments
 (0)