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
871 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
master func _ready():
2020-07-08 22:12:14 +00:00
if network == null:
network = PowerNetwork.new()
network.add_node(self)
$"/root/scene/systems".add_child(network, true)
master 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
master func _got_neighbour(area: Area2D):
2020-07-08 12:30:46 +00:00
if area == self:
return
2020-07-08 22:12:14 +00:00
if area.network == null:
area.network = network
network.rpc("add_node", area)
2020-07-08 22:12:14 +00:00
elif area.network != network:
# Merge networks
network.rpc("join", area.network)
2020-07-08 12:30:46 +00:00
neighbours.push_back(area)