Browse Source

properly compute percentages

This is based on min and max gauge values
Arnaud Vergnet 3 years ago
parent
commit
b6c0618883
1 changed files with 28 additions and 3 deletions
  1. 28
    3
      scenes/end-screen/EndRecap.gd

+ 28
- 3
scenes/end-screen/EndRecap.gd View File

@@ -11,6 +11,8 @@ var choices_names := ["tel_ouvert"]
11 11
 var gauges_ranges := [[-11, 14], [-9, 23], [-23, 24], [-13, 16], [-16, 17]]
12 12
 var relations_ranges := [[-5, 6], [-3, 5]]
13 13
 
14
+var gauges_values := []
15
+var relations_values := []
14 16
 
15 17
 var gauges := {}
16 18
 var relations := {}
@@ -22,6 +24,17 @@ onready var gauges_timer = $GaugesTimer
22 24
 var shown_gauge_index = 0
23 25
 
24 26
 func _ready():
27
+	_recover_variables()
28
+	gauges_values = _get_percentages(gauges, gauges_names, gauges_ranges)
29
+	relations_values = _get_percentages(relations, relations_names, relations_ranges)
30
+	
31
+	print(gauges_values)
32
+	print(relations_values)
33
+	
34
+	gauges_timer.start()
35
+
36
+
37
+func _recover_variables():
25 38
 	var definitions = Dialogic.get_definitions()
26 39
 	# Get relations and gauges from variables
27 40
 	for d in definitions["variables"]:
@@ -39,12 +52,24 @@ func _ready():
39 52
 	print(relations)
40 53
 	print("--")
41 54
 	print(choices)
42
-	
43
-	gauges_timer.start()
55
+
56
+
57
+func _get_percentages(data: Dictionary, names: Array, ranges: Array) -> Array:
58
+	var final_array := []
59
+	for i in range(0, data.size()):
60
+		var val = float(data[names[i]]["value"])
61
+		var min_max = ranges[i]
62
+		# Adjust offset
63
+		val -= min_max[0]
64
+		# Get whole range
65
+		var total_range = min_max[1] - min_max[0]
66
+		final_array.append(100 * val / total_range)
67
+	return final_array
68
+
44 69
 
45 70
 func _on_GaugesTimer_timeout():
46 71
 	var c = progress_container.get_child(shown_gauge_index)
47
-	c.progress = float(gauges[gauges_names[shown_gauge_index]]["value"])
72
+	c.progress = gauges_values[shown_gauge_index]
48 73
 	shown_gauge_index += 1
49 74
 	if shown_gauge_index >= progress_container.get_child_count():
50 75
 		gauges_timer.stop()

Loading…
Cancel
Save