2025-03-14 16:46:25 -06:00
|
|
|
class_name GunkAlarm extends GunkNode
|
2025-03-13 13:34:35 -06:00
|
|
|
## Raises the grunk alert when triggered.
|
|
|
|
|
|
|
|
const ALERT_DELTA := 1
|
|
|
|
|
2025-03-14 16:46:25 -06:00
|
|
|
## Time to wait for a pulse signal before triggering.
|
|
|
|
@export var pulse_timeout := 6.0
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
var _busy := false
|
|
|
|
|
|
|
|
@onready var mesh_instance_3d: MeshInstance3D = %MeshInstance3D
|
|
|
|
@onready var animation_player: AnimationPlayer = %AnimationPlayer
|
2025-03-14 16:46:25 -06:00
|
|
|
@onready var pulse_listener_timer: Timer = %PulseListenerTimer
|
2025-03-13 13:34:35 -06:00
|
|
|
|
|
|
|
|
|
|
|
## Trigger this alarm.
|
|
|
|
##
|
|
|
|
## Will not trigger if this alarm is busy (e.g. on cooldown)
|
|
|
|
func trigger() -> void:
|
|
|
|
if not _busy:
|
|
|
|
_busy = true
|
2025-03-13 14:50:59 -06:00
|
|
|
Game.manager.raise_alert(ALERT_DELTA)
|
2025-03-13 13:34:35 -06:00
|
|
|
animation_player.play("trigger")
|
|
|
|
|
|
|
|
|
2025-03-14 16:46:25 -06:00
|
|
|
## Pulse this alarm, resetting the pulse countdown until triggering.
|
|
|
|
##
|
|
|
|
## Note that alarms will not begin the pulse countdown until receiving the first pulse.
|
|
|
|
## On networks without a heart, the pulse timeout will be completely ignored.
|
|
|
|
func pulse() -> void:
|
|
|
|
pulse_listener_timer.start(pulse_timeout)
|
|
|
|
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
func _process(delta: float) -> void:
|
|
|
|
super._process(delta)
|
|
|
|
# TODO actual model & animation
|
|
|
|
var material: StandardMaterial3D = mesh_instance_3d.mesh.surface_get_material(0)
|
2025-03-14 15:27:55 -06:00
|
|
|
var value := 1.0 - pct_damage()
|
2025-03-13 13:34:35 -06:00
|
|
|
material.albedo_color = Color(value, value, value)
|
|
|
|
|
2025-03-14 16:46:25 -06:00
|
|
|
# TODO pulse animation
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
|
|
|
|
func _on_animation_finished(anim_name: StringName) -> void:
|
|
|
|
if anim_name == "trigger":
|
|
|
|
_busy = false
|