TimerSprite.gd 890 B

123456789101112131415161718192021222324252627282930313233
  1. class_name TimerSprite
  2. extends Sprite2D
  3. @export var max_value := 1.0
  4. @export var value_name := ""
  5. @export_enum("Global", "Player", "Timer") var object := 0
  6. @export var timer: Timer = null
  7. @export var warn_sfx: AudioStreamPlayer = null
  8. @export var warn_threshold := 0.7
  9. var can_warn := false
  10. func _ready() -> void:
  11. texture = ResourceSetter.get_resource(texture, self)
  12. func _process(_delta: float) -> void:
  13. var node = owner if object == 1 else Global
  14. if object == 2:
  15. node = timer
  16. var value = node.get(value_name)
  17. var percent = inverse_lerp(max_value, 0, value)
  18. percent = clamp(percent, 0, 1)
  19. get_parent().visible = percent < 1 and Settings.file.visuals.visible_timers
  20. frame = lerp(0, 6, percent)
  21. if percent >= warn_threshold and Settings.file.audio.extra_sfx == 1:
  22. if can_warn:
  23. can_warn = false
  24. AudioManager.play_global_sfx("timer_warning")
  25. else:
  26. can_warn = true