deprecated.gd 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. class_name ModLoaderDeprecated
  2. extends Object
  3. ##
  4. ## API methods for deprecating funcs. Can be used by mods with public APIs.
  5. const LOG_NAME := "ModLoader:Deprecated"
  6. ## Marks a method that has changed its name or class.[br]
  7. ## [br]
  8. ## [b]Parameters:[/b][br]
  9. ## - [param old_method] ([String]): The name of the deprecated method.[br]
  10. ## - [param new_method] ([String]): The name of the new method to use.[br]
  11. ## - [param since_version] ([String]): The version number from which the method has been deprecated.[br]
  12. ## - [param show_removal_note] ([bool]): (optional) If true, includes a note about future removal of the old method. Default is true.[br]
  13. ## [br]
  14. ## [b]Returns:[/b][br]
  15. ## - No return value[br]
  16. static func deprecated_changed(old_method: String, new_method: String, since_version: String, show_removal_note: bool = true) -> void:
  17. _deprecated_log(str(
  18. "DEPRECATED: ",
  19. "The method \"%s\" has been deprecated since version %s. " % [old_method, since_version],
  20. "Please use \"%s\" instead. " % new_method,
  21. "The old method will be removed with the next major update, and will break your code if not changed. " if show_removal_note else ""
  22. ))
  23. ## Marks a method that has been entirely removed, with no replacement.[br]
  24. ## [br]
  25. ## [b]Parameters:[/b][br]
  26. ## - [param old_method] ([String]): The name of the removed method.[br]
  27. ## - [param since_version] ([String]): The version number from which the method has been deprecated.[br]
  28. ## - [param show_removal_note] ([bool]): (optional) If true, includes a note about future removal of the old method. Default is true.[br]
  29. ## [br]
  30. ## [b]Returns:[/b][br]
  31. ## - No return value[br]
  32. ## [br]
  33. ## ===[br]
  34. ## [b]Note:[/b][br]
  35. ## This should rarely be needed but is included for completeness.[br]
  36. ## ===[br]
  37. static func deprecated_removed(old_method: String, since_version: String, show_removal_note: bool = true) -> void:
  38. _deprecated_log(str(
  39. "DEPRECATED: ",
  40. "The method \"%s\" has been deprecated since version %s, and is no longer available. " % [old_method, since_version],
  41. "There is currently no replacement method. ",
  42. "The method will be removed with the next major update, and will break your code if not changed. " if show_removal_note else ""
  43. ))
  44. ## Marks a method with a freeform deprecation message.[br]
  45. ## [br]
  46. ## [b]Parameters:[/b][br]
  47. ## - [param msg] ([String]): The deprecation message.[br]
  48. ## - [param since_version] ([String]): (optional) The version number from which the deprecation applies.[br]
  49. ## [br]
  50. ## [b]Returns:[/b][br]
  51. ## - No return value[br]
  52. static func deprecated_message(msg: String, since_version: String = "") -> void:
  53. var since_text := " (since version %s)" % since_version if since_version else ""
  54. _deprecated_log(str("DEPRECATED: ", msg, since_text))
  55. # Internal function for logging deprecation messages with support to trigger warnings instead of fatal errors.[br]
  56. # [br]
  57. # [b]Parameters:[/b][br]
  58. # - [param msg] ([String]): The deprecation message.[br]
  59. # [br]
  60. # [b]Returns:[/b][br]
  61. # - No return value[br]
  62. static func _deprecated_log(msg: String) -> void:
  63. if ModLoaderStore and ModLoaderStore.ml_options.ignore_deprecated_errors or OS.has_feature("standalone"):
  64. ModLoaderLog.warning(msg, LOG_NAME, true)
  65. else:
  66. ModLoaderLog.fatal(msg, LOG_NAME, true)