Util.gd 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. extends Node
  2. class_name Util
  3. # Logging
  4. static func PrintLog(logGroup : String, logString : String):
  5. print("[%d.%03d][%s] %s" % [Time.get_ticks_msec() / 1000.0, Time.get_ticks_msec() % 1000, logGroup, logString])
  6. static func PrintInfo(_logGroup : String, _logString : String):
  7. # print("[%d.%03d][%s] %s" % [Time.get_ticks_msec() / 1000.0, Time.get_ticks_msec() % 1000, logGroup, logString])
  8. pass
  9. # Node management
  10. static func RemoveNode(node : Node, parent : Node):
  11. if node != null:
  12. if parent != null:
  13. parent.remove_child(node)
  14. node.queue_free()
  15. # Screenshot
  16. static func GetScreenCapture() -> Image:
  17. return Launcher.get_viewport().get_texture().get_image()
  18. # Fade
  19. static func FadeInOutRatio(value : float, maxValue : float, fadeIn : float, fadeOut : float) -> float:
  20. var ratio : float = 1.0
  21. if value < fadeIn:
  22. ratio = min(value / fadeIn, ratio)
  23. if value > maxValue - fadeOut:
  24. ratio = min((fadeOut - (value - (maxValue - fadeOut))) / fadeOut, ratio)
  25. return ratio
  26. # Text
  27. static func GetFormatedText(value : String, numberAfterComma : int = 0) -> String:
  28. var commaLocation : int = value.find(".")
  29. var charCounter : int = 0
  30. if commaLocation > 0:
  31. charCounter = commaLocation - 3
  32. else:
  33. charCounter = value.length() - 3
  34. while charCounter > 0:
  35. value = value.insert(charCounter, ",")
  36. charCounter = charCounter - 3
  37. commaLocation = value.find(".")
  38. if commaLocation == -1:
  39. commaLocation = value.length()
  40. if numberAfterComma > 0:
  41. value += "."
  42. if numberAfterComma > 0:
  43. for i in range(value.length() - 1, commaLocation + numberAfterComma):
  44. value += "0"
  45. else:
  46. value = value.substr(0, commaLocation)
  47. return value