Skip to content

Commit

Permalink
Block code: Don't use get_class for custom classes
Browse files Browse the repository at this point in the history
Overriding the native get_class is not supported and raises an error.
Add a method to get either the custom or the native class.
  • Loading branch information
manuq committed Jun 19, 2024
1 parent 80b227a commit 29f250a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions addons/block_code/block_code_node/block_code.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ 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

# 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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func _ready():
$Sprite2D.texture = sprite_texture


func get_class():
func get_custom_class():
return "SimpleCharacter"


Expand Down

0 comments on commit 29f250a

Please sign in to comment.