-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlate_produce.gd
234 lines (197 loc) · 6.11 KB
/
Plate_produce.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
extends Control
export var item_name = "Item"
export var amount = 0
export var bars_active_num = 0
var item_id
var main
# recipe
var bars_num = 1000
export var rcp_metal = 0
export var rcp_concrete = 0
export var rcp_plastic = 0
export var rcp_rubber = 0
export var rcp_wood = 0
export var rcp_cloth = 0
export var rcp_tarpaper = 0
export var rcp_parts = 0
export var rcp_rebar = 0
export var rcp_carpet = 0
export var rcp_electronics = 0
export var rcp_sofa = 0
export var rcp_furniture = 0
export var rcp_roof_tile = 0
export var rcp_wall_tile = 0
export var rcp_door = 0
export var rcp_window = 0
export var rcp_boiler = 0
export var rcp_device = 0
export var rcp_boiler_room = 0
export var rcp_kitchen = 0
export var rcp_living_room = 0
export var rcp_building = 0
export var rcp_house = 0
export var rcp_work = 1
var res_required = [0, 0, 0, 0, 0, 0, 0]
var res_current = [0, 0, 0, 0, 0, 0, 0]
var res_complete: bool = false
var item_required = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
var item_current = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
var item_complete: bool = false
var work_required = 1
var work_current = 0
var produce_sound_player
var done_sound_player
var decline_sound_player
var vars
var prog_bar
# Called when the node enters the scene tree for the first time.
func _ready():
vars = get_node("/root/GlobalVars")
prog_bar = $"Progress bar"
produce_sound_player = get_node("Bottom lane/ProduceSoundPlayer")
done_sound_player = get_node("Bottom lane/DoneSoundPlayer")
decline_sound_player = get_node("Bottom lane/DeclineSoundPlayer")
update_recipe_label()
_update_price_label()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
$"Bottom lane/Amount label".text = "Stock " + str(vars.items_stock[get_item_id()])
update_recipe_label()
func _init_required():
res_required[0] = rcp_metal
res_required[1] = rcp_concrete
res_required[2] = rcp_plastic
res_required[3] = rcp_rubber
res_required[4] = rcp_wood
res_required[5] = rcp_cloth
res_required[6] = rcp_tarpaper
item_required[0] = rcp_parts
item_required[1] = rcp_rebar
item_required[2] = rcp_carpet
item_required[3] = rcp_electronics
item_required[4] = rcp_sofa
item_required[5] = rcp_furniture
item_required[6] = rcp_roof_tile
item_required[7] = rcp_wall_tile
item_required[8] = rcp_door
item_required[9] = rcp_window
item_required[10] = rcp_boiler
item_required[11] = rcp_device
item_required[12] = rcp_boiler_room
item_required[13] = rcp_kitchen
item_required[14] = rcp_living_room
item_required[15] = rcp_building
item_required[16] = rcp_house
work_required = rcp_work
func update_recipe_label():
var offset = 12
var cur_text = "[center]Recipe:[/center]\n"
for i in range(0, vars.res_names.size()):
if(res_required[i] != 0):
var res_line = vars.res_names[i]
for j in range(0, (offset - res_line.length())):
res_line += " "
cur_text += res_line
cur_text += str(res_current[i]) + "/" + str(res_required[i]) + " "
if(vars.res_available[i] < res_required[i] - res_current[i]):
cur_text += "[color=red](" + str(vars.res_available[i]) + ")[/color]\n"
else:
cur_text += "(" + str(vars.res_available[i]) + ")\n"
for i in range(0, vars.items_names.size()):
if(item_required[i] != 0):
var item_line = vars.items_names[i]
for j in range(0, (offset - item_line.length())):
item_line += " "
cur_text += item_line
cur_text += str(item_current[i]) + "/" + str(item_required[i]) + " "
if(vars.items_stock[i] < item_required[i] - item_current[i]):
cur_text += "[color=red](" + str(vars.items_stock[i]) + ")[/color]\n"
else:
cur_text += "(" + str(vars.items_stock[i]) + ")\n"
cur_text += "Work "
cur_text += str(work_current) + "/" + str(work_required) + " \n"
$"Recipe/Recipe label".bbcode_text = cur_text
func _on_Produce_button_button_down():
if (!res_complete):
for i in range (0, res_required.size()):
if (res_required[i] != 0):
if(res_current[i] < res_required[i]):
if (vars.res_available[i] > 0):
produce_sound_player.play()
prog_bar.denied = false
prog_bar.activate(1)
vars.res_available[i] -= 1
res_current[i] += 1
SignalManager.emit_signal("res_changed")
return
else:
decline_sound_player.play()
prog_bar.denied = true
return
else:
continue
else:
continue
res_complete = true
if (!item_complete):
for i in range (0, item_required.size()):
if (item_required[i] != 0):
if(item_current[i] < item_required[i]):
if (vars.items_stock[i] > 0):
produce_sound_player.play()
prog_bar.denied = false
prog_bar.activate(1)
vars.items_stock[i] -= 1
item_current[i] += 1
SignalManager.emit_signal("item_changed")
return
else:
decline_sound_player.play()
prog_bar.denied = true
return
else:
continue
else:
continue
item_complete = true
work_current += 1
if (work_current != work_required):
produce_sound_player.play()
prog_bar.activate(1)
else:
done_sound_player.play()
vars.items_stock[get_item_id()] += 1
prog_bar.activate(1)
SignalManager.emit_signal("item_changed")
for i in range(0, res_current.size()):
res_current[i] = 0
res_complete = false
for i in range(0, item_current.size()):
item_current[i] = 0
item_complete = false
work_current = 0
func get_item_id():
if (item_id == null):
for i in range(0, vars.items_names.size()):
if(vars.items_names[i] == item_name):
item_id = i
break
return item_id
func _on_Progress_bar_ready():
var progress_bar = $"Progress bar"
_init_required()
bars_num = 0
for i in range(0, res_required.size()):
bars_num += res_required[i]
for i in range(0, item_required.size()):
bars_num += item_required[i]
bars_num += work_required
progress_bar.bars_num = bars_num
progress_bar.bars_active_num = bars_active_num
func _on_Product_name_label_ready():
$"Product name label".text = item_name
func _update_price_label():
var text = "[center]"
text += str(vars.items_prices[get_item_id()])
text += "[color=green]$[/color]"
$"Bottom lane/Price label".bbcode_text = text