grunk/src/props/wall_switch/wall_switch.gd

44 lines
916 B
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()
func enable() -> void:
enabled = true
# Clear off the rest of the gunk
gunk_body.clear_all()
light_animation.play("success")
interactive.enabled = true
func _activate() -> void:
animation_player.play("activate")
activated.emit()
# Disable while animation is playing
interactive.enabled = false
func _animation_finished(_anim_name: StringName) -> void:
interactive.enabled = true
func _on_gunk_body_clear_total_updated(clear_total: float) -> void:
if not enabled and clear_total >= CLEAR_THRESHOLD:
enable()