1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

ExtensionApi Improvements (#959)

* Improved signal api

* added two more signals

* Improved debug messaging system

* fix typo
This commit is contained in:
Variable 2023-12-14 06:44:50 +05:00 committed by GitHub
parent 17ee10a131
commit 8d09713774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 97 deletions

View file

@ -46,7 +46,7 @@ func check_sanity(extension_name: String):
extension_history, extension_history,
" which are not removed properly" " which are not removed properly"
) )
print(error_msg) printerr(error_msg)
## [code]This function is used internally and not meant to be used by extensions.[/code] ## [code]This function is used internally and not meant to be used by extensions.[/code]
@ -56,7 +56,8 @@ func clear_history(extension_name: String):
## [code]This function is used internally and not meant to be used by extensions.[/code] ## [code]This function is used internally and not meant to be used by extensions.[/code]
func add_action(action: String): func add_action(section: String, key: String):
var action = str(section, "/", key)
var extension_name = _get_caller_extension_name() var extension_name = _get_caller_extension_name()
if extension_name != "Unknown": if extension_name != "Unknown":
if extension_name in _action_history.keys(): if extension_name in _action_history.keys():
@ -67,7 +68,8 @@ func add_action(action: String):
## [code]This function is used internally and not meant to be used by extensions.[/code] ## [code]This function is used internally and not meant to be used by extensions.[/code]
func remove_action(action: String): func remove_action(section: String, key: String):
var action = str(section, "/", key)
var extension_name = _get_caller_extension_name() var extension_name = _get_caller_extension_name()
if extension_name != "Unknown": if extension_name != "Unknown":
if extension_name in _action_history.keys(): if extension_name in _action_history.keys():
@ -97,7 +99,7 @@ func _exit_tree():
check_sanity(keys) check_sanity(keys)
# The Api Methods Start Here # The API Methods Start Here
## Returns the version of the ExtensionsApi. ## Returns the version of the ExtensionsApi.
func get_api_version() -> int: func get_api_version() -> int:
return ProjectSettings.get_setting("application/config/ExtensionsAPI_Version") return ProjectSettings.get_setting("application/config/ExtensionsAPI_Version")
@ -198,7 +200,7 @@ class MenuAPI:
if item_id == -1: if item_id == -1:
idx = popup_menu.get_item_count() - 1 idx = popup_menu.get_item_count() - 1
popup_menu.set_item_metadata(idx, item_metadata) popup_menu.set_item_metadata(idx, item_metadata)
ExtensionsApi.add_action("add_menu") ExtensionsApi.add_action("MenuAPI", "add_menu")
return idx return idx
## Removes a menu item at index [param item_idx] from the [param menu_type] defined by ## Removes a menu item at index [param item_idx] from the [param menu_type] defined by
@ -208,7 +210,7 @@ class MenuAPI:
if not popup_menu: if not popup_menu:
return return
popup_menu.remove_item(item_idx) popup_menu.remove_item(item_idx)
ExtensionsApi.remove_action("add_menu") ExtensionsApi.remove_action("MenuAPI", "add_menu")
## Gives access to common dialog related functions. ## Gives access to common dialog related functions.
@ -269,7 +271,7 @@ class PanelAPI:
dockable.tabs_visible = true dockable.tabs_visible = true
await ExtensionsApi.wait_frame() await ExtensionsApi.wait_frame()
dockable.tabs_visible = false dockable.tabs_visible = false
ExtensionsApi.add_action("add_tab") ExtensionsApi.add_action("PanelAPI", "add_tab")
## Removes the [param node] from the DockableContainer. ## Removes the [param node] from the DockableContainer.
func remove_node_from_tab(node: Node) -> void: func remove_node_from_tab(node: Node) -> void:
@ -300,7 +302,7 @@ class PanelAPI:
dockable.tabs_visible = true dockable.tabs_visible = true
await ExtensionsApi.wait_frame() await ExtensionsApi.wait_frame()
dockable.tabs_visible = false dockable.tabs_visible = false
ExtensionsApi.remove_action("add_tab") ExtensionsApi.remove_action("PanelAPI", "add_tab")
# PRIVATE METHODS # PRIVATE METHODS
func _get_dockable_container_ui() -> Node: func _get_dockable_container_ui() -> Node:
@ -366,7 +368,7 @@ class ThemeAPI:
var themes: BoxContainer = Global.preferences_dialog.find_child("Themes") var themes: BoxContainer = Global.preferences_dialog.find_child("Themes")
themes.themes.append(theme) themes.themes.append(theme)
themes.add_theme(theme) themes.add_theme(theme)
ExtensionsApi.add_action("add_theme") ExtensionsApi.add_action("ThemeAPI", "add_theme")
## Returns index of the [param theme] in preferences. ## Returns index of the [param theme] in preferences.
func find_theme_index(theme: Theme) -> int: func find_theme_index(theme: Theme) -> int:
@ -390,7 +392,7 @@ class ThemeAPI:
## Remove the [param theme] from preferences. ## Remove the [param theme] from preferences.
func remove_theme(theme: Theme) -> void: func remove_theme(theme: Theme) -> void:
Global.preferences_dialog.themes.remove_theme(theme) Global.preferences_dialog.themes.remove_theme(theme)
ExtensionsApi.remove_action("add_theme") ExtensionsApi.remove_action("ThemeAPI", "add_theme")
## Gives ability to add/remove tools. ## Gives ability to add/remove tools.
@ -419,7 +421,7 @@ class ToolAPI:
) )
Tools.tools[tool_name] = tool_class Tools.tools[tool_name] = tool_class
Tools.add_tool_button(tool_class) Tools.add_tool_button(tool_class)
ExtensionsApi.add_action("add_tool") ExtensionsApi.add_action("ToolAPI", "add_tool")
## Removes a tool with name [param tool_name] ## Removes a tool with name [param tool_name]
## and assign Pencil as left tool, Eraser as right tool. ## and assign Pencil as left tool, Eraser as right tool.
@ -430,7 +432,7 @@ class ToolAPI:
var tool_class: Tools.Tool = Tools.tools[tool_name] var tool_class: Tools.Tool = Tools.tools[tool_name]
if tool_class: if tool_class:
Tools.remove_tool(tool_class) Tools.remove_tool(tool_class)
ExtensionsApi.remove_action("add_tool") ExtensionsApi.remove_action("ToolAPI", "add_tool")
## Gives access to pixelorama's selection system. ## Gives access to pixelorama's selection system.
@ -659,14 +661,14 @@ class ExportAPI:
var id = Export.add_custom_file_format( var id = Export.add_custom_file_format(
format_name, extension, exporter_generator, tab, is_animated format_name, extension, exporter_generator, tab, is_animated
) )
ExtensionsApi.add_action("add_exporter") ExtensionsApi.add_action("ExportAPI", "add_exporter")
return id return id
## Removes the exporter with [param id] from Pixelorama. ## Removes the exporter with [param id] from Pixelorama.
func remove_export_option(id: int): func remove_export_option(id: int):
if Export.custom_exporter_generators.has(id): if Export.custom_exporter_generators.has(id):
Export.remove_custom_file_format(id) Export.remove_custom_file_format(id)
ExtensionsApi.remove_action("add_exporter") ExtensionsApi.remove_action("ExportAPI", "add_exporter")
## Gives access to adding custom import options. ## Gives access to adding custom import options.
@ -721,107 +723,78 @@ class SignalsAPI:
func _on_texture_changed(): func _on_texture_changed():
texture_changed.emit() texture_changed.emit()
# GLOBAL SIGNALS func _connect_disconnect(signal_class: Signal, callable: Callable, disconnect := false):
## connects a signal to [param callable], that emits if !disconnect:
signal_class.connect(callable)
ExtensionsApi.add_action("SignalsAPI", signal_class.get_name())
else:
signal_class.disconnect(callable)
ExtensionsApi.remove_action("SignalsAPI", signal_class.get_name())
# APP RELATED SIGNALS
## connects/disconnects a signal to [param callable], that emits
## when pixelorama is just opened. ## when pixelorama is just opened.
func connect_pixelorama_opened(callable: Callable): func signal_pixelorama_opened(callable: Callable, disconnect := false):
Global.pixelorama_opened.connect(callable) _connect_disconnect(Global.pixelorama_opened, callable, disconnect)
ExtensionsApi.add_action("pixelorama_opened")
## Reverse of [method connect_pixelorama_opened]. ## connects/disconnects a signal to [param callable], that emits
func disconnect_pixelorama_opened(callable: Callable):
Global.pixelorama_opened.disconnect(callable)
ExtensionsApi.remove_action("pixelorama_opened")
## connects a signal to [param callable], that emits
## when pixelorama is about to close. ## when pixelorama is about to close.
func connect_pixelorama_about_to_close(callable: Callable): func signal_pixelorama_about_to_close(callable: Callable, disconnect := false):
Global.pixelorama_about_to_close.connect(callable) _connect_disconnect(Global.pixelorama_about_to_close, callable, disconnect)
ExtensionsApi.add_action("pixelorama_about_to_close")
## Reverse of [method connect_pixelorama_about_to_close]. # PROJECT RELATED SIGNALS
func disconnect_pixelorama_about_to_close(callable: Callable): ## connects/disconnects a signal to [param callable], that emits
Global.pixelorama_about_to_close.disconnect(callable)
ExtensionsApi.remove_action("pixelorama_about_to_close")
## connects a signal to [param callable], that emits
## whenever a new project is created.[br] ## whenever a new project is created.[br]
## [b]Binds: [/b]It has one bind of type [code]Project[/code] which is the newly created project ## [b]Binds: [/b]It has one bind of type [code]Project[/code] which is the newly created project
func connect_project_created(callable: Callable): func signal_project_created(callable: Callable, disconnect := false):
Global.project_created.connect(callable) _connect_disconnect(Global.project_created, callable, disconnect)
ExtensionsApi.add_action("project_created")
## Reverse of [method connect_project_created]. ## connects/disconnects a signal to [param callable], that emits
func disconnect_project_created(callable: Callable): ## after a project is saved.
Global.project_created.disconnect(callable) func signal_project_saved(callable: Callable, disconnect := false):
ExtensionsApi.remove_action("project_created") _connect_disconnect(OpenSave.project_saved, callable, disconnect)
## connects a signal to [param callable], that emits ## connects/disconnects a signal to [param callable], that emits
## whenever project is about to be saved.
func connect_project_about_to_save(callable: Callable):
Global.project_saved.connect(callable)
ExtensionsApi.add_action("project_saved")
## Reverse of [method connect_project_about_to_save].
func disconnect_project_saved(callable: Callable):
Global.project_saved.disconnect(callable)
ExtensionsApi.remove_action("project_saved")
## connects a signal to [param callable], that emits
## whenever you switch to some other project. ## whenever you switch to some other project.
func connect_project_changed(callable: Callable): func signal_project_changed(callable: Callable, disconnect := false):
Global.project_changed.connect(callable) _connect_disconnect(Global.project_changed, callable, disconnect)
ExtensionsApi.add_action("project_changed")
## Reverse of [method connect_project_changed]. ## connects/disconnects a signal to [param callable], that emits
func disconnect_project_changed(callable: Callable):
Global.project_changed.disconnect(callable)
ExtensionsApi.remove_action("project_changed")
## connects a signal to [param callable], that emits
## whenever you select a different cel. ## whenever you select a different cel.
func connect_cel_changed(callable: Callable): func signal_cel_changed(callable: Callable, disconnect := false):
Global.cel_changed.connect(callable) _connect_disconnect(Global.cel_changed, callable, disconnect)
ExtensionsApi.add_action("cel_changed")
## Reverse of [method connect_cel_changed]. # TOOL RELATED SIGNALS
func disconnect_cel_changed(callable: Callable): ## connects/disconnects a signal to [param callable], that emits
Global.cel_changed.disconnect(callable) ## whenever a tool changes color.[br]
ExtensionsApi.remove_action("cel_changed") ## [b]Binds: [/b] It has two bind of type [Color] (indicating new color)
## and [int] (Indicating button that tool is assigned to, see [enum @GlobalScope.MouseButton])
func signal_tool_color_changed(callable: Callable, disconnect := false):
_connect_disconnect(Tools.color_changed, callable, disconnect)
# TOOL SIGNALS # TIMELINE RELATED SIGNALS
## connects a signal to [param callable], that emits ## connects/disconnects a signal to [param callable], that emits
## whenever a tool changes color. ## whenever timeline animation starts.[br]
func connect_tool_color_changed(callable: Callable): ## [b]Binds: [/b] It has one bind of type [bool] which indicated if animation is in
Tools.color_changed.connect(callable) ## forward direction ([code]true[/code]) or backward direction ([code]false[/code])
ExtensionsApi.add_action("color_changed") func signal_timeline_animation_started(callable: Callable, disconnect := false):
_connect_disconnect(Global.animation_timeline.animation_started, callable, disconnect)
## Reverse of [method connect_tool_color_changed]. ## connects/disconnects a signal to [param callable], that emits
func disconnect_tool_color_changed(callable: Callable): ## whenever timeline animation stops.
Tools.color_changed.disconnect(callable) func signal_timeline_animation_finished(callable: Callable, disconnect := false):
ExtensionsApi.remove_action("color_changed") _connect_disconnect(Global.animation_timeline.animation_finished, callable, disconnect)
# UPDATER SIGNALS # UPDATER SIGNALS
## connects a signal to [param callable], that emits ## connects/disconnects a signal to [param callable], that emits
## whenever texture of the currently focused cel changes. ## whenever texture of the currently focused cel changes.
func connect_current_cel_texture_changed(callable: Callable): func signal_current_cel_texture_changed(callable: Callable, disconnect := false):
texture_changed.connect(callable) _connect_disconnect(texture_changed, callable, disconnect)
ExtensionsApi.add_action("texture_changed")
## Reverse of [method connect_current_cel_texture_changed]. ## connects/disconnects a signal to [param callable], that emits
func disconnect_current_cel_texture_changed(callable: Callable):
texture_changed.disconnect(callable)
ExtensionsApi.remove_action("texture_changed")
## connects a signal to [param callable], that emits
## whenever preview is about to be drawn.[br] ## whenever preview is about to be drawn.[br]
## [b]Binds: [/b]It has one bind of type [Dictionary] with keys: [code]exporter_id[/code], ## [b]Binds: [/b]It has one bind of type [Dictionary] with keys: [code]exporter_id[/code],
## [code]export_tab[/code], [code]preview_images[/code], [code]durations[/code] ## [code]export_tab[/code], [code]preview_images[/code], [code]durations[/code]
func connect_export_about_to_preview(callable: Callable): ## [br] Use this if you plan on changing preview of export
Global.export_dialog.about_to_preview.connect(callable) func signal_export_about_to_preview(callable: Callable, disconnect := false):
ExtensionsApi.add_action("export_about_to_preview") _connect_disconnect(Global.export_dialog.about_to_preview, callable, disconnect)
## Reverse of [method connect_export_about_to_preview].
func disconnect_export_about_to_preview(callable: Callable):
Global.export_dialog.about_to_preview.disconnect(callable)
ExtensionsApi.remove_action("export_about_to_preview")

