Skip to content

Commit

Permalink
Remove block.on_canvas
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dylanmccall committed Jun 25, 2024
1 parent a6f9366 commit 105247c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 7 deletions.
3 changes: 1 addition & 2 deletions addons/block_code/drag_manager/drag_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Drag:
assert(block.get_parent() == null)

add_child(block)
block.on_canvas = false
block.position = -offset

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

if not _snap_point.block.on_canvas:
if not _block_canvas.is_ancestor_of(_snap_point):
# We only snap to blocks on the canvas:
return false

Expand Down
2 changes: 0 additions & 2 deletions addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func _populate_block_scenes_by_class():
func add_block(block: Block, position: Vector2 = Vector2.ZERO) -> void:
block.position = position
block.position.y += _window_scroll.scroll_vertical
block.on_canvas = true
_window.add_child(block)
_window.custom_minimum_size.y = max(block.position.y + EXTEND_MARGIN, _window.custom_minimum_size.y)

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

scene.on_canvas = true
parent.add_child(scene)

var scene_block: Block = scene as Block
Expand Down
2 changes: 0 additions & 2 deletions addons/block_code/ui/blocks/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ signal modified
## The next block in the line of execution (can be null if end)
@export var bottom_snap_path: NodePath

var on_canvas: bool = false

var bottom_snap: SnapPoint


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func set_snapped_block(snapped_block: Block) -> Block:

if snapped_block:
add_child(snapped_block)
snapped_block.on_canvas = block.on_canvas

if snapped_block and orphaned_block:
var last_snap = _get_last_snap(snapped_block)
Expand Down

0 comments on commit 105247c

Please sign in to comment.