generated from krampus/template-godot4
46 lines
938 B
GDScript
46 lines
938 B
GDScript
extends Node3D
|
|
|
|
signal cleared
|
|
signal activated
|
|
|
|
const CLEAR_THRESHOLD := 2650
|
|
|
|
@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 _on_gunk_body_painted() -> void:
|
|
if not enabled:
|
|
var clear_total := gunk_body.get_clear_total()
|
|
if clear_total >= CLEAR_THRESHOLD:
|
|
enable()
|
|
|
|
|
|
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
|