SchildDerStaerke/scripts/wall_doorway.gd

33 lines
800 B
GDScript

class_name WallDoorway
extends ItemInteractable
func _ready() -> void:
state_changed.connect(_on_state_changed)
interaction_area.interact = Callable(self, "_on_interact")
apply_state(States.closed)
func _on_interact() -> void:
apply_state(_toggled_state(state))
func _on_state_changed(new_state: States) -> void:
_update_action_name(new_state)
func apply_state(new_state: States) -> void:
if new_state == States.closed:
animation_player.play(ANIM_CLOSE)
else:
animation_player.play(ANIM_OPEN)
state = new_state
_update_action_name(new_state)
func _toggled_state(s: States) -> States:
return States.opened if s == States.closed else States.closed
func _update_action_name(s: States) -> void:
interaction_area.action_name = ACTION_OPEN if s == States.closed else ACTION_CLOSE