-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport.gd
88 lines (81 loc) · 2.46 KB
/
report.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
extends Node3D
var OK = [
preload("res://textures/whiteboard_tick_01.jpg"),
preload("res://textures/whiteboard_tick_02.jpg"),
preload("res://textures/whiteboard_tick_03.jpg"),
preload("res://textures/whiteboard_tick_04.jpg"),
]
var ERROR = [
preload("res://textures/whiteboard_cross_01.jpg"),
preload("res://textures/whiteboard_cross_02.jpg"),
preload("res://textures/whiteboard_cross_03.jpg"),
preload("res://textures/whiteboard_cross_04.jpg"),
]
var sound_played := false
var correct := false
var something_to_report := false
var light_mat: StandardMaterial3D
func _ready() -> void:
light_mat = $ReportLight/ReportLight.mesh.surface_get_material(1)
light_mat.emission = Color.BLACK
light_mat.albedo_color = Color.BLACK
func update_report(data: Array) -> void:
sound_played = false
something_to_report = true
for c in %ReportSubviewportNode.get_children():
c.queue_free()
var robot_with_anomaly := false
var robot_off_without_anomaly := false
var robot_without_battery := false
var r_row := 0
var r_column := 0
var batteries_charged_required := false
for r: Dictionary in data:
var icon := Sprite2D.new()
if r.handled_correctly:
icon.texture = OK.pick_random()
else:
icon.texture = ERROR.pick_random()
%ReportSubviewportNode.add_child(icon)
icon.position = Vector2(200+(r_column*450), 300+(r_row*150))
if r.glitched:
icon.position.x += 200
if r.power and not r.handled_correctly:
robot_with_anomaly = true
else:
if r.full_battery:
robot_without_battery = true
if not r.power:
robot_off_without_anomaly = true
icon.scale = Vector2.ONE * 0.2
r_row += 1
if r_row == floor(data.size()*0.5):
r_row = 0
r_column += 1
batteries_charged_required = r.batteries_charged_required
correct = true
if robot_off_without_anomaly:
$PowerErrorLabel.text = tr("ERROR OFF NO ANOMALY")
correct = false
elif robot_with_anomaly:
$PowerErrorLabel.text = tr("ERROR ANOMALY ON")
correct = false
else:
$PowerErrorLabel.text = tr("NO ERROR")
if batteries_charged_required and robot_without_battery:
$BatteryErrorLabel.text = tr("ERROR FULL BATTERY")
correct = false
else:
$BatteryErrorLabel.text = tr("NO ERROR")
func play_sound() -> void:
if not something_to_report: return
if sound_played: return
sound_played = true
if correct:
$CorrectSound.play()
light_mat.emission = Color.GREEN
light_mat.albedo_color = Color.GREEN
else:
$IncorrectSound.play()
light_mat.emission = Color.RED
light_mat.albedo_color = Color.RED