class_name StateBuild extends State static var current_builder_element: BuilderElement func _state_enter(): %BuildGrid.visible = true if Tower.selected_towers: for tower in Tower.selected_towers.duplicate(): tower.is_selected = false func _state_exit(): %BuildGrid.visible = false func _state_input(event: InputEvent): if event.is_action_pressed("builder_tower_select"): if current_builder_element and current_builder_element.can_build(): 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 event.is_action_pressed("build_mode_start"): get_viewport().set_input_as_handled() if current_builder_element: current_builder_element.queue_free() current_builder_element = null set_state("StateDefault") if event.is_action_pressed("builder_cancel") and current_builder_element: get_viewport().set_input_as_handled() current_builder_element.queue_free() current_builder_element = null func _state_unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("select"): set_state("StateDefault")