-
Notifications
You must be signed in to change notification settings - Fork 0
/
Group.gd
73 lines (49 loc) · 1.5 KB
/
Group.gd
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
extends HBoxContainer
export (PackedScene) var Fan
var selected = false setget set_selected
var fan_count
var index
signal group_selected
signal group_consumed
func _process(_delta):
# TODO: Change this to be a border around the selected maybe
if selected:
set_modulate(Color(1.0, 1.0, 1.0, 1.0))
else:
set_modulate(Color(1.0, 1.0, 1.0, 0.5))
func _ready():
randomize()
fan_count = random_fan_count()
for _i in range(fan_count):
var fan = Fan.instance()
add_child(fan)
func _input(_event):
var relevant_input_action
if index == 0:
relevant_input_action = Input.is_action_just_pressed("select_group_1")
if index == 1:
relevant_input_action = Input.is_action_just_pressed("select_group_2")
if index == 2:
relevant_input_action = Input.is_action_just_pressed("select_group_3")
if relevant_input_action:
set_selected(not selected)
func _on_Group_gui_input(_event):
if Input.is_action_just_pressed("select_group"):
set_selected(not selected)
# For when this group is placed in seats
func consume():
Gamestate.current_selected_group = null
emit_signal("group_consumed")
queue_free()
func set_selected(new_value):
selected = new_value
if selected:
emit_signal("group_selected")
Gamestate.current_selected_group = self
else:
Gamestate.current_selected_group = null
# Pick random number between 1 and 3
func random_fan_count():
# I'm doing a range from 0.5 to 3.5 because I
# think that gives each number 1, 2, or 3 an equal chance
return round(rand_range(0.5, 3.5))