Skip to content

Commit

Permalink
API: Add methods for deprecation + API Folder (#156)
Browse files Browse the repository at this point in the history
* API: Add methods for deprecation

* API: Deprecated - Lints

* API: Deprecated - PR review amends
  • Loading branch information
ithinkandicode authored Mar 2, 2023
1 parent 90bd4c6 commit 61132dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions addons/mod_loader/api/deprecated.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class_name ModLoaderDeprecated
extends Node

# API methods for deprecating funcs. Can be used by mods with public APIs.

const LOG_NAME := "ModLoader:Deprecated"


# A method has changed its name/class
static func deprecated_changed(old_method: String, new_method: String, since_version: String, show_removal_note: bool = true):
ModLoaderUtils.log_fatal(str(
"DEPRECATED: ",
"The method \"%s\" has been deprecated since version %s. " % [old_method, since_version],
"Please use \"%s\" instead. " % new_method,
"The old method will be removed with the next major update, and will break your code if not changed. " if show_removal_note else ""
), LOG_NAME)


# A method has been entirely removed, with no replacement
# (should never be needed but good to have just in case)
static func deprecated_removed(old_method: String, since_version: String, show_removal_note: bool = true):
ModLoaderUtils.log_fatal(str(
"DEPRECATED: ",
"The method \"%s\" has been deprecated since version %s, and is no longer available. " % [old_method, since_version],
"There is currently no replacement method. ",
"The method will be removed with the next major update, and will break your code if not changed. " if show_removal_note else ""
), LOG_NAME)


# Freeform deprecation message.
# Allows you to add a deprecation comment without specifying the old/new method
static func deprecated_message(msg: String, since_version: String = ""):
var since_text := " (since version %s)" % since_version if since_version else ""
ModLoaderUtils.log_fatal(str("DEPRECATED: ", msg, since_text), LOG_NAME)
5 changes: 5 additions & 0 deletions addons/mod_loader/mod_loader_setup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const new_global_classes := [
"class": "ModLoaderOptionsProfile",
"language": "GDScript",
"path": "res://addons/mod_loader/options/classes/options_profile.gd"
}, {
"base": "Node",
"class": "ModLoaderDeprecated",
"language": "GDScript",
"path": "res://addons/mod_loader/api/deprecated.gd"
}
]

Expand Down

0 comments on commit 61132dd

Please sign in to comment.