Skip to content

Commit 29f250a

Browse files
committed
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.
1 parent 80b227a commit 29f250a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

addons/block_code/block_code_node/block_code.gd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ func _ready():
1414
_update_parent_script()
1515

1616

17+
func _get_custom_or_native_class(node: Node):
18+
if node.has_method("get_custom_class"):
19+
return node.get_custom_class()
20+
return node.get_class()
21+
22+
1723
func _enter_tree():
1824
if not Engine.is_editor_hint():
1925
return
2026

2127
# Create script
2228
if bsd == null:
2329
var new_bsd: BlockScriptData = load("res://addons/block_code/ui/bsd_templates/default_bsd.tres").duplicate(true)
24-
new_bsd.script_inherits = get_parent().call("get_class") # For whatever reason this works instead of just .get_class :)
30+
new_bsd.script_inherits = _get_custom_or_native_class(get_parent())
2531
new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits)
2632
bsd = new_bsd
2733

@@ -44,6 +50,8 @@ func _update_parent_script():
4450

4551

4652
func _get_configuration_warnings():
47-
if bsd:
48-
if get_parent().call("get_class") != bsd.script_inherits:
49-
return ["The parent is not a %s. Create a new BlockCode node and reattach." % bsd.script_inherits]
53+
var warnings = []
54+
if bsd and _get_custom_or_native_class(get_parent()) != bsd.script_inherits:
55+
var warning = "The parent is not a %s. Create a new BlockCode node and reattach." % bsd.script_inherits
56+
warnings.append(warning)
57+
return warnings

addons/block_code/simple_nodes/simple_character/simple_character.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func _ready():
99
$Sprite2D.texture = sprite_texture
1010

1111

12-
func get_class():
12+
func get_custom_class():
1313
return "SimpleCharacter"
1414

1515

0 commit comments

Comments
 (0)