1
0
Fork 0
spacetac/arenas/anchor.gd

49 lines
1.0 KiB
GDScript

extends Sprite
class_name Anchor
export var selectable = false
export var selected = false
export(String, "normal", "attack_start", "defend_start") var anchor_type = "normal"
var content
func _process(delta):
if selected:
modulate = Color(1, 0.4, 0.4)
elif selectable:
modulate = Color(1, 0.8, 0.2)
else:
modulate = Color(1, 1, 1)
func _ready():
add_to_group("anchors")
if not content and self.get_child_count() == 1:
set_content(self.get_child(0))
func is_connected_to(other: Anchor) -> bool:
for route in get_tree().get_nodes_in_group("routes"):
if route is Route and route.is_connecting(self, other):
return true
return false
func set_content(val):
if val is Node:
var old_parent = val.get_parent()
if old_parent:
if old_parent.has_method("set_content"):
old_parent.set_content(null)
old_parent.remove_child(val)
if not get_children().has(val):
add_child(val)
content = val
else:
content = null
func get_content():
return content if content else null
func is_empty() -> bool:
return not content