generated from krampus/template-godot4
37 lines
975 B
GDScript3
37 lines
975 B
GDScript3
|
class_name GunkAlarm extends GunkNode
|
||
|
## Raises the grunk alert when triggered.
|
||
|
|
||
|
## Emitted when this alarm is triggered, just after the alert level is raised.
|
||
|
signal triggered
|
||
|
|
||
|
const ALERT_DELTA := 1
|
||
|
|
||
|
var _busy := false
|
||
|
|
||
|
@onready var mesh_instance_3d: MeshInstance3D = %MeshInstance3D
|
||
|
@onready var animation_player: AnimationPlayer = %AnimationPlayer
|
||
|
|
||
|
|
||
|
## Trigger this alarm.
|
||
|
##
|
||
|
## Will not trigger if this alarm is busy (e.g. on cooldown)
|
||
|
func trigger() -> void:
|
||
|
if not _busy:
|
||
|
Game.manager.raise_alert(ALERT_DELTA)
|
||
|
_busy = true
|
||
|
animation_player.play("trigger")
|
||
|
triggered.emit()
|
||
|
|
||
|
|
||
|
func _process(delta: float) -> void:
|
||
|
super._process(delta)
|
||
|
# TODO actual model & animation
|
||
|
var material: StandardMaterial3D = mesh_instance_3d.mesh.surface_get_material(0)
|
||
|
var value := 1.0 - _sustained_damage / durability
|
||
|
material.albedo_color = Color(value, value, value)
|
||
|
|
||
|
|
||
|
func _on_animation_finished(anim_name: StringName) -> void:
|
||
|
if anim_name == "trigger":
|
||
|
_busy = false
|