2023-11-20 00:58:26 +02:00
|
|
|
extends XRController3D
|
|
|
|
|
2024-04-17 17:49:58 +03:00
|
|
|
const Entity = preload ("res://content/entities/entity.gd")
|
|
|
|
|
2023-11-20 00:58:26 +02:00
|
|
|
@onready var area = $trash_bin/Area3D
|
|
|
|
@onready var trash_bin = $trash_bin
|
|
|
|
@onready var animation = $AnimationPlayer
|
|
|
|
|
|
|
|
var to_delete = []
|
|
|
|
var trash_bin_visible: bool = true:
|
|
|
|
set(value):
|
|
|
|
if trash_bin_visible == value:
|
|
|
|
return
|
|
|
|
|
|
|
|
if value:
|
|
|
|
add_child(trash_bin)
|
|
|
|
else:
|
|
|
|
if animation.is_playing():
|
|
|
|
await animation.animation_finished
|
|
|
|
remove_child(trash_bin)
|
|
|
|
|
|
|
|
trash_bin_visible = value
|
|
|
|
|
|
|
|
var trash_bin_large: bool = false:
|
|
|
|
set(value):
|
|
|
|
if trash_bin_large == value:
|
|
|
|
return
|
|
|
|
|
|
|
|
if value:
|
|
|
|
animation.play("add_trashbin")
|
|
|
|
else:
|
|
|
|
animation.play_backwards("add_trashbin")
|
|
|
|
|
|
|
|
trash_bin_large = value
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
trash_bin_visible = false
|
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
EventSystem.on_grab_down.connect(func(event: EventPointer):
|
2024-04-17 17:49:58 +03:00
|
|
|
trash_bin_visible=event.target is Entity
|
2023-11-20 00:58:26 +02:00
|
|
|
)
|
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
EventSystem.on_grab_move.connect(func(event):
|
2023-11-20 00:58:26 +02:00
|
|
|
if !trash_bin_visible:
|
|
|
|
return
|
|
|
|
|
2024-04-17 17:49:58 +03:00
|
|
|
if event.target is Entity&&area.overlaps_body(event.target):
|
2023-11-20 00:58:26 +02:00
|
|
|
if !to_delete.has(event.target):
|
|
|
|
to_delete.append(event.target)
|
2024-04-17 17:49:58 +03:00
|
|
|
trash_bin_large=true
|
2023-11-20 00:58:26 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
to_delete.erase(event.target)
|
2024-04-17 17:49:58 +03:00
|
|
|
trash_bin_large=false
|
2023-11-20 00:58:26 +02:00
|
|
|
|
|
|
|
)
|
|
|
|
|
2023-11-27 01:23:19 +02:00
|
|
|
EventSystem.on_grab_up.connect(func(_event: EventPointer):
|
2023-11-20 00:58:26 +02:00
|
|
|
if !trash_bin_visible:
|
|
|
|
return
|
|
|
|
|
|
|
|
for entity in to_delete:
|
|
|
|
entity.queue_free()
|
|
|
|
to_delete.clear()
|
2024-04-17 17:49:58 +03:00
|
|
|
trash_bin_large=false
|
|
|
|
trash_bin_visible=false
|
2023-11-20 00:58:26 +02:00
|
|
|
)
|