Skip to content

Commit 105247c

Browse files
committed
Remove block.on_canvas
Instead, check if a block is on the canvas using `Node.is_ancestor_of`. This avoids needing to keep the property in sync between multiple places.
1 parent a6f9366 commit 105247c

File tree

4 files changed

+1
-7
lines changed

4 files changed

+1
-7
lines changed

addons/block_code/drag_manager/drag_manager.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Drag:
4242
assert(block.get_parent() == null)
4343

4444
add_child(block)
45-
block.on_canvas = false
4645
block.position = -offset
4746

4847
_block = block
@@ -92,7 +91,7 @@ class Drag:
9291
push_error("Warning: snap point %s does not reference its parent block." % _snap_point)
9392
return false
9493

95-
if not _snap_point.block.on_canvas:
94+
if not _block_canvas.is_ancestor_of(_snap_point):
9695
# We only snap to blocks on the canvas:
9796
return false
9897

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func _populate_block_scenes_by_class():
3232
func add_block(block: Block, position: Vector2 = Vector2.ZERO) -> void:
3333
block.position = position
3434
block.position.y += _window_scroll.scroll_vertical
35-
block.on_canvas = true
3635
_window.add_child(block)
3736
_window.custom_minimum_size.y = max(block.position.y + EXTEND_MARGIN, _window.custom_minimum_size.y)
3837

@@ -83,7 +82,6 @@ func load_tree(parent: Node, node: SerializedBlockTreeNode):
8382
for prop_pair in node.serialized_block.serialized_props:
8483
scene.set(prop_pair[0], prop_pair[1])
8584

86-
scene.on_canvas = true
8785
parent.add_child(scene)
8886

8987
var scene_block: Block = scene as Block

addons/block_code/ui/blocks/block/block.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ signal modified
2323
## The next block in the line of execution (can be null if end)
2424
@export var bottom_snap_path: NodePath
2525

26-
var on_canvas: bool = false
27-
2826
var bottom_snap: SnapPoint
2927

3028

addons/block_code/ui/blocks/utilities/snap_point/snap_point.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func set_snapped_block(snapped_block: Block) -> Block:
3535

3636
if snapped_block:
3737
add_child(snapped_block)
38-
snapped_block.on_canvas = block.on_canvas
3938

4039
if snapped_block and orphaned_block:
4140
var last_snap = _get_last_snap(snapped_block)

0 commit comments

Comments
 (0)