52 lines
1.4 KiB
GDScript3
52 lines
1.4 KiB
GDScript3
|
tool
|
||
|
|
||
|
extends Control
|
||
|
|
||
|
var socketTemplate = preload("res://Actors/Objects/ElectricSocket/ElectricSocket.tscn")
|
||
|
|
||
|
var api : EditorPlugin
|
||
|
|
||
|
onready var socket_types = $Commands/MakeSocket/Type
|
||
|
|
||
|
func _ready():
|
||
|
# Add make_socket options
|
||
|
socket_types.add_item("SNK", 0)
|
||
|
socket_types.add_item("SRC", 1)
|
||
|
socket_types.add_item("BID", 2)
|
||
|
|
||
|
func _make_socket(direction: String) -> void:
|
||
|
var socket_dir = null
|
||
|
var socket_type = null
|
||
|
var offset = Vector2.ZERO
|
||
|
match direction:
|
||
|
"up":
|
||
|
socket_dir = ElectricSocket.Direction.DOWN
|
||
|
offset.y = -32
|
||
|
"left":
|
||
|
socket_dir = ElectricSocket.Direction.RIGHT
|
||
|
offset.x = -32
|
||
|
"down":
|
||
|
socket_dir = ElectricSocket.Direction.UP
|
||
|
offset.y = 32
|
||
|
"right":
|
||
|
socket_dir = ElectricSocket.Direction.LEFT
|
||
|
offset.x = 32
|
||
|
match socket_types.get_selected_id():
|
||
|
0:
|
||
|
socket_type = ElectricSocket.Flow.SINK
|
||
|
1:
|
||
|
socket_type = ElectricSocket.Flow.SOURCE
|
||
|
2:
|
||
|
socket_type = ElectricSocket.Flow.BIDIRECTIONAL
|
||
|
var map = api.get_editor_interface().get_edited_scene_root()
|
||
|
var sockets = map.get_node("sockets")
|
||
|
var nodes = api.get_editor_interface().get_selection().get_selected_nodes()
|
||
|
for node in nodes:
|
||
|
var socket = socketTemplate.instance()
|
||
|
socket.direction = socket_dir
|
||
|
socket.flow = socket_type
|
||
|
sockets.add_child(socket)
|
||
|
socket.owner = map
|
||
|
socket.global_position = node.global_position + offset
|
||
|
socket.connectionPaths = [socket.get_path_to(node)]
|