2025-03-28 14:16:43 -06:00
|
|
|
@tool
|
2025-03-15 19:00:37 -06:00
|
|
|
class_name GunkAlarm extends SignalNode
|
2025-03-13 13:34:35 -06:00
|
|
|
## Raises the grunk alert when triggered.
|
|
|
|
|
|
|
|
const ALERT_DELTA := 1
|
|
|
|
|
2025-03-28 14:16:43 -06:00
|
|
|
const JITTER_SCALE_FACTOR := 0.15
|
|
|
|
const JITTER_INFLATION_FACTOR := 1.5
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
var _busy := false
|
|
|
|
|
2025-03-14 16:46:25 -06:00
|
|
|
@onready var pulse_listener_timer: Timer = %PulseListenerTimer
|
2025-04-21 14:41:37 -06:00
|
|
|
@onready var animation_player: AnimationPlayer = $FrameSkipper/Rumbler3D/AlarmMesh/AnimationPlayer
|
|
|
|
@onready var trigger_animation: AnimationPlayer = %TriggerAnimation
|
|
|
|
@onready var pulse_animation: AnimationPlayer = %PulseAnimation
|
|
|
|
|
|
|
|
@onready var bud: MeshInstance3D = $FrameSkipper/Rumbler3D/AlarmMesh/Armature/Skeleton3D/Bud
|
2025-04-02 20:09:09 -06:00
|
|
|
@onready var alarm_sfx: AudioStreamPlayer3D = %AlarmSFX
|
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-04-21 14:41:37 -06:00
|
|
|
trigger_animation.play("trigger")
|
2025-04-02 20:09:09 -06:00
|
|
|
alarm_sfx.play()
|
2025-03-13 13:34:35 -06:00
|
|
|
|
|
|
|
|
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:
|
2025-04-21 14:41:37 -06:00
|
|
|
pulse_animation.seek(0)
|
|
|
|
pulse_animation.play("pulse")
|
2025-03-14 16:46:25 -06:00
|
|
|
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
func _process(delta: float) -> void:
|
2025-03-28 14:16:43 -06:00
|
|
|
if Engine.is_editor_hint():
|
|
|
|
return
|
|
|
|
|
2025-03-13 13:34:35 -06:00
|
|
|
super._process(delta)
|
|
|
|
# TODO actual model & animation
|
2025-04-21 13:11:49 -06:00
|
|
|
var shader: ShaderMaterial = bud.get_surface_override_material(0)
|
2025-03-28 14:16:43 -06:00
|
|
|
var damage := pct_damage()
|
|
|
|
shader.set_shader_parameter("jitter_time_scale", pow(damage * JITTER_SCALE_FACTOR, 1.2))
|
|
|
|
shader.set_shader_parameter("vertex_inflation", pow(damage * JITTER_INFLATION_FACTOR, 3))
|
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
|