diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-09-28 15:27:43 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-09-28 15:27:43 +0200 |
commit | b96e384d8299473b14edcbf885fa914a9308d18f (patch) | |
tree | 0bde9428f42b309ea167a41473252bda8035e21a /Game/States | |
parent | 4597189f157834c80f56b12b701fd2b2a15c2798 (diff) |
next commit
Diffstat (limited to 'Game/States')
-rw-r--r-- | Game/States/Build/BuilderElement.gd | 3 | ||||
-rw-r--r-- | Game/States/Build/StateBuild.gd | 26 | ||||
-rw-r--r-- | Game/States/Default/StateDefault.gd | 6 |
3 files changed, 15 insertions, 20 deletions
diff --git a/Game/States/Build/BuilderElement.gd b/Game/States/Build/BuilderElement.gd index 8315792..bb10b06 100644 --- a/Game/States/Build/BuilderElement.gd +++ b/Game/States/Build/BuilderElement.gd @@ -67,6 +67,9 @@ func _process(_delta): if global_position != previous_position: queue_redraw() + + # TODO: rpc to other peers + # TODO: only as preview not as blocking to build func can_build(): diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd index b92020b..d2fb39d 100644 --- a/Game/States/Build/StateBuild.gd +++ b/Game/States/Build/StateBuild.gd @@ -7,19 +7,6 @@ static var current_builder_element: BuilderElement func _state_enter(): %BuildGrid.visible = true - var builder_element_scene = preload("res://Game/States/Build/BuilderElement.tscn") - var builder_element = builder_element_scene.instantiate() - - var tower = preload("res://Towers/Tower.tscn").instantiate() as Tower - tower.attack_range = [ - Client.stage.map.tile_set.tile_size.x * 2, - Client.stage.map.tile_set.tile_size.x * 3, - Client.stage.map.tile_set.tile_size.x * 4, - ].pick_random() - - builder_element.element = tower - get_tree().current_scene.add_child(builder_element) - current_builder_element = builder_element func _state_exit(): @@ -28,9 +15,8 @@ func _state_exit(): func _state_input(event: InputEvent): if event.is_action_pressed("builder_tower_select"): - get_viewport().set_input_as_handled() - if current_builder_element.can_build(): + if current_builder_element and current_builder_element.can_build(): var placed_tower = current_builder_element.element.duplicate() as Tower Client.place_tower(placed_tower, current_builder_element.global_position) @@ -42,9 +28,13 @@ func _state_input(event: InputEvent): if not Input.is_action_pressed("builder_tower_place_keep"): current_builder_element.queue_free() - set_state("StateDefault") + current_builder_element = null - if event.is_action_pressed("builder_cancel") or event.is_action_pressed("build_mode_start"): + if event.is_action_pressed("build_mode_start"): get_viewport().set_input_as_handled() - current_builder_element.queue_free() + + if current_builder_element: + current_builder_element.queue_free() + current_builder_element = null + set_state("StateDefault") diff --git a/Game/States/Default/StateDefault.gd b/Game/States/Default/StateDefault.gd index 26384c5..1d2dd9f 100644 --- a/Game/States/Default/StateDefault.gd +++ b/Game/States/Default/StateDefault.gd @@ -4,9 +4,11 @@ extends State func _state_input(event: InputEvent) -> void: if event.is_action_pressed("build_mode_start"): - set_state("StateBuild") + set_state("StateBuild") - if event.is_action_pressed("builder_tower_select"): + # deselect + if event.is_action_pressed("select"): + # if not multi selecting if not event.is_double_click() and not Input.is_action_pressed("select_multiple"): if Tower.selected_towers: for tower in Tower.selected_towers.duplicate(): |