View file

@ -1,5 +1,8 @@
extends Panel extends Panel
signal animation_started(forward: bool)
signal animation_finished
const FRAME_BUTTON_TSCN := preload("res://src/UI/Timeline/FrameButton.tscn") const FRAME_BUTTON_TSCN := preload("res://src/UI/Timeline/FrameButton.tscn")
var is_animation_running := false var is_animation_running := false
@ -560,6 +563,7 @@ func _on_AnimationTimer_timeout() -> void:
play_forward.button_pressed = false play_forward.button_pressed = false
play_backwards.button_pressed = false play_backwards.button_pressed = false
Global.animation_timer.stop() Global.animation_timer.stop()
animation_finished.emit()
is_animation_running = false is_animation_running = false
1: # Cycle loop 1: # Cycle loop
project.selected_cels.clear() project.selected_cels.clear()
@ -586,6 +590,7 @@ func _on_AnimationTimer_timeout() -> void:
play_backwards.button_pressed = false play_backwards.button_pressed = false
play_forward.button_pressed = false play_forward.button_pressed = false
Global.animation_timer.stop() Global.animation_timer.stop()
animation_finished.emit()
is_animation_running = false is_animation_running = false
1: # Cycle loop 1: # Cycle loop
project.selected_cels.clear() project.selected_cels.clear()
@ -640,8 +645,10 @@ func play_animation(play: bool, forward_dir: bool) -> void:
Global.animation_timer.wait_time = duration * (1 / Global.current_project.fps) Global.animation_timer.wait_time = duration * (1 / Global.current_project.fps)
Global.animation_timer.start() Global.animation_timer.start()
animation_forward = forward_dir animation_forward = forward_dir
animation_started.emit(forward_dir)
else: else:
Global.animation_timer.stop() Global.animation_timer.stop()
animation_finished.emit()
is_animation_running = play is_animation_running = play