From 29f250adf0e1dfda5e7fc85d949cf015363d4fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Tue, 18 Jun 2024 23:03:36 -0300 Subject: [PATCH] Block code: Don't use get_class for custom classes Overriding the native get_class is not supported and raises an error. Add a method to get either the custom or the native class. --- addons/block_code/block_code_node/block_code.gd | 16 ++++++++++++---- .../simple_character/simple_character.gd | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/block_code/block_code_node/block_code.gd b/addons/block_code/block_code_node/block_code.gd index 62dab20b..61da4dea 100644 --- a/addons/block_code/block_code_node/block_code.gd +++ b/addons/block_code/block_code_node/block_code.gd @@ -14,6 +14,12 @@ func _ready(): _update_parent_script() +func _get_custom_or_native_class(node: Node): + if node.has_method("get_custom_class"): + return node.get_custom_class() + return node.get_class() + + func _enter_tree(): if not Engine.is_editor_hint(): return @@ -21,7 +27,7 @@ func _enter_tree(): # Create script if bsd == null: var new_bsd: BlockScriptData = load("res://addons/block_code/ui/bsd_templates/default_bsd.tres").duplicate(true) - new_bsd.script_inherits = get_parent().call("get_class") # For whatever reason this works instead of just .get_class :) + new_bsd.script_inherits = _get_custom_or_native_class(get_parent()) new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits) bsd = new_bsd @@ -44,6 +50,8 @@ func _update_parent_script(): func _get_configuration_warnings(): - if bsd: - if get_parent().call("get_class") != bsd.script_inherits: - return ["The parent is not a %s. Create a new BlockCode node and reattach." % bsd.script_inherits] + var warnings = [] + if bsd and _get_custom_or_native_class(get_parent()) != bsd.script_inherits: + var warning = "The parent is not a %s. Create a new BlockCode node and reattach." % bsd.script_inherits + warnings.append(warning) + return warnings diff --git a/addons/block_code/simple_nodes/simple_character/simple_character.gd b/addons/block_code/simple_nodes/simple_character/simple_character.gd index 4c560ad4..5b4de358 100644 --- a/addons/block_code/simple_nodes/simple_character/simple_character.gd +++ b/addons/block_code/simple_nodes/simple_character/simple_character.gd @@ -9,7 +9,7 @@ func _ready(): $Sprite2D.texture = sprite_texture -func get_class(): +func get_custom_class(): return "SimpleCharacter"