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, attacker: bool) -> Node: """ Spawn a unit on an empty anchor """ var scene = load("res://units/" + name + ".tscn") var node = scene.instance() anchor.set_content(node) node.attacker = attacker return node static func list_units(tree: SceneTree): """ List all units in battle """ var units = [] for anchor in tree.get_nodes_in_group("anchors"): var content = anchor.get_content() if content: units.append(content) return units static func get_state(tree: SceneTree): """ Build the simple state associated with current battle scene """ var nodes = [] var routes = [] for anchor in tree.get_nodes_in_group("anchors"): pass for route in tree.get_nodes_in_group("routes"): pass return { "nodes": nodes, "routes": routes }