From 860370bd4e47eceab81b3d7383dac7360f1086e6 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Sun, 30 Apr 2023 14:52:01 +0300 Subject: [PATCH] Add a get_class_name() method in the cel classes I wish Godot had a method for this already --- src/Autoload/ExtensionsAPI.gd | 13 ++----------- src/Classes/BaseCel.gd | 4 ++++ src/Classes/Cel3D.gd | 4 ++++ src/Classes/GroupCel.gd | 4 ++++ src/Classes/PixelCel.gd | 4 ++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Autoload/ExtensionsAPI.gd b/src/Autoload/ExtensionsAPI.gd index 26ad91f03..b532af06c 100644 --- a/src/Autoload/ExtensionsAPI.gd +++ b/src/Autoload/ExtensionsAPI.gd @@ -303,14 +303,5 @@ class ProjectAPI: # then the old extension would have no idea how to identify the types they use # E.g the extension may try to use a GroupCel as a PixelCel (if it doesn't know the difference) # So it's encouraged to use this function to access cels - var project = get_current_project() - var cel = project.get_current_cel() - # Add cel types as we have more and more cels - if cel is PixelCel: - return {"cel": cel, "type": "PixelCel"} - elif cel is GroupCel: - return {"cel": cel, "type": "GroupCel"} - elif cel is Cel3D: - return {"cel": cel, "type": "Cel3D"} - else: - return {"cel": cel, "type": "BaseCel"} + var cel := get_current_project().get_current_cel() + return {"cel": cel, "type": cel.get_class_name()} diff --git a/src/Classes/BaseCel.gd b/src/Classes/BaseCel.gd index a6bce36b8..796b6d55e 100644 --- a/src/Classes/BaseCel.gd +++ b/src/Classes/BaseCel.gd @@ -73,3 +73,7 @@ func on_remove() -> void: func instantiate_cel_button() -> Node: return null + + +func get_class_name() -> String: + return "BaseCel" diff --git a/src/Classes/Cel3D.gd b/src/Classes/Cel3D.gd index 23efb7ced..a6cf54391 100644 --- a/src/Classes/Cel3D.gd +++ b/src/Classes/Cel3D.gd @@ -210,3 +210,7 @@ func load_image_data_from_pxo(file: File, project_size: Vector2) -> void: func instantiate_cel_button() -> Node: return Global.pixel_cel_button_node.instance() + + +func get_class_name() -> String: + return "Cel3D" diff --git a/src/Classes/GroupCel.gd b/src/Classes/GroupCel.gd index 55d7cbd7b..d9f006628 100644 --- a/src/Classes/GroupCel.gd +++ b/src/Classes/GroupCel.gd @@ -19,3 +19,7 @@ func get_image() -> Image: func instantiate_cel_button() -> Node: return Global.group_cel_button_node.instance() + + +func get_class_name() -> String: + return "GroupCel" diff --git a/src/Classes/PixelCel.gd b/src/Classes/PixelCel.gd index 649f1552e..dff5d8357 100644 --- a/src/Classes/PixelCel.gd +++ b/src/Classes/PixelCel.gd @@ -71,3 +71,7 @@ func load_image_data_from_pxo(file: File, project_size: Vector2) -> void: func instantiate_cel_button() -> Node: return Global.pixel_cel_button_node.instance() + + +func get_class_name() -> String: + return "PixelCel"