1
0
Fork 0
spacetac/arenas/anchor.gd

49 lines
1 KiB
GDScript3
Raw Normal View History

2020-02-03 21:59:43 +00:00
extends Sprite
class_name Anchor
export var selectable = false
export var selected = false
export(String, "normal", "attack_start", "defend_start") var anchor_type = "normal"
2020-02-27 23:41:11 +00:00
var content
2020-02-03 21:59:43 +00:00
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)
2020-02-18 22:24:00 +00:00
2020-02-03 21:59:43 +00:00
func _ready():
add_to_group("anchors")
2020-02-18 22:24:00 +00:00
2020-02-27 23:41:11 +00:00
if not content and self.get_child_count() == 1:
set_content(self.get_child(0))
2020-02-03 21:59:43 +00:00
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
2020-02-18 22:24:00 +00:00
2020-02-03 21:59:43 +00:00
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)
2020-02-27 23:41:11 +00:00
if not get_children().has(val):
add_child(val)
content = val
2020-02-09 23:28:05 +00:00
else:
content = null
2020-02-18 22:24:00 +00:00
2020-02-09 23:28:05 +00:00
func get_content():
2020-02-27 23:41:11 +00:00
return content if content else null
2020-02-18 22:24:00 +00:00
2020-02-03 21:59:43 +00:00
func is_empty() -> bool:
2020-02-27 23:41:11 +00:00
return not content