Arcade racing demo got Godot 3.3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
878B

  1. extends Node
  2. signal message(msg)
  3. signal value_passed(name, v)
  4. const EMIT_RATE = 0.1
  5. var _timer_message : float = 0.0
  6. var _timer_pass_val : float = 0.0
  7. var _msg_buffer = []
  8. var _pass_val_buffer = []
  9. func _msgformat(msg : String, args : Array) -> String:
  10. for i in range(0, args.size()):
  11. msg = msg.format(args[i], "$" + String(i))
  12. return msg
  13. func message(msg : String, args : Array = []) -> void:
  14. if _timer_message <= 0.0:
  15. emit_signal("message", _msgformat(msg, args))
  16. _timer_message = EMIT_RATE
  17. else:
  18. _msg_buffer.append(_msgformat(msg, args))
  19. func pass_value(name : String, val) -> void:
  20. emit_signal("value_passed", name, val)
  21. func _process(delta : float) -> void:
  22. if _timer_message > 0.0:
  23. _timer_message = max(0.0, _timer_message - delta)
  24. if _timer_message == 0.0 and _msg_buffer.size() > 0:
  25. emit_signal("message", _msg_buffer)
  26. _msg_buffer = []