This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Actors/Objects/ElectricSocket/ElectricSocket.gd

62 lines
1.4 KiB
GDScript3
Raw Normal View History

2020-07-08 12:30:46 +00:00
tool
2020-07-09 07:19:17 +00:00
class_name ElectricSocket
2020-07-08 12:30:46 +00:00
extends Area2D
enum Direction { LEFT, RIGHT, UP, DOWN }
2020-07-08 22:12:14 +00:00
enum Flow { SOURCE, SINK, BIDIRECTIONAL }
2020-07-08 12:30:46 +00:00
export(Direction) var direction = Direction.DOWN setget set_direction
2020-07-08 22:12:14 +00:00
export(Array, NodePath) var connectionPaths = []
var connections = []
2020-07-08 12:30:46 +00:00
export(Color) var source_color
export(Color) var sink_color
2020-07-08 22:12:14 +00:00
export(Color) var bidirectional_color
2020-07-08 12:30:46 +00:00
export(Flow) var flow = Flow.SINK setget set_flow
2020-07-08 22:12:14 +00:00
onready var socket = $socket
2020-07-09 07:19:17 +00:00
var network = null
2020-07-08 12:30:46 +00:00
func _ready():
2020-07-08 22:12:14 +00:00
socket.material = socket.material.duplicate()
2020-07-08 12:30:46 +00:00
refresh_sprite()
2020-07-08 22:12:14 +00:00
for connection in connectionPaths:
add_connection(get_node(connection))
func add_connection(node: Node):
var manager = node.get_node("PowerManager") as PowerManager
2020-07-09 07:19:17 +00:00
manager.socket = self
2020-07-08 12:30:46 +00:00
func set_direction(dir):
direction = dir
2020-07-08 22:12:14 +00:00
refresh_sprite()
2020-07-08 12:30:46 +00:00
func set_flow(val):
flow = val
2020-07-08 22:12:14 +00:00
refresh_sprite()
2020-07-08 12:30:46 +00:00
func refresh_sprite():
2020-07-08 22:12:14 +00:00
if socket == null:
return
2020-07-08 12:30:46 +00:00
match direction:
Direction.DOWN:
2020-07-08 22:12:14 +00:00
socket.region_rect.position = Vector2(0, 0)
2020-07-08 12:30:46 +00:00
Direction.UP:
2020-07-08 22:12:14 +00:00
socket.region_rect.position = Vector2(32, 0)
2020-07-08 12:30:46 +00:00
Direction.LEFT:
2020-07-08 22:12:14 +00:00
socket.region_rect.position = Vector2(32, 32)
2020-07-08 12:30:46 +00:00
Direction.RIGHT:
2020-07-08 22:12:14 +00:00
socket.region_rect.position = Vector2(0, 32)
2020-07-08 12:30:46 +00:00
match flow:
Flow.SOURCE:
2020-07-08 22:12:14 +00:00
socket.material.set_shader_param("cable_color", source_color)
2020-07-08 12:30:46 +00:00
Flow.SINK:
2020-07-08 22:12:14 +00:00
socket.material.set_shader_param("cable_color", sink_color)
Flow.BIDIRECTIONAL:
socket.material.set_shader_param("cable_color", bidirectional_color)