Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support for Godot 4.1 #441

Open
wants to merge 6 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion addons/mod_loader/internal/mod_hook_preprocessor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static func get_return_type_string(return_data: Dictionary) -> String:
if return_data.has("class_name") and not str(return_data.class_name).is_empty():
type_base = str(return_data.class_name)
else:
type_base = type_string(return_data.type)
type_base = get_type_name(return_data.type)

var type_hint: String = "" if return_data.hint_string.is_empty() else ("[%s]" % return_data.hint_string)

Expand All @@ -369,3 +369,89 @@ static func collect_getters_and_setters(text: String, regex_getter_setter: RegEx
result[mat.get_string(4)] = true

return result


# This function was taken from https://github.com/godotengine/godot/blob/7e67b496ff7e35f66b88adcbdd5b252d01739cbb/modules/gdscript/tests/scripts/utils.notest.gd#L69
# It is used instead of type_string because type_string does not exist in Godot 4.1
static func get_type_name(type: Variant.Type) -> String:
match type:
TYPE_NIL:
return "Nil" # `Nil` in core, `null` in GDScript.
TYPE_BOOL:
return "bool"
TYPE_INT:
return "int"
TYPE_FLOAT:
return "float"
TYPE_STRING:
return "String"
TYPE_VECTOR2:
return "Vector2"
TYPE_VECTOR2I:
return "Vector2i"
TYPE_RECT2:
return "Rect2"
TYPE_RECT2I:
return "Rect2i"
TYPE_VECTOR3:
return "Vector3"
TYPE_VECTOR3I:
return "Vector3i"
TYPE_TRANSFORM2D:
return "Transform2D"
TYPE_VECTOR4:
return "Vector4"
TYPE_VECTOR4I:
return "Vector4i"
TYPE_PLANE:
return "Plane"
TYPE_QUATERNION:
return "Quaternion"
TYPE_AABB:
return "AABB"
TYPE_BASIS:
return "Basis"
TYPE_TRANSFORM3D:
return "Transform3D"
TYPE_PROJECTION:
return "Projection"
TYPE_COLOR:
return "Color"
TYPE_STRING_NAME:
return "StringName"
TYPE_NODE_PATH:
return "NodePath"
TYPE_RID:
return "RID"
TYPE_OBJECT:
return "Object"
TYPE_CALLABLE:
return "Callable"
TYPE_SIGNAL:
return "Signal"
TYPE_DICTIONARY:
return "Dictionary"
TYPE_ARRAY:
return "Array"
TYPE_PACKED_BYTE_ARRAY:
return "PackedByteArray"
TYPE_PACKED_INT32_ARRAY:
return "PackedInt32Array"
TYPE_PACKED_INT64_ARRAY:
return "PackedInt64Array"
TYPE_PACKED_FLOAT32_ARRAY:
return "PackedFloat32Array"
TYPE_PACKED_FLOAT64_ARRAY:
return "PackedFloat64Array"
TYPE_PACKED_STRING_ARRAY:
return "PackedStringArray"
TYPE_PACKED_VECTOR2_ARRAY:
return "PackedVector2Array"
TYPE_PACKED_VECTOR3_ARRAY:
return "PackedVector3Array"
TYPE_PACKED_COLOR_ARRAY:
return "PackedColorArray"
38: # TYPE_PACKED_VECTOR4_ARRAY
return "PackedVector4Array"
push_error("Argument `type` is invalid. Use `TYPE_*` constants.")
return "<invalid type>"
2 changes: 1 addition & 1 deletion addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func _load_metadata(manifest_dict: Dictionary, zip_path := ""):

func _load_mods(mod_data: Dictionary) -> void:
var mod_zip_paths: Array[String] = []
for mod: ModData in mod_data.values():
for mod in mod_data.values():
if not mod.is_loadable:
Comment on lines +130 to 131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep the type in the loop, we can do something fun like this:

Suggested change
for mod in mod_data.values():
if not mod.is_loadable:
for _mod in mod_data.values():
var mod: ModData = _mod
if not mod.is_loadable:

continue
if not mod.zip_path:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[gd_resource type="Resource" script_class="ModLoaderOptionsProfile" load_steps=2 format=4 uid="uid://bodsw0jyh6rn5"]
[gd_resource type="Resource" script_class="ModLoaderOptionsProfile" load_steps=2 format=3 uid="uid://bodsw0jyh6rn5"]

[ext_resource type="Script" path="res://addons/mod_loader/resources/options_profile.gd" id="1"]

[resource]
script = ExtResource("1")
enable_mods = true
locked_mods = Array[String]([])
locked_mods = []
log_level = 2
disabled_mods = Array[String]([])
disabled_mods = []
allow_modloader_autoloads_anywhere = false
steam_id = 0
override_path_to_mods = ""
override_path_to_configs = ""
override_path_to_workshop = ""
ignore_deprecated_errors = false
ignored_mod_names_in_log = Array[String]([])
ignored_mod_names_in_log = []
load_from_steam_workshop = false
load_from_local = true
8 changes: 4 additions & 4 deletions addons/mod_loader/options/profiles/production_workshop.tres
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[gd_resource type="Resource" script_class="ModLoaderOptionsProfile" load_steps=2 format=4 uid="uid://cg0vv5k4o71rv"]
[gd_resource type="Resource" script_class="ModLoaderOptionsProfile" load_steps=2 format=3 uid="uid://cg0vv5k4o71rv"]

[ext_resource type="Script" path="res://addons/mod_loader/resources/options_profile.gd" id="1"]

[resource]
script = ExtResource("1")
enable_mods = true
locked_mods = Array[String]([])
locked_mods = []
log_level = 2
disabled_mods = Array[String]([])
disabled_mods = []
allow_modloader_autoloads_anywhere = false
steam_id = 0
override_path_to_mods = ""
override_path_to_configs = ""
override_path_to_workshop = ""
ignore_deprecated_errors = false
ignored_mod_names_in_log = Array[String]([])
ignored_mod_names_in_log = []
load_from_steam_workshop = true
load_from_local = true