diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-06 22:35:04 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-06 22:35:04 +0100 |
commit | 63d2a59042fb9d90a586ad85d8364de7c38aea8e (patch) | |
tree | f4c648b39313f10f44898d0216a9147dfb4ba491 /Game | |
parent | f20b3a48a14f34def41d823fabb476981ef7055e (diff) |
next commit
Diffstat (limited to 'Game')
-rw-r--r-- | Game/Client.gd | 9 | ||||
-rw-r--r-- | Game/Selection/SelectionManager.gd | 24 | ||||
-rw-r--r-- | Game/Selection/SelectionManager.tscn | 6 | ||||
-rw-r--r-- | Game/States/Build/StateBuild.gd | 21 |
4 files changed, 46 insertions, 14 deletions
diff --git a/Game/Client.gd b/Game/Client.gd index 2c3bb69..7ca26ec 100644 --- a/Game/Client.gd +++ b/Game/Client.gd @@ -16,16 +16,17 @@ var state: State : var current_stage: Stage +var selection: SelectionManager + var player: Player: get(): return Network.get_player(multiplayer.get_unique_id()) -func _ready(): - pass - - func initialize_stage(stage: Stage): + selection = preload("res://Game/Selection/SelectionManager.tscn").instantiate() + add_child(selection) + current_stage = stage diff --git a/Game/Selection/SelectionManager.gd b/Game/Selection/SelectionManager.gd index c58dc69..49cb319 100644 --- a/Game/Selection/SelectionManager.gd +++ b/Game/Selection/SelectionManager.gd @@ -2,5 +2,29 @@ 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 diff --git a/Game/Selection/SelectionManager.tscn b/Game/Selection/SelectionManager.tscn new file mode 100644 index 0000000..e89880f --- /dev/null +++ b/Game/Selection/SelectionManager.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://mgm4npqeybbr"] + +[ext_resource type="Script" path="res://Game/Selection/SelectionManager.gd" id="1_1w5l7"] + +[node name="SelectionManager" type="Node"] +script = ExtResource("1_1w5l7") diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd index ea06671..0bd5efb 100644 --- a/Game/States/Build/StateBuild.gd +++ b/Game/States/Build/StateBuild.gd @@ -19,18 +19,19 @@ func _state_exit(): func _state_input(event: InputEvent): if event.is_action_pressed("builder_tower_select"): - if current_builder_element and current_builder_element.can_build(): + if current_builder_element: get_viewport().set_input_as_handled() - var placed_tower = current_builder_element.element.instantiate() as Tower - - placed_tower.global_position = current_builder_element.global_position - - Client.place_tower(placed_tower) - - if not Input.is_action_pressed("builder_tower_place_keep"): - current_builder_element.queue_free() - current_builder_element = null + if current_builder_element.can_build(): + var placed_tower = current_builder_element.element.instantiate() as Tower + + placed_tower.global_position = current_builder_element.global_position + + Client.place_tower(placed_tower) + + if not Input.is_action_pressed("builder_tower_place_keep"): + current_builder_element.queue_free() + current_builder_element = null if event.is_action_pressed("build_mode_start"): get_viewport().set_input_as_handled() |