grunk/src/props/wall_switch/wall_switch.gd

55 lines
1.2 KiB
GDScript3
Raw Normal View History

2025-03-05 14:46:13 -07:00
extends Node3D
2025-03-05 15:35:49 -07:00
signal cleared
signal activated
2025-03-09 16:40:19 -06:00
const CLEAR_THRESHOLD := 1500
2025-03-05 15:35:49 -07:00
@export var enabled := false
@onready var animation_player: AnimationPlayer = %AnimationPlayer
@onready var light_animation: AnimationPlayer = %LightAnimation
@onready var gunk_body: GunkBody = %GunkBody
@onready var interactive: Interactive = %Interactive
func _ready() -> void:
if enabled:
enable()
2025-03-10 17:00:30 -06:00
## Called once all gunk is cleared. Enables interaction & plays animations
2025-03-05 15:35:49 -07:00
func enable() -> void:
enabled = true
# Clear off the rest of the gunk
gunk_body.clear_all()
light_animation.play("success")
interactive.enabled = true
2025-03-10 17:00:30 -06:00
## Called once the switch is no longer usable. Disables interaction & plays animations
func disable() -> void:
if enabled:
2025-03-13 12:25:04 -06:00
light_animation.play("disable")
2025-03-10 17:00:30 -06:00
enabled = false
interactive.enabled = false
2025-03-05 15:35:49 -07:00
func _activate() -> void:
animation_player.play("activate")
activated.emit()
# Disable while animation is playing
interactive.enabled = false
2025-03-10 17:00:30 -06:00
func _animation_finished(anim_name: StringName) -> void:
if anim_name == "activate":
interactive.enabled = enabled
func _on_gunk_body_clear_total_updated(clear_total: float) -> void:
if not enabled and clear_total >= CLEAR_THRESHOLD:
enable()