54 lines
1.1 KiB
GDScript
54 lines
1.1 KiB
GDScript
tool
|
|
|
|
extends Area2D
|
|
|
|
enum Direction { LEFT, RIGHT, UP, DOWN }
|
|
enum Flow { SOURCE, SINK }
|
|
|
|
export(Direction) var direction = Direction.DOWN setget set_direction
|
|
|
|
export(Array, NodePath) var connections = []
|
|
|
|
export(Color) var source_color
|
|
export(Color) var sink_color
|
|
|
|
export(Flow) var flow = Flow.SINK setget set_flow
|
|
|
|
var ready = false
|
|
|
|
func _ready():
|
|
ready = true
|
|
$socket.material = $socket.material.duplicate()
|
|
refresh_sprite()
|
|
|
|
func set_direction(dir):
|
|
direction = dir
|
|
if ready:
|
|
refresh_sprite()
|
|
|
|
func set_flow(val):
|
|
flow = val
|
|
if ready:
|
|
refresh_sprite()
|
|
|
|
func refresh_sprite():
|
|
var rot = 0
|
|
match direction:
|
|
Direction.DOWN:
|
|
$socket.region_rect.position = Vector2(0, 0)
|
|
rot = 0
|
|
Direction.UP:
|
|
$socket.region_rect.position = Vector2(32, 0)
|
|
rot = PI
|
|
Direction.LEFT:
|
|
$socket.region_rect.position = Vector2(32, 32)
|
|
rot = PI/2
|
|
Direction.RIGHT:
|
|
$socket.region_rect.position = Vector2(0, 32)
|
|
rot = -PI/2
|
|
match flow:
|
|
Flow.SOURCE:
|
|
$socket.material.set_shader_param("cable_color", source_color)
|
|
Flow.SINK:
|
|
$socket.material.set_shader_param("cable_color", sink_color)
|