From 76ad1f11f42e2da1d5b498918be69107558e2bfa Mon Sep 17 00:00:00 2001 From: Nitwel Date: Mon, 6 May 2024 13:02:20 +0200 Subject: [PATCH] fix deleting entities --- .../system/controller_left/controller_left.gd | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/content/system/controller_left/controller_left.gd b/app/content/system/controller_left/controller_left.gd index 4db2e50..a29f7fb 100644 --- a/app/content/system/controller_left/controller_left.gd +++ b/app/content/system/controller_left/controller_left.gd @@ -37,20 +37,22 @@ func _ready(): trash_bin_visible = false EventSystem.on_grab_down.connect(func(event: EventPointer): - trash_bin_visible=event.target is Entity + trash_bin_visible=_get_entity(event.target) != null ) EventSystem.on_grab_move.connect(func(event): if !trash_bin_visible: return - if event.target is Entity&&area.overlaps_body(event.target): - if !to_delete.has(event.target): - to_delete.append(event.target) + var entity=_get_entity(event.target) + + if entity is Entity&&area.overlaps_body(entity): + if !to_delete.has(entity): + to_delete.append(entity) trash_bin_large=true else: - to_delete.erase(event.target) + to_delete.erase(entity) trash_bin_large=false ) @@ -64,4 +66,15 @@ func _ready(): to_delete.clear() trash_bin_large=false trash_bin_visible=false + + House.body.save_all_entities() ) + +func _get_entity(node: Node): + if node is Entity: + return node + + if node.get_parent() == null: + return null + + return _get_entity(node.get_parent()) \ No newline at end of file