From d7e33f4431905e532f22bd3ce31418ecbbc94169 Mon Sep 17 00:00:00 2001 From: Variable <77773850+Variable-ind@users.noreply.github.com> Date: Wed, 4 Jan 2023 19:21:15 +0500 Subject: [PATCH] Api Improvements (#802) * Api Improvements Proper Removal of Tools A new `get_current_cel_info()` method * a new show_error() method usefull for displaying messages like "Incompatible API" etc... * typo * formatting * added an improvement --- src/Autoload/ExtensionsAPI.gd | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Autoload/ExtensionsAPI.gd b/src/Autoload/ExtensionsAPI.gd index 012848592..549524ed5 100644 --- a/src/Autoload/ExtensionsAPI.gd +++ b/src/Autoload/ExtensionsAPI.gd @@ -4,6 +4,13 @@ extends Node enum { FILE, EDIT, SELECT, IMAGE, VIEW, WINDOW, HELP } +func show_error(text: String) -> void: + # useful for displaying messages like "Incompatible API" etc... + Global.error_dialog.set_text(text) + Global.error_dialog.popup_centered() + Global.dialog_open(true) + + func get_api_version() -> int: return ProjectSettings.get_setting("application/config/ExtensionsAPI_Version") @@ -20,6 +27,22 @@ func get_current_project() -> Project: return Global.current_project +func get_current_cel_info() -> Dictionary: + # As types of cel are added to Pixelorama, + # 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"} + else: + return {"cel": cel, "type": "BaseCel"} + + func get_global() -> Global: return Global @@ -160,7 +183,6 @@ func add_menu_item(menu_type: int, item_name: String, item_metadata, item_id := if item_id == -1: idx = popup_menu.get_item_count() - 1 popup_menu.set_item_metadata(idx, item_metadata) - return idx @@ -188,6 +210,9 @@ func add_tool( func remove_tool(tool_name: String) -> void: + # Re-assigning the tools in case the tool to be removed is also Active + Tools.assign_tool("Pencil", BUTTON_LEFT) + Tools.assign_tool("Eraser", BUTTON_RIGHT) var tool_class: Tools.Tool = Tools.tools[tool_name] if tool_class: Tools.remove_tool(tool_class)