2025-07-03 13:24:54 -06:00
|
|
|
class_name Holdable extends Node
|
|
|
|
## Component for holdable elements
|
|
|
|
|
|
|
|
@export var hold_distance := 1.0
|
2025-07-04 14:56:35 -06:00
|
|
|
@export var controller: RigidBody3D
|
2025-07-03 13:24:54 -06:00
|
|
|
|
|
|
|
|
2025-07-04 14:56:35 -06:00
|
|
|
func _ready() -> void:
|
|
|
|
if not controller:
|
2025-07-04 16:30:11 -06:00
|
|
|
controller = _default_controller()
|
|
|
|
assert(controller, "Holdable %s has no valid controller!" % str(self))
|
2025-07-04 14:56:35 -06:00
|
|
|
|
|
|
|
controller.add_user_signal(Interactive.SELECT_SIGNAL)
|
|
|
|
controller.connect(Interactive.SELECT_SIGNAL, select)
|
2025-07-04 16:30:11 -06:00
|
|
|
controller.add_user_signal(Interactive.DESELECT_SIGNAL)
|
|
|
|
controller.connect(Interactive.DESELECT_SIGNAL, deselect)
|
2025-07-04 14:56:35 -06:00
|
|
|
controller.add_user_signal(Interactive.ACTIVATE_SIGNAL)
|
|
|
|
controller.connect(Interactive.ACTIVATE_SIGNAL, activate)
|
|
|
|
|
|
|
|
|
2025-07-04 16:30:11 -06:00
|
|
|
func _default_controller() -> RigidBody3D:
|
|
|
|
return get_parent() as RigidBody3D
|
|
|
|
|
|
|
|
|
2025-07-04 14:56:35 -06:00
|
|
|
func select() -> void:
|
2025-07-08 17:36:21 -06:00
|
|
|
Tutorial.manager.activate("game/tutorial/progress/pick_up")
|
2025-07-04 14:56:35 -06:00
|
|
|
Player.instance.hud.hold_hud.select_prop()
|
|
|
|
|
|
|
|
|
2025-07-04 16:30:11 -06:00
|
|
|
func deselect() -> void:
|
|
|
|
Player.instance.hud.hold_hud.deselect()
|
|
|
|
|
|
|
|
|
2025-07-04 14:56:35 -06:00
|
|
|
func activate() -> void:
|
|
|
|
if not Player.instance.hold_component.holding_object():
|
|
|
|
Player.instance.hold_component.attach(controller, hold_distance)
|