1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Signal api (#851)

* New SignalAPI

* more project methods

* re-order

* Update ExtensionsAPI.gd

* some fixes

* fixes

* more fixes

* Fixes

* typo

* added a required `project_changed`

* Update ExtensionsAPI.gd

* Update ExtensionsAPI.gd
This commit is contained in:
Variable 2023-05-01 14:50:15 +05:00 committed by GitHub
parent 860370bd4e
commit 44c2df98e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View file

@ -9,6 +9,7 @@ var panel = PanelAPI.new()
var theme = ThemeAPI.new()
var tools = ToolAPI.new()
var project = ProjectAPI.new()
var signals = SignalsAPI.new()
# This fail-safe below is designed to work ONLY if Pixelorama is launched in Godot Editor
var _action_history: Dictionary = {}
@ -305,3 +306,65 @@ class ProjectAPI:
# So it's encouraged to use this function to access cels
var cel := get_current_project().get_current_cel()
return {"cel": cel, "type": cel.get_class_name()}
func get_cel_info_at(project: Project, frame: int, layer: int) -> Dictionary:
# frames from left to right, layers from bottomn to top
clamp(frame, 0, project.frames.size() - 1)
clamp(layer, 0, project.layers.size() - 1)
var cel = project.frames[frame].cels[layer]
return {"cel": cel, "type": cel.get_class_name()}
class SignalsAPI:
# system to auto-adjust texture_changed to the "current cel"
signal texture_changed
var _last_cel: BaseCel
func _init() -> void:
Global.connect("project_changed", self, "_update_texture_signal")
Global.connect("cel_changed", self, "_update_texture_signal")
func _update_texture_signal():
if _last_cel:
_last_cel.disconnect("texture_changed", self, "_on_texture_changed")
if Global.current_project:
_last_cel = Global.current_project.get_current_cel()
_last_cel.connect("texture_changed", self, "_on_texture_changed")
func _on_texture_changed():
emit_signal("texture_changed")
# Global signals
func connect_project_changed(target: Object, method: String):
Global.connect("project_changed", target, method)
ExtensionsApi.add_action("project_changed")
func disconnect_project_changed(target: Object, method: String):
Global.disconnect("project_changed", target, method)
ExtensionsApi.remove_action("project_changed")
func connect_cel_changed(target: Object, method: String):
Global.connect("cel_changed", target, method)
ExtensionsApi.add_action("cel_changed")
func disconnect_cel_changed(target: Object, method: String):
Global.disconnect("cel_changed", target, method)
ExtensionsApi.remove_action("cel_changed")
# Tool Signal
func connect_tool_color_changed(target: Object, method: String):
Tools.connect("color_changed", target, method)
ExtensionsApi.add_action("color_changed")
func disconnect_tool_color_changed(target: Object, method: String):
Tools.disconnect("color_changed", target, method)
ExtensionsApi.remove_action("color_changed")
# updater signals
func connect_current_cel_texture_changed(target: Object, method: String):
connect("texture_changed", target, method)
ExtensionsApi.add_action("texture_changed")
func disconnect_current_cel_texture_changed(target: Object, method: String):
disconnect("texture_changed", target, method)
ExtensionsApi.remove_action("texture_changed")

View file

@ -252,6 +252,8 @@ func _ready() -> void:
var tooltip: String = node.hint_tooltip
if !tooltip.empty() and node.shortcut:
ui_tooltips[node] = tooltip
yield(get_tree(), "idle_frame")
emit_signal("project_changed")
func _initialize_keychain() -> void: