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

38 lines
836 B
GDScript3
Raw Normal View History

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