blob: e7f122df7273d96e0119113f96838a5973672e19 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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():
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:
current_builder_element.queue_free()
current_builder_element = null
func _state_unhandled_input(_event: InputEvent) -> void:
pass
|