29 lines
896 B
GDScript
29 lines
896 B
GDScript
static func update_anchors(tree: SceneTree, position, acceptability) -> Anchor:
|
|
""" Update anchor visual hint, and return selected one
|
|
"""
|
|
var anchors = tree.get_nodes_in_group("anchors")
|
|
for anchor in anchors:
|
|
anchor.selectable = position and acceptability.call_func(anchor)
|
|
|
|
var selected_anchor = null
|
|
var selected_distance = INF
|
|
for anchor in anchors:
|
|
if anchor.selectable:
|
|
var distance = anchor.global_position.distance_to(position)
|
|
if distance < 150 and distance < selected_distance:
|
|
selected_anchor = anchor
|
|
selected_distance = distance
|
|
|
|
for anchor in anchors:
|
|
anchor.selected = (anchor == selected_anchor)
|
|
|
|
return selected_anchor
|
|
|
|
static func spawn_unit(name: String, anchor: Anchor) -> Node:
|
|
""" Spawn a unit on an empty anchor
|
|
"""
|
|
var scene = load("res://units/" + name + ".tscn")
|
|
var node = scene.instance()
|
|
anchor.set_content(node)
|
|
return node
|