Skip to content

Commit 29ab2ef

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 9dd0b11 commit 29ab2ef

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

addons/block_code/drag_manager/drag_manager.gd

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Drag:
141141
if _block_scope != top_block.get_entry_statement():
142142
return false
143143
elif top_block:
144-
var tree_scope := DragManager.get_tree_scope(top_block)
144+
var tree_scope := InstructionTree.get_tree_scope(top_block)
145145
if tree_scope != "" and _block_scope != tree_scope:
146146
return false
147147

@@ -230,7 +230,7 @@ func drag_block(block: Block, copied_from: Block = null):
230230

231231
block.disconnect_signals()
232232

233-
var block_scope := get_tree_scope(block)
233+
var block_scope := InstructionTree.get_tree_scope(block)
234234
if block_scope != "":
235235
_block_canvas.set_scope(block_scope)
236236

@@ -273,16 +273,3 @@ func connect_block_canvas_signals(block: Block):
273273
block.drag_started.connect(drag_block)
274274
if block.modified.get_connections().size() == 0:
275275
block.modified.connect(func(): block_modified.emit())
276-
277-
278-
## Returns the scope of the first non-empty scope child block
279-
static func get_tree_scope(node: Node) -> String:
280-
if node is Block:
281-
if node.scope != "":
282-
return node.scope
283-
284-
for c in node.get_children():
285-
var scope := get_tree_scope(c)
286-
if scope != "":
287-
return scope
288-
return ""

addons/block_code/instruction_tree/instruction_tree.gd

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

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

addons/block_code/ui/block_canvas/block_canvas.gd

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

0 commit comments

Comments
 (0)