summaryrefslogtreecommitdiff
path: root/Game/Selection/SelectionManager.gd
blob: 49cb3198797155bf86e3284faf719cee300fdfa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class_name SelectionManager
extends Node


var selection_groups := {}

signal selected_group_changed
var selected_group := "":
	set(value):
		selected_group = value
		selected_group_changed.emit()


func _ready() -> void:
	pass


func change_selection_group_id(towers: Array[Tower], previous_id: String, new_id: String) -> void:
	if new_id not in selection_groups:
		selection_groups[new_id] = []
	
	selection_groups[new_id].append_array(towers)
	
	for tower in towers:
		selection_groups[previous_id].erase(tower)
	
	if selection_groups[previous_id].is_empty():
		selection_groups.erase(previous_id)
		if previous_id == selected_group:
			selected_group = new_id