properly compute percentages
This is based on min and max gauge values
This commit is contained in:
parent
7dec78e1ed
commit
b6c0618883
1 changed files with 28 additions and 3 deletions
|
@ -11,6 +11,8 @@ var choices_names := ["tel_ouvert"]
|
|||
var gauges_ranges := [[-11, 14], [-9, 23], [-23, 24], [-13, 16], [-16, 17]]
|
||||
var relations_ranges := [[-5, 6], [-3, 5]]
|
||||
|
||||
var gauges_values := []
|
||||
var relations_values := []
|
||||
|
||||
var gauges := {}
|
||||
var relations := {}
|
||||
|
@ -22,6 +24,17 @@ onready var gauges_timer = $GaugesTimer
|
|||
var shown_gauge_index = 0
|
||||
|
||||
func _ready():
|
||||
_recover_variables()
|
||||
gauges_values = _get_percentages(gauges, gauges_names, gauges_ranges)
|
||||
relations_values = _get_percentages(relations, relations_names, relations_ranges)
|
||||
|
||||
print(gauges_values)
|
||||
print(relations_values)
|
||||
|
||||
gauges_timer.start()
|
||||
|
||||
|
||||
func _recover_variables():
|
||||
var definitions = Dialogic.get_definitions()
|
||||
# Get relations and gauges from variables
|
||||
for d in definitions["variables"]:
|
||||
|
@ -39,12 +52,24 @@ func _ready():
|
|||
print(relations)
|
||||
print("--")
|
||||
print(choices)
|
||||
|
||||
gauges_timer.start()
|
||||
|
||||
|
||||
func _get_percentages(data: Dictionary, names: Array, ranges: Array) -> Array:
|
||||
var final_array := []
|
||||
for i in range(0, data.size()):
|
||||
var val = float(data[names[i]]["value"])
|
||||
var min_max = ranges[i]
|
||||
# Adjust offset
|
||||
val -= min_max[0]
|
||||
# Get whole range
|
||||
var total_range = min_max[1] - min_max[0]
|
||||
final_array.append(100 * val / total_range)
|
||||
return final_array
|
||||
|
||||
|
||||
func _on_GaugesTimer_timeout():
|
||||
var c = progress_container.get_child(shown_gauge_index)
|
||||
c.progress = float(gauges[gauges_names[shown_gauge_index]]["value"])
|
||||
c.progress = gauges_values[shown_gauge_index]
|
||||
shown_gauge_index += 1
|
||||
if shown_gauge_index >= progress_container.get_child_count():
|
||||
gauges_timer.stop()
|
||||
|
|
Loading…
Reference in a new issue