From 453509ae1623ee6742ca79c3f5c6e5a5cf1016b2 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Thu, 2 Mar 2023 17:43:59 +0100 Subject: [PATCH 1/7] refactor: :recycle: Added type check to `_get_string_from_dict()` | `_get_array_from_dict()` --- addons/mod_loader/classes/mod_manifest.gd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index a5d053bc..a83b13a3 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -218,17 +218,25 @@ static func is_mod_id_valid(original_mod_id: String, check_mod_id: String, type return true -# Returns an empty String if the key does not exist +# Returns an empty String if the key does not exist or is not type of String static func _get_string_from_dict(dict: Dictionary, key: String) -> String: if not dict.has(key): return "" + + if not dict[key] is String: + return "" + return dict[key] -# Returns an empty Array if the key does not exist +# Returns an empty Array if the key does not exist or is not type of Array static func _get_array_from_dict(dict: Dictionary, key: String) -> Array: if not dict.has(key): return [] + + if not dict[key] is Array: + return [] + return dict[key] From 01f0ca541a9548a38dc5cb146ab7405a272a6a61 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Thu, 2 Mar 2023 17:52:47 +0100 Subject: [PATCH 2/7] refactor: :recycle: Added `compatible_mod_loader_version` to manifest data Added `compatible_mod_loader_version` to manifest data. This field has been changed from a single String to a PoolStringArray for parity with other version fields. Added handling for this change and deprecation warning. Single String value for `compatible_mod_loader_version` deprecated --- addons/mod_loader/classes/mod_manifest.gd | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index a83b13a3..d6022a42 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -23,6 +23,8 @@ var authors: PoolStringArray = [] # only used for information var compatible_game_version: PoolStringArray = [] # only used for information +var compatible_mod_loader_version: PoolStringArray = [] +# only used for information var incompatibilities: PoolStringArray = [] var tags : PoolStringArray = [] var config_defaults := {} @@ -71,10 +73,11 @@ func _init(manifest: Dictionary) -> void: website_url = manifest.website_url dependencies = manifest.dependencies - var godot_details: Dictionary = manifest.extra.godot + var godot_details: Dictionary = manifest.extra.godot authors = _get_array_from_dict(godot_details, "authors") incompatibilities = _get_array_from_dict(godot_details, "incompatibilities") compatible_game_version = _get_array_from_dict(godot_details, "compatible_game_version") + compatible_mod_loader_version = _handle_compatible_mod_loader_version(godot_details) description_rich = _get_string_from_dict(godot_details, "description_rich") tags = _get_array_from_dict(godot_details, "tags") config_defaults = godot_details.config_defaults @@ -115,6 +118,27 @@ func get_as_dict() -> Dictionary: } +# Handles deprecation of the single string value in the compatible_mod_loader_version. +func _handle_compatible_mod_loader_version(godot_details: Dictionary) -> Array: + var link_manifest_docs := "https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Files#manifestjson" + var array_value := _get_array_from_dict(godot_details, "compatible_mod_loader_version") + + # If there are array values just return them + if array_value.size() > 0: + return array_value + + # If the array is empty check if a string was passed + var string_value := _get_string_from_dict(godot_details, "compatible_mod_loader_version") + # If an empty string was passed + if string_value == "": + ModLoaderUtils.log_error("compatible_mod_loader_version is a required field. For more details visit " + link_manifest_docs, LOG_NAME) + return [] + + # If a string was passed + ModLoaderDeprecated.deprecated_message("The single String value for 'compatible_mod_loader_version' is deprecated. Please provide an Array. For more details visit " + link_manifest_docs, "6.0.0") + return [string_value] + + # A valid namespace may only use letters (any case), numbers and underscores # and has to be longer than 3 characters # a-z A-Z 0-9 _ (longer than 3 characters) From 944ad247c807431bc31bce8b278e494eb18c4935 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Fri, 3 Mar 2023 08:46:53 +0100 Subject: [PATCH 3/7] refactor: :recycle: Reworked comments Reworked comments to fit the latest discussion in #166 --- addons/mod_loader/classes/mod_manifest.gd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index d6022a42..fa65d92e 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -131,11 +131,19 @@ func _handle_compatible_mod_loader_version(godot_details: Dictionary) -> Array: var string_value := _get_string_from_dict(godot_details, "compatible_mod_loader_version") # If an empty string was passed if string_value == "": - ModLoaderUtils.log_error("compatible_mod_loader_version is a required field. For more details visit " + link_manifest_docs, LOG_NAME) + ModLoaderUtils.log_error( + '"compatible_mod_loader_version" is a required field.' + + ' For more details visit ' + link_manifest_docs, + LOG_NAME + ) return [] # If a string was passed - ModLoaderDeprecated.deprecated_message("The single String value for 'compatible_mod_loader_version' is deprecated. Please provide an Array. For more details visit " + link_manifest_docs, "6.0.0") + ModLoaderDeprecated.deprecated_message( + 'The single String value for "compatible_mod_loader_version" is deprecated.' + + ' Please provide an Array. For more details visit ' + link_manifest_docs, + "6.0.0" + ) return [string_value] From 5be454af779442f1bbd740cec484546bd7342d70 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Fri, 3 Mar 2023 08:50:07 +0100 Subject: [PATCH 4/7] refactor: :recycle: Additional comment to point to validation method --- addons/mod_loader/classes/mod_manifest.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index fa65d92e..805d34a5 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -23,6 +23,7 @@ var authors: PoolStringArray = [] # only used for information var compatible_game_version: PoolStringArray = [] # only used for information +# Validated by [method _handle_compatible_mod_loader_version] var compatible_mod_loader_version: PoolStringArray = [] # only used for information var incompatibilities: PoolStringArray = [] From ff85356d1ea0693fc6a77f4b079eb281fe17eb30 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Fri, 3 Mar 2023 09:28:08 +0100 Subject: [PATCH 5/7] refactor: :recycle: Updated `get_as_dict()` Added `compatible_mod_loader_version` to `get_as_dict()` --- addons/mod_loader/classes/mod_manifest.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index 805d34a5..7ffca4cd 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -111,6 +111,7 @@ func get_as_dict() -> Dictionary: "dependencies": dependencies, "authors": authors, "compatible_game_version": compatible_game_version, + "compatible_mod_loader_version": compatible_mod_loader_version, "incompatibilities": incompatibilities, "tags": tags, "config_defaults": config_defaults, From 10c16771e32e160f192ff941dc5a27eff6780ec2 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Fri, 3 Mar 2023 21:56:27 +0100 Subject: [PATCH 6/7] refactor: :recycle: version number validation version number validation for array values of `compatible_mod_loader_version` in `_handle_compatible_mod_loader_version()` --- addons/mod_loader/classes/mod_manifest.gd | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index 7ffca4cd..c2c10d86 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -125,8 +125,14 @@ func _handle_compatible_mod_loader_version(godot_details: Dictionary) -> Array: var link_manifest_docs := "https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Files#manifestjson" var array_value := _get_array_from_dict(godot_details, "compatible_mod_loader_version") - # If there are array values just return them + # If there are array values if array_value.size() > 0: + # Check for valid versions + for value in array_value: + var value_string := str(value) + if not is_semver_valid(value_string): + return [] + return array_value # If the array is empty check if a string was passed @@ -179,8 +185,13 @@ static func is_semver_valid(check_version_number: String, is_silent := false) -> if re.search(check_version_number) == null: if not is_silent: - ModLoaderUtils.log_fatal('Invalid semantic version: "%s". ' + - 'You may only use numbers without leading zero and periods following this format {mayor}.{minor}.{patch}' % check_version_number, + # Using str() here because format strings cause an error + ModLoaderUtils.log_fatal( + str( + 'Invalid semantic version: "%s".', + 'You may only use numbers without leading zero and periods', + 'following this format {mayor}.{minor}.{patch}' + ) % check_version_number, LOG_NAME ) return false From cdf2418c40804b971c07216efd93934b13832e79 Mon Sep 17 00:00:00 2001 From: Kai Roth Date: Fri, 3 Mar 2023 22:22:02 +0100 Subject: [PATCH 7/7] style: :art: Reworked strings Reworked strings to fit the latest discussion in #166 --- addons/mod_loader/classes/mod_manifest.gd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mod_loader/classes/mod_manifest.gd b/addons/mod_loader/classes/mod_manifest.gd index c2c10d86..c675ca7f 100644 --- a/addons/mod_loader/classes/mod_manifest.gd +++ b/addons/mod_loader/classes/mod_manifest.gd @@ -140,16 +140,16 @@ func _handle_compatible_mod_loader_version(godot_details: Dictionary) -> Array: # If an empty string was passed if string_value == "": ModLoaderUtils.log_error( - '"compatible_mod_loader_version" is a required field.' + - ' For more details visit ' + link_manifest_docs, + "\"compatible_mod_loader_version\" is a required field." + + " For more details visit " + link_manifest_docs, LOG_NAME ) return [] # If a string was passed ModLoaderDeprecated.deprecated_message( - 'The single String value for "compatible_mod_loader_version" is deprecated.' + - ' Please provide an Array. For more details visit ' + link_manifest_docs, + "The single String value for \"compatible_mod_loader_version\" is deprecated." + + " Please provide an Array. For more details visit " + link_manifest_docs, "6.0.0" ) return [string_value]