-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
126 lines (95 loc) · 2.91 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
extends Node2D
@onready var loaded_station_id : String
@onready var station_node : Node2D = $Station
@onready var station_instance : Node2D
@onready var orders : Array = []
@onready var ui_node := $UI
@onready var ui_orders_node := $UI/Orders
var day_score := 0
var orders_todo_today := 0
var orders_received := 0
var orders_handled := 0
func _ready():
# start_day()
pass
func _process(delta):
# DEBUG
if Input.is_action_just_pressed("debug_new_order"):
new_order()
func unload_station() -> void:
if station_instance != null:
station_instance.queue_free()
func load_station(station_id : String) -> void:
if station_id == loaded_station_id:
return
unload_station()
var new_station = load(station_id)
station_instance = new_station.instantiate()
station_node.add_child(station_instance)
loaded_station_id = station_id
func change_station(new_station : GameData.Station) -> void:
# find out if new station is to the left or right of current station
var new_station_before_current = false
var found_current_station = false
for station in GameData.station_scene_ids.keys():
if GameData.station_scene_ids[station] == loaded_station_id:
found_current_station = true
elif station == new_station:
if !found_current_station:
new_station_before_current = true
load_station(GameData.station_scene_ids[station])
break
print("left" if new_station_before_current else "right")
func start_day() -> void:
orders_todo_today = GameData.number_orders_first_day
if Global.day == 1:
orders_todo_today = GameData.number_orders_second_day
day_score = 0
orders_received = 0
orders_handled = 0
load_station(Global.get_station_scene_file(GameData.Station.FABRIC))
station_instance.get_node("Music").play()
$DayScreen.hide()
$UI.show()
$Station.show()
$UI/StationButtons.show()
$Logic/OrderTimer.start()
$UI/Mixers/Mixer.reset_mix()
$UI/Mixers/Mixer2.reset_mix()
$UI/Mixers/Mixer3.reset_mix()
new_order()
# two orders after first day
if Global.day > 0:
new_order()
func end_day() -> void:
Global.day += 1
station_instance.get_node("Music").stop()
$FinishSound.play()
$Logic/OrderTimer.stop()
$UI/StationButtons.hide()
$Logic/DayEndTimer.start()
func return_to_day_screen() -> void:
$UI.hide()
$Station.hide()
$DayScreen.show()
var order_scene := preload("res://ui/order.tscn")
func new_order() -> void:
# block creating new order if there are too many
if self.orders.size() >= get_maximum_number_of_orders():
return
if orders_received >= orders_todo_today:
return
var order_instance = order_scene.instantiate()
order_instance.name = "order_" + str(orders_received)
ui_orders_node.add_child(order_instance)
orders.append(order_instance)
orders_received += 1
func order_completed() -> void:
orders_handled += 1
if orders_handled >= orders_todo_today:
end_day()
func get_maximum_number_of_orders() -> int:
# only 2 maximum orders for the tutorial
if Global.day == 0:
return 2
return 4