miggor-StreamGraph/classes/deck/nodes/obs_set_source_transform.gd

109 lines
3.1 KiB
GDScript3
Raw Permalink Normal View History

# (c) 2023-present Eroax
# (c) 2023-present Yagich
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
extends DeckNode
var noobs: NoOBSWS
var lock := false # TODO: evaluate if this locking is actually needed
enum InputPorts{
SCENE_NAME,
SOURCE_ID,
XFORM,
SET,
}
func _init() -> void:
name = "Set Source Transform"
node_type = "obs_set_source_transform"
description = "Sets an OBS source's transform, which includes position and rotation, among other things."
category = "obs"
props_to_serialize = []
add_input_port(
DeckType.Types.STRING,
"Scene name",
"field"
)
add_input_port(
DeckType.Types.NUMERIC,
"Source ID",
"field"
)
add_input_port(
DeckType.Types.DICTIONARY,
"Transform"
)
add_input_port(
DeckType.Types.BOOL,
"Set",
"button"
)
func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> void:
#{ "scene_item_transform": { "alignment": 5, "bounds_alignment": 0, "bounds_height": 0, "bounds_type": "OBS_BOUNDS_NONE", "bounds_width": 0, "crop_bottom": 0, "crop_left": 0, "crop_right": 0, "crop_top": 0, "height": 257, "position_x": 1800, "position_y": 414, "rotation": 0, "scale_x": 1, "scale_y": 1, "source_height": 257, "source_width": 146, "width": 146 }}
if to_input_port != 3:
return
if noobs == null:
noobs = Connections.obs_websocket
if lock:
return
var scene_name: String
if request_value(InputPorts.SCENE_NAME) != null:
scene_name = request_value(InputPorts.SCENE_NAME)
elif get_input_ports()[InputPorts.SCENE_NAME].value_callback.get_object() && get_input_ports()[InputPorts.SCENE_NAME].value_callback.call() != "":
scene_name = get_input_ports()[InputPorts.SCENE_NAME].value_callback.call()
if scene_name.is_empty():
return
var source_id: float
var res_as = await request_value_async(InputPorts.SOURCE_ID)
if res_as != null:
source_id = res_as
elif get_input_ports()[InputPorts.SOURCE_ID].value_callback.get_object() && get_input_ports()[InputPorts.SOURCE_ID].value_callback.call() != null:
source_id = get_input_ports()[InputPorts.SOURCE_ID].value_callback.call()
var xform: Dictionary
if request_value(InputPorts.XFORM) != null:
xform = request_value(InputPorts.XFORM)
elif get_input_ports()[InputPorts.XFORM].value_callback.get_object() && get_input_ports()[InputPorts.XFORM].value_callback.call() != null:
xform = get_input_ports()[InputPorts.XFORM].value_callback.call()
if xform.is_empty():
return
lock = true
#noobs.make_generic_request("SetSceneItemTransform",
#{
#"scene_name": scene_name,
#"scene_item_id": source_id,
#"scene_item_transform": xform,
#})
#var sleep := noobs.make_generic_request("Sleep", {"sleep_frames": 1})
#sleep.response_received.connect(func(): lock = false)
var b := noobs.make_batch_request(false, NoOBSWS.Enums.RequestBatchExecutionType.SERIAL_FRAME)
b.add_request(
"SetSceneItemTransform",
"",
{
"scene_name": scene_name,
"scene_item_id": source_id,
"scene_item_transform": xform,
}
)
b.add_request("Sleep", "", {"sleep_frames": 1})
b.response_received.connect(func(): lock = false)
b.send()