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/Systems/Electricity/ElectricProbe.gd
2020-07-09 09:19:17 +02:00

37 lines
836 B
GDScript

extends Area2D
class_name ProbeElectric
const center = Vector2.ONE * 16
var neighbours = []
var network: PowerNetwork = null
func _ready():
if network == null:
network = PowerNetwork.new()
network.add_node(self)
$"/root/scene/systems".add_child(network, true)
func _physics_process(_delta):
if PowerNetwork.DEBUG:
update()
func _draw():
if PowerNetwork.DEBUG:
draw_circle(center, 4, network.debugColor)
for neighbour in neighbours:
var delta = (neighbour.global_position - global_position) / global_scale
draw_line(center, delta + center, network.debugColor, 2)
func _got_neighbour(area: Area2D):
if area == self:
return
if area.network == null:
area.network = network
network.add_node(area)
elif area.network != network:
# Merge networks
network.join(area.network)
neighbours.push_back(area